本文整理汇总了Java中javax.xml.transform.TransformerFactory.newTemplates方法的典型用法代码示例。如果您正苦于以下问题:Java TransformerFactory.newTemplates方法的具体用法?Java TransformerFactory.newTemplates怎么用?Java TransformerFactory.newTemplates使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.xml.transform.TransformerFactory
的用法示例。
在下文中一共展示了TransformerFactory.newTemplates方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: init
import javax.xml.transform.TransformerFactory; //导入方法依赖的package包/类
@PostConstruct
public void init() throws Exception {
FopFactoryBuilder builder = new FopFactoryBuilder(new File(".").toURI());
builder.setAccessibility(true);
fopFactory = builder.build();
foUserAgent = fopFactory.newFOUserAgent();
foUserAgent.setCreator("DSS Webapp");
foUserAgent.setAccessibility(true);
TransformerFactory transformerFactory = DomUtils.getSecureTransformerFactory();
InputStream simpleIS = FOPService.class.getResourceAsStream("/xslt/pdf/simple-report.xslt");
templateSimpleReport = transformerFactory.newTemplates(new StreamSource(simpleIS));
Utils.closeQuietly(simpleIS);
InputStream detailedIS = FOPService.class.getResourceAsStream("/xslt/pdf/detailed-report.xslt");
templateDetailedReport = transformerFactory.newTemplates(new StreamSource(detailedIS));
Utils.closeQuietly(detailedIS);
}
示例2: testConcurrentTransformations
import javax.xml.transform.TransformerFactory; //导入方法依赖的package包/类
@Test
public void testConcurrentTransformations() throws Exception {
final TransformerFactory tf = TransformerFactory.newInstance();
final Source xslsrc = new StreamSource(new StringReader(XSL));
final Templates tmpl = tf.newTemplates(xslsrc);
concurrentTestPassed.set(true);
// Execute multiple TestWorker tasks
for (int id = 0; id < THREADS_COUNT; id++) {
EXECUTOR.execute(new TransformerThread(tmpl.newTransformer(), id));
}
// Initiate shutdown of previously submitted task
EXECUTOR.shutdown();
// Wait for termination of submitted tasks
if (!EXECUTOR.awaitTermination(THREADS_COUNT, TimeUnit.SECONDS)) {
// If not all tasks terminates during the time out force them to shutdown
EXECUTOR.shutdownNow();
}
// Check if all transformation threads generated the correct namespace prefix
assertTrue(concurrentTestPassed.get());
}
示例3: testConcurrentTransformations
import javax.xml.transform.TransformerFactory; //导入方法依赖的package包/类
@Test
public void testConcurrentTransformations() throws Exception {
final TransformerFactory tf = TransformerFactory.newInstance();
final Source xslsrc = new StreamSource(new StringReader(XSL));
final Templates tmpl = tf.newTemplates(xslsrc);
concurrentTestPassed.set(true);
// Execute multiple TestWorker tasks
for (int id = 0; id < THREADS_COUNT; id++) {
EXECUTOR.execute(new TransformerThread(tmpl.newTransformer(), id));
}
// Initiate shutdown of previously submitted task
runWithAllPerm(EXECUTOR::shutdown);
// Wait for termination of submitted tasks
if (!EXECUTOR.awaitTermination(THREADS_COUNT, TimeUnit.SECONDS)) {
// If not all tasks terminates during the time out force them to shutdown
runWithAllPerm(EXECUTOR::shutdownNow);
}
// Check if all transformation threads generated the correct namespace prefix
assertTrue(concurrentTestPassed.get());
}
示例4: XSLTBench
import javax.xml.transform.TransformerFactory; //导入方法依赖的package包/类
public XSLTBench(File scratch) throws Exception {
// Check Xalan version, this is easy to get wrong because its
// bundled with Java these days, so we do explict check
this.scratch = scratch;
Properties props = System.getProperties();
if (!org.apache.xalan.Version.getVersion().equals(XALAN_VERSION)) {
System.err.println("*** Incorrect version of Xalan in use!");
System.err.println("*** Should be '" + XALAN_VERSION + "',");
System.err.println("*** actually is '" + org.apache.xalan.Version.getVersion() + "').");
System.err.println("*** To fix this, extract the included xalan.jar:");
System.err.println("*** unzip " + props.get("java.class.path") + " xalan.jar");
System.err.println("*** and override your jvm's boot classpath:");
System.err.println("*** java -Xbootclasspath/p:xalan.jar [...] ");
throw new Exception("Please fix your bootclasspath and try again.");
}
// Fix the JAXP transformer to be Xalan
String key = "javax.xml.transform.TransformerFactory";
String value = "org.apache.xalan.processor.TransformerFactoryImpl";
props.put(key, value);
System.setProperties(props);
// Compile the test stylesheet for later use
Source stylesheet = new StreamSource(new File(scratch, "xalan/xmlspec.xsl"));
TransformerFactory factory = TransformerFactory.newInstance();
_template = factory.newTemplates(stylesheet);
// Create the work queue for jobs
_workQueue = new WorkQueue();
}
示例5: testReuseTemplates
import javax.xml.transform.TransformerFactory; //导入方法依赖的package包/类
@Test
public void testReuseTemplates() throws Exception {
final TransformerFactory tf = TransformerFactory.newInstance();
final Source xslsrc = new StreamSource(new StringReader(XSL));
final Templates tmpl = tf.newTemplates(xslsrc);
for (int i = 0; i < TRANSF_COUNT; i++) {
checkResult(doTransformation(tmpl.newTransformer()));
}
}
示例6: testTransform
import javax.xml.transform.TransformerFactory; //导入方法依赖的package包/类
private String testTransform(String xsl) throws Exception {
//Prepare sources for transormation
Source src = new StreamSource(new StringReader(xml));
Source xslsrc = new StreamSource(new StringReader(xslPre + xsl + xslPost));
//Create factory, template and transformer
TransformerFactory tf = TransformerFactory.newInstance();
Templates tmpl = tf.newTemplates(xslsrc);
Transformer t = tmpl.newTransformer();
//Prepare output stream
StringWriter xmlResultString = new StringWriter();
StreamResult xmlResultStream = new StreamResult(xmlResultString);
//Transform
t.transform(src, xmlResultStream);
return xmlResultString.toString().trim();
}
示例7: xform
import javax.xml.transform.TransformerFactory; //导入方法依赖的package包/类
private static String xform(final String xml, final String xsl) throws Exception {
final TransformerFactory tf = TransformerFactory.newInstance();
final Source xslsrc = new StreamSource(new File(xsl));
final Templates tmpl = tf.newTemplates(xslsrc);
final Transformer t = tmpl.newTransformer();
StringWriter writer = new StringWriter();
final Source src = new StreamSource(new File(xml));
final Result res = new StreamResult(writer);
t.transform(src, res);
return writer.toString();
}
示例8: testTransform
import javax.xml.transform.TransformerFactory; //导入方法依赖的package包/类
@Test
public final void testTransform() {
try {
String inFilename = "CR6935697.xml";
String xslFilename = "CR6935697.xsl";
String outFilename = "CR6935697.out";
// Create transformer factory
TransformerFactory factory = TransformerFactory.newInstance();
// Use the factory to create a template containing the xsl file
Templates template = factory.newTemplates(new StreamSource(getClass().getResourceAsStream(xslFilename)));
// Use the template to create a transformer
Transformer xformer = template.newTransformer();
// Prepare the input and output files
Source source = new StreamSource(getClass().getResourceAsStream(inFilename));
Result result = new StreamResult(new FileOutputStream(USER_DIR + outFilename));
// Apply the xsl file to the source file and write the result to the
// output file
xformer.transform(source, result);
} catch (Exception e) {
// unexpected failure
e.printStackTrace();
Assert.fail(e.toString());
}
}
示例9: getTemplates
import javax.xml.transform.TransformerFactory; //导入方法依赖的package包/类
public Templates getTemplates(TransformerFactory tf)
throws TransformerConfigurationException
{
return tf.newTemplates(
new StreamSource(new ByteArrayInputStream(xsl.getBytes()))
);
}
示例10: test926007_1
import javax.xml.transform.TransformerFactory; //导入方法依赖的package包/类
@Test
public void test926007_1() throws Exception {
TransformerFactory factory = TransformerFactory.newInstance();
File f = new File(getClass().getResource("logon.xsl").getPath());
Templates t = factory.newTemplates(new StreamSource(f));
Transformer transformer = t.newTransformer();
transformer.setOutputProperty(OutputKeys.INDENT, "yes");
transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2");
transformer.transform(new StreamSource(getClass().getResourceAsStream("src.xml")), new StreamResult(System.out));
}
示例11: test926007_2
import javax.xml.transform.TransformerFactory; //导入方法依赖的package包/类
@Test
public void test926007_2() throws Exception {
TransformerFactory factory = TransformerFactory.newInstance();
// factory.setAttribute("generate-translet", Boolean.TRUE);
File f = new File(getClass().getResource("home.xsl").getPath());
Templates t = factory.newTemplates(new StreamSource(f));
Transformer transformer = t.newTransformer();
transformer.setOutputProperty(OutputKeys.INDENT, "yes");
transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2");
transformer.transform(new StreamSource(getClass().getResourceAsStream("src.xml")), new StreamResult(System.out));
}
示例12: test926007_3
import javax.xml.transform.TransformerFactory; //导入方法依赖的package包/类
@Test
public void test926007_3() throws Exception {
TransformerFactory factory = TransformerFactory.newInstance();
// factory.setAttribute("generate-translet", Boolean.TRUE);
File f = new File(getClass().getResource("upload-media.xsl").getPath());
Templates t = factory.newTemplates(new StreamSource(f));
Transformer transformer = t.newTransformer();
transformer.setOutputProperty(OutputKeys.INDENT, "yes");
transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2");
transformer.transform(new StreamSource(getClass().getResourceAsStream("src.xml")), new StreamResult(System.out));
}
示例13: init
import javax.xml.transform.TransformerFactory; //导入方法依赖的package包/类
@PostConstruct
public void init() throws TransformerConfigurationException {
TransformerFactory transformerFactory = DomUtils.getSecureTransformerFactory();
InputStream simpleIS = XSLTService.class.getResourceAsStream("/xslt/html/simple-report.xslt");
templateSimpleReport = transformerFactory.newTemplates(new StreamSource(simpleIS));
Utils.closeQuietly(simpleIS);
InputStream detailedIS = XSLTService.class.getResourceAsStream("/xslt/html/detailed-report.xslt");
templateDetailedReport = transformerFactory.newTemplates(new StreamSource(detailedIS));
Utils.closeQuietly(detailedIS);
}
示例14: test926007_1
import javax.xml.transform.TransformerFactory; //导入方法依赖的package包/类
@Test
public void test926007_1() throws Exception {
TransformerFactory factory = TransformerFactory.newInstance();
File f = new File(getClass().getResource("MsWordXMLImport.xsl.data").getPath());
Templates t = factory.newTemplates(new StreamSource(f));
}
示例15: testTransform
import javax.xml.transform.TransformerFactory; //导入方法依赖的package包/类
@Test
public final void testTransform() {
try {
String inFilename = "CR7098746.xml";
String xslFilename = "CR7098746.xsl";
StringWriter sw = new StringWriter();
// Create transformer factory
TransformerFactory factory = TransformerFactory.newInstance();
// set the translet name
// factory.setAttribute("translet-name", "myTranslet");
// set the destination directory
// factory.setAttribute("destination-directory", "c:\\temp");
// factory.setAttribute("generate-translet", Boolean.TRUE);
// Use the factory to create a template containing the xsl file
Templates template = factory.newTemplates(new StreamSource(getClass().getResourceAsStream(xslFilename)));
// Use the template to create a transformer
Transformer xformer = template.newTransformer();
// Prepare the input and output files
Source source = new StreamSource(getClass().getResourceAsStream(inFilename));
// Result result = new StreamResult(new
// FileOutputStream(outFilename));
Result result = new StreamResult(sw);
// Apply the xsl file to the source file and write the result to the
// output file
xformer.transform(source, result);
String out = sw.toString();
if (out.indexOf("<p>") < 0) {
Assert.fail(out);
}
} catch (Exception e) {
// unexpected failure
e.printStackTrace();
Assert.fail(e.toString());
}
}