javax.xml.transform.Templates.newTransformer()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(11.3k)|赞(0)|评价(0)|浏览(94)

本文整理了Java中javax.xml.transform.Templates.newTransformer()方法的一些代码示例,展示了Templates.newTransformer()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Templates.newTransformer()方法的具体详情如下:
包路径:javax.xml.transform.Templates
类名称:Templates
方法名:newTransformer

Templates.newTransformer介绍

[英]Create a new transformation context for this Templates object.
[中]为此模板对象创建新的转换上下文。

代码示例

代码示例来源:origin: robovm/robovm

/**
 * Construct an empty XML filter, with no parent.
 *
 * <p>This filter will have no parent: you must assign a parent
 * before you start a parse or do any configuration with
 * setFeature or setProperty.</p>
 *
 * @see org.xml.sax.XMLReader#setFeature
 * @see org.xml.sax.XMLReader#setProperty
 */
public TrAXFilter (Templates templates)
 throws TransformerConfigurationException
{
 m_templates = templates;
 m_transformer = (TransformerImpl)templates.newTransformer();
}

代码示例来源:origin: xalan/xalan

/**
 * Construct an empty XML filter, with no parent.
 *
 * <p>This filter will have no parent: you must assign a parent
 * before you start a parse or do any configuration with
 * setFeature or setProperty.</p>
 *
 * @see org.xml.sax.XMLReader#setFeature
 * @see org.xml.sax.XMLReader#setProperty
 */
public TrAXFilter (Templates templates)
 throws TransformerConfigurationException
{
 m_templates = templates;
 m_transformer = (TransformerImpl)templates.newTransformer();
}

代码示例来源:origin: spring-projects/spring-framework

/**
 * Create the {@link Transformer} instance used to prefer the XSLT transformation.
 * <p>The default implementation simply calls {@link Templates#newTransformer()}, and
 * configures the {@link Transformer} with the custom {@link URIResolver} if specified.
 * @param templates the XSLT Templates instance to create a Transformer for
 * @return the Transformer object
 * @throws TransformerConfigurationException in case of creation failure
 */
protected Transformer createTransformer(Templates templates) throws TransformerConfigurationException {
  Transformer transformer = templates.newTransformer();
  if (this.uriResolver != null) {
    transformer.setURIResolver(this.uriResolver);
  }
  return transformer;
}

代码示例来源:origin: org.springframework/spring-webmvc

/**
 * Create the {@link Transformer} instance used to prefer the XSLT transformation.
 * <p>The default implementation simply calls {@link Templates#newTransformer()}, and
 * configures the {@link Transformer} with the custom {@link URIResolver} if specified.
 * @param templates the XSLT Templates instance to create a Transformer for
 * @return the Transformer object
 * @throws TransformerConfigurationException in case of creation failure
 */
protected Transformer createTransformer(Templates templates) throws TransformerConfigurationException {
  Transformer transformer = templates.newTransformer();
  if (this.uriResolver != null) {
    transformer.setURIResolver(this.uriResolver);
  }
  return transformer;
}

代码示例来源:origin: xalan/xalan

public TrAXFilter(Templates templates)  throws 
TransformerConfigurationException
{
_templates = templates;
_transformer = (TransformerImpl) templates.newTransformer();
  _transformerHandler = new TransformerHandlerImpl(_transformer);
}

代码示例来源:origin: xalan/xalan

/**
 * javax.xml.transform.sax.SAXTransformerFactory implementation.
 * Get a TransformerHandler object that can process SAX ContentHandler
 * events into a Result, based on the transformation instructions
 * specified by the argument.
 *
 * @param templates Represents a pre-processed stylesheet
 * @return A TransformerHandler object that can handle SAX events
 * @throws TransformerConfigurationException
 */    
public TransformerHandler newTransformerHandler(Templates templates) 
throws TransformerConfigurationException  
{
final Transformer transformer = templates.newTransformer();
final TransformerImpl internal = (TransformerImpl)transformer;
return new TransformerHandlerImpl(internal);
}

代码示例来源:origin: gocd/gocd

