本文整理了Java中javax.xml.transform.Templates
类的一些代码示例,展示了Templates
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Templates
类的具体详情如下:
包路径:javax.xml.transform.Templates
类名称:Templates
[英]An object that implements this interface is the runtime representation of processed transformation instructions.
Templates must be thread-safe for a given instance over multiple threads running concurrently, and may be used multiple times in a given session.
[中]实现此接口的对象是已处理转换指令的运行时表示。
对于一个给定实例,模板必须是线程安全的,可以在多个线程上同时运行,并且可以在给定会话中多次使用。
代码示例来源: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: xalan/xalan
argv[++i], ObjectFactory.findClassLoader(), true);
tfactory.setURIResolver(uriResolver);
stylesheet = tfactory.newTemplates(new StreamSource(xslFileName));
strResult = new StreamResult(new FileOutputStream(outFileName));
strResult.setSystemId(outFileName);
strResult = new StreamResult(System.out);
throw new TransformerException(XSLMessages.createMessage(XSLTErrorResources.ER_NO_STYLESHEET_IN_MEDIA, new Object[]{inFileName, media})); //"No stylesheet found in: "
throw new TransformerException(XSLMessages.createMessage(XSLTErrorResources.ER_NO_STYLESHEET_PI, new Object[]{inFileName})); //"No xml-stylesheet PI found in: "
Transformer transformer = flavor.equals("th") ? null : stylesheet.newTransformer();
transformer.setErrorListener(new DefaultErrorHandler(false));
transformer.setOutputProperty(OutputKeys.METHOD, outputType);
stylesheet.getOutputProperties();
serializer.setOutputProperties(serializationProps);
transformer.transform(new StreamSource(inFileName), result);
代码示例来源:origin: org.everrest/everrest-core
@Override
public void write(OutputStream output) throws IOException {
try {
Transformer transformer = templates.newTransformer();
transformer.transform(source, new StreamResult(output));
} catch (TransformerException tre) {
throw new IOException(tre.getMessage(), tre);
}
}
}
代码示例来源:origin: apache/cxf
private String transformLocally(Message m, UriInfo ui, Source source) throws Exception {
InputStream is = ResourceUtils.getResourceStream(stylesheetReference, m.getExchange().getBus());
TransformerFactory transformerFactory = TransformerFactory.newInstance();
transformerFactory.setFeature(javax.xml.XMLConstants.FEATURE_SECURE_PROCESSING, true);
Transformer t = transformerFactory.newTemplates(new StreamSource(is)).newTransformer();
t.setParameter("base.path", m.get("http.base.path"));
StringWriter stringWriter = new StringWriter();
t.transform(source, new StreamResult(stringWriter));
return stringWriter.toString();
}
代码示例来源:origin: pentaho/pentaho-kettle
TransformerFactory factory = TransformerFactory.newInstance();
try {
Templates template = factory.newTemplates( new StreamSource( xslInputStream ) );
Transformer xformer = template.newTransformer();
xformer.setOutputProperties( outputProperties );
xformer.setParameter( nameOfParams[i], valueOfParams[i] );
Source source = new StreamSource( xmlInputStream );
os = KettleVFS.getOutputStream( outputfile, false );
StreamResult resultat = new StreamResult( os );
xformer.transform( source, resultat );
代码示例来源:origin: com.opensymphony/webwork
if (location != null) {
templates = getTemplates(location);
transformer = templates.newTransformer();
} else
transformer = TransformerFactory.newInstance().newTransformer();
transformer.setURIResolver(getURIResolver());
mimeType = "text/xml"; // no stylesheet, raw xml
else
mimeType = templates.getOutputProperties().getProperty(OutputKeys.MEDIA_TYPE);
if (mimeType == null) {
transformer.transform(xmlSource, new StreamResult(out));
代码示例来源:origin: stackoverflow.com
"</xsl:stylesheet>";
TransformerFactory transFactory = new TransformerFactoryImpl();
Templates templates = transFactory.newTemplates(
new SAXSource(new InputSource(new StringReader(stylesheet))));
StreamResult result = new StreamResult(new StringWriter());
final StringWriter messageOut = new StringWriter();
Transformer transformer = templates.newTransformer();
((net.sf.saxon.jaxp.TransformerImpl)transformer).getUnderlyingController().setMessageEmitter(
new MessageEmitter() {
transformer.transform(new StreamSource(new StringReader("<in/>")), result);
assertEquals("Hi!", messageOut.toString().trim());
} catch (TransformerException e) {
e.printStackTrace();
fail();
代码示例来源: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: apache/cxf
public static Document transform(Templates xsltTemplate, Document in) {
try {
DOMSource beforeSource = new DOMSource(in);
Document out = DOMUtils.createDocument();
Transformer trans = xsltTemplate.newTransformer();
trans.transform(beforeSource, new DOMResult(out));
return out;
} catch (TransformerException e) {
throw new Fault("XML_TRANSFORM", LOG, e, e.getMessage());
}
}
}
代码示例来源:origin: marytts/marytts
Transformer transformer = stylesheet.newTransformer();
transformer.setErrorListener(new LoggingErrorHandler(Thread.currentThread().getName()
+ " client.EmotionML transformer"));
transformer.setParameter("voice", d.getDefaultVoice().getName());
transformer.transform(domSource, domResult);
代码示例来源:origin: webwork/webwork-jira
Transformer transformer = templates.newTransformer();
String mimeType = templates.getOutputProperties().getProperty(OutputKeys.MEDIA_TYPE);
if (mimeType == null) {
transformer.transform(xmlSource, new StreamResult(out));
代码示例来源:origin: stackoverflow.com
final String document1 = ...
final String document2 = ...
final Templates template = ...
final Transformer transformer = template.newTransformer();
transformer.setURIResolver(new StringURIResolver().put("document2", document2));
final StringWriter out = new StringWriter();
transformer.transform(new StreamSource(new StringReader(document1)),
new StreamResult(out));
代码示例来源:origin: pentaho/mondrian
Templates stylesheet = tfactory.newTemplates(new DOMSource(xslDOM));
Transformer transformer = stylesheet.newTransformer();
if (namevalueParameters != null) {
for (int i = 0; i < namevalueParameters.length; i++) {
String value = namevalueParameters[i][1];
transformer.setParameter(name, value);
transformer.transform(new DOMSource(inDoc, null), domResult);
代码示例来源:origin: org.jdom/jdom
/**
* Transforms the given input nodes to a list of output nodes.
*
* @param inputNodes input nodes
* @return transformed output nodes
* @throws XSLTransformException if there's a problem in the transformation
*/
public List<Content> transform(List<Content> inputNodes) throws XSLTransformException {
JDOMSource source = new JDOMSource(inputNodes);
JDOMResult result = new JDOMResult();
result.setFactory(factory); // null ok
try {
templates.newTransformer().transform(source, result);
return result.getResult();
}
catch (TransformerException e) {
throw new XSLTransformException("Could not perform transformation", e);
}
}
代码示例来源:origin: org.apache.ant/ant
transformer = templates.newTransformer();
transformer.setErrorListener(this);
if (uriResolver != null) {
transformer.setURIResolver(uriResolver);
transformer.setOutputProperty(pair[0], pair[1]);
代码示例来源:origin: net.java.dev.msv/msv-testharness
public void setStylesheet(File stylesheet) throws Exception {
xslStream = new FileInputStream(stylesheet);
StreamSource src = new StreamSource(xslStream);
src.setSystemId(getSystemId(stylesheet));
templates = tfactory.newTemplates(src);
transformer = templates.newTransformer();
}
代码示例来源:origin: com.caucho/resin
path.getParent().mkdirs();
Properties output = stylesheet.getOutputProperties();
transformer = stylesheet.newTransformer();
transformer.setParameter(param, req.getParameter(param));
transformer.setParameter("xtp:context_path", contextPath);
transformer.setParameter("xtp:servlet_path", servletPath);
代码示例来源: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: 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: jenkinsci/fitnesse-plugin
public static Transformer newRawResultsTransformer() throws TransformerException {
//In case of start method is not called by Jenkins plugin life cycle management
if (templates == null) {
try {
initTemplate();
} catch (Exception e) {
throw new TransformerException("Can't initialize template", e);
}
}
return templates.newTransformer();
}
内容来源于网络,如有侵权,请联系作者删除!