Hi,
I am trying to use Apache FOP translets which would hopefully improve my
performance than creating new transfomer (even for the first time). I could
not find an example of using Apache FOP translets. I am not sure whether my
code uses translets or not. Would anyone know whether I am doing it the
correct way in terms of compiling & using the translets & also whether
there is anyway that I can verify that even for the first time the xsl's are
being used in the application (after server startup), it is using the
compiled translets (from the jar file that i have put in my maven repository
p1.p2.myTranslet.jar) AND not compiling the xsl's into templates again.
Below lists what I have done.
Translet Compiling
============
=> SET CLASSPATH=xalan-2.7.1.jar;xml-apis-1.3.04.jar;xercesIm
pl-2.9.1.jar;serializer-2.7.1.jar
=> ava org.apache.xalan.xsltc.cmdline.Compile -p p1.p2 -x -j myTranslet.jar
stylesheet1.xsl stylesheet2.jar
Using the translets
============
// Static part of the class has a section that creates the templates from
all our xsl's & puts it in HashMap 'templatesStore'
for (String label_xsl : LABEL_XSL_RESOURCES)
{
Source source = classpathSource(label_xsl);
templatesStore.put(label_xsl,
trasformerFactory.newTemplates(source));
}
Using Translets
==========
trasformerFactory = TransformerFactory.newInstance();
trasformerFactory.setURIResolver(new
ClassUriResolver(LABEL_XSL_RESOURCE_PATH));
// For using the translets
// Set the TransformerFactory system property.
// Note: For more flexibility, load properties from a properties
file.
trasformerFactory.setAttribute("debug", Boolean.TRUE);
// trasformerFactory.setAttribute("use-classpath", Boolean.TRUE);
trasformerFactory.setAttribute("package-name", "p1.p2");
trasformerFactory.setAttribute("jar-name", "myTranslet");
trasformerFactory.setAttribute("translet-name", "myTranslet");
String key = "javax.xml.transform.TransformerFactory";
String value = "org.apache.xalan.xsltc.trax.TransformerFactoryImpl";
Properties props = System.getProperties();
props.put(key, value);
System.setProperties(props);
// Using the translets
Templates templates = (Templates) templatesStore.get(xsltResourceName);
if (templates != null) {
return templates.newTransformer();
}
else
{
throw new TransformerException("Could not create a new
Transformer for " + xsltResourceName + "; Template not found.");
}
--
View this message in context:
http://old.nabble.com/Using-Apache-FOP-translets-in-java-EE-application-tp27364146p27364146.html
Sent from the FOP - Users mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]