public Properties generate(File[] allTestFiles, String uploadDestPath) {
  FileOutputStream transformedHtml = null;
  File mergedResults = new File(folderToUpload.getAbsolutePath() + FileUtil.fileseparator() + TEST_RESULTS_FILE);
  File mergedResource = null;
  FileInputStream mergedFileStream = null;
  try {
    mergedResource = mergeAllTestResultToSingleFile(allTestFiles);
    transformedHtml = new FileOutputStream(mergedResults);
    try {
      mergedFileStream = new FileInputStream(mergedResource);
      Source xmlSource = new StreamSource(mergedFileStream);
      StreamResult result = new StreamResult(transformedHtml);
      templates.newTransformer().transform(xmlSource, result);
    } catch (Exception e) {
      publisher.reportErrorMessage("Unable to publish test properties. Error was " + e.getMessage(), e);
    }
    extractProperties(mergedResults);
    publisher.upload(mergedResults, uploadDestPath);
    return null;
  } catch (Exception e) {
    publisher.reportErrorMessage("Unable to publish test properties. Error was " + e.getMessage(), e);
  } finally {
    IOUtils.closeQuietly(mergedFileStream);
    IOUtils.closeQuietly(transformedHtml);
    if (mergedResource != null) {
      mergedResource.delete();
    }
  }
  return new Properties();
}

代码示例来源:origin: marytts/marytts

/**
 * Default constructor. Calls <code>startup()</code> if it has not been called before.
 * 
 * @throws MaryConfigurationException
 *             MaryConfigurationException
 * @see #startup()
 */
public MaryNormalisedWriter() throws MaryConfigurationException {
  try {
    // startup every time:
    startup();
    transformer = stylesheet.newTransformer();
  } catch (Exception e) {
    throw new MaryConfigurationException("Cannot initialise XML writing code", e);
  }
}

代码示例来源:origin: marytts/marytts

/**
 * Default constructor. Calls <code>startup()</code> if it has not been called before.
 * 
 * @throws MaryConfigurationException
 *             MaryConfigurationException
 * @see #startup()
 */
public MaryNormalisedWriter() throws MaryConfigurationException {
  try {
    // startup every time:
    startup();
    transformer = stylesheet.newTransformer();
  } catch (Exception e) {
    throw new MaryConfigurationException("Cannot initialise XML writing code", e);
  }
}

代码示例来源:origin: apache/nifi

@Override
  public void process(final InputStream rawIn, final OutputStream out) throws IOException {
    try (final InputStream in = new BufferedInputStream(rawIn)) {
      final Templates templates;
      if (cache != null) {
        templates = cache.get(path);
      } else {
        templates = newTemplates(context, path);
      }
      final Transformer transformer = templates.newTransformer();
      transformer.setOutputProperty(OutputKeys.INDENT, (indentOutput ? "yes" : "no"));
      // pass all dynamic properties to the transformer
      for (final Map.Entry<PropertyDescriptor, String> entry : context.getProperties().entrySet()) {
        if (entry.getKey().isDynamic()) {
          String value = context.newPropertyValue(entry.getValue()).evaluateAttributeExpressions(original).getValue();
          transformer.setParameter(entry.getKey().getName(), value);
        }
      }
      // use a StreamSource with Saxon
      StreamSource source = new StreamSource(in);
      StreamResult result = new StreamResult(out);
      transformer.transform(source, result);
    } catch (final Exception e) {
      throw new IOException(e);
    }
  }
});

代码示例来源:origin: xalan/xalan

/**
 * javax.xml.transform.sax.TransformerFactory implementation.
 * Process the Source into a Templates object, which is a a compiled
 * representation of the source. Note that this method should not be
 * used with XSLTC, as the time-consuming compilation is done for each
 * and every transformation.
 *
 * @return A Templates object that can be used to create Transformers.
 * @throws TransformerConfigurationException
 */
public Transformer newTransformer(Source source) throws
TransformerConfigurationException 
{
final Templates templates = newTemplates(source);
final Transformer transformer = templates.newTransformer();
if (_uriResolver != null) {
  transformer.setURIResolver(_uriResolver);
}
return(transformer);
}

代码示例来源:origin: marytts/marytts

public MaryData process(MaryData d) throws Exception {
    DOMSource domSource = new DOMSource(d.getDocument());
    Transformer transformer = stylesheet.newTransformer();

    // Log transformation errors to client:
    if (doWarnClient) {
      // Use custom error handler:
      transformer.setErrorListener(new LoggingErrorHandler(Thread.currentThread().getName() + " client.APML transformer"));
    }

    // Transform DOMSource into a DOMResult
    Document maryxmlDocument = docBuilder.newDocument();
    DOMResult domResult = new DOMResult(maryxmlDocument);
    transformer.transform(domSource, domResult);
    MaryData result = new MaryData(outputType(), d.getLocale());
    result.setDocument(maryxmlDocument);
    return result;
  }
}

代码示例来源:origin: marytts/marytts

public MaryData process(MaryData d) throws Exception {
    DOMSource domSource = new DOMSource(d.getDocument());

    Transformer transformer = stylesheet.newTransformer();
    // Log transformation errors to client:
    if (doWarnClient) {
      // Use custom error handler:
      transformer.setErrorListener(new LoggingErrorHandler(Thread.currentThread().getName() + " client.SSML transformer"));
    }

    // Transform DOMSource into a DOMResult
    Document maryxmlDocument = docBuilder.newDocument();
    DOMResult domResult = new DOMResult(maryxmlDocument);
    transformer.transform(domSource, domResult);
    MaryData result = new MaryData(outputType(), d.getLocale());
    result.setDocument(maryxmlDocument);
    return result;
  }
}

代码示例来源:origin: marytts/marytts

public MaryData process(MaryData d) throws Exception {
    DOMSource domSource = new DOMSource(d.getDocument());
    Transformer transformer = stylesheet.newTransformer();

    // Log transformation errors to client:
    if (doWarnClient) {
      // Use custom error handler:
      transformer.setErrorListener(new LoggingErrorHandler(Thread.currentThread().getName() + " client.Sable transformer"));
    }

    // Transform DOMSource into a DOMResult
    Document maryxmlDocument = docBuilder.newDocument();
    DOMResult domResult = new DOMResult(maryxmlDocument);
    transformer.transform(domSource, domResult);
    MaryData result = new MaryData(outputType(), d.getLocale());
    result.setDocument(maryxmlDocument);
    return result;
  }
}

代码示例来源:origin: marytts/marytts

public MaryData process(MaryData d) throws Exception {
    DOMSource domSource = new DOMSource(d.getDocument());
    Transformer transformer = stylesheet.newTransformer();

    // Log transformation errors to client:
    if (doWarnClient) {
      // Use custom error handler:
      transformer.setErrorListener(new LoggingErrorHandler(Thread.currentThread().getName() + " client.Sable transformer"));
    }

    // Transform DOMSource into a DOMResult
    Document maryxmlDocument = docBuilder.newDocument();
    DOMResult domResult = new DOMResult(maryxmlDocument);
    transformer.transform(domSource, domResult);
    MaryData result = new MaryData(outputType(), d.getLocale());
    result.setDocument(maryxmlDocument);
    return result;
  }
}

代码示例来源:origin: marytts/marytts

public MaryData process(MaryData d) throws Exception {
    DOMSource domSource = new DOMSource(d.getDocument());

    Transformer transformer = stylesheet.newTransformer();
    // Log transformation errors to client:
    if (doWarnClient) {
      // Use custom error handler:
      transformer.setErrorListener(new LoggingErrorHandler(Thread.currentThread().getName() + " client.SSML transformer"));
    }

    // Transform DOMSource into a DOMResult
    Document maryxmlDocument = docBuilder.newDocument();
    DOMResult domResult = new DOMResult(maryxmlDocument);
    transformer.transform(domSource, domResult);
    MaryData result = new MaryData(outputType(), d.getLocale());
    result.setDocument(maryxmlDocument);
    return result;
  }
}

代码示例来源:origin: marytts/marytts

public MaryData process(MaryData d) throws Exception {
    DOMSource domSource = new DOMSource(d.getDocument());
    Transformer transformer = stylesheet.newTransformer();

    // Log transformation errors to client:
    if (doWarnClient) {
      // Use custom error handler:
      transformer.setErrorListener(new LoggingErrorHandler(Thread.currentThread().getName() + " client.APML transformer"));
    }

    // Transform DOMSource into a DOMResult
    Document maryxmlDocument = docBuilder.newDocument();
    DOMResult domResult = new DOMResult(maryxmlDocument);
    transformer.transform(domSource, domResult);
    MaryData result = new MaryData(outputType(), d.getLocale());
    result.setDocument(maryxmlDocument);
    return result;
  }
}

代码示例来源:origin: marytts/marytts

Transformer transformer = stylesheet.newTransformer();

代码示例来源:origin: marytts/marytts

Transformer transformer = stylesheet.newTransformer();

代码示例来源:origin: robovm/robovm

(TransformerImpl) templates.newTransformer();
transformer.setURIResolver(m_uriResolver);
TransformerHandler th =

相关文章