|
Nux 1.6 | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object nux.xom.pool.XSLTransformFactory
public class XSLTransformFactory
Creates and returns new XSLTransform
objects using flexible parametrization (thread-safe).
TRAX factories, attributes and URIResolver
of the underlying TRAX
TransformerFactory
can be specified by overriding the protected
getPreferredTransformerFactories
and initFactory
methods.
For anything but simple/basic use cases, this API is more robust, configurable and convenient than the underlying XOM XSLTransform constructor API.
This implementation is thread-safe.
Example usage:
// without custom factories: XSLTransform trans = new XSLTransformFactory().createTransform(new File("/tmp/test.xsl")); Document doc = BuilderPool.GLOBAL_POOL.getBuilder(false).build(new File("/tmp/test.xml")); Nodes nodes = trans.transform(doc); for (int i=0; i < nodes.size(); i++) { System.out.println("node "+i+": "+nodes.get(i).toXML()); } // with custom factories: XSLTransformFactory factory = new XSLTransformFactory() { protected String[] getPreferredTransformerFactories() { return new String[] { "net.sf.saxon.TransformerFactoryImpl", "org.apache.xalan.processor.TransformerFactoryImpl" }; } }; XSLTransform trans = factory.createTransform(new File("/tmp/test.xsl")); Document doc = BuilderPool.GLOBAL_POOL.getBuilder(false).build(new File("/tmp/test.xml")); Nodes nodes = trans.transform(doc);
Constructor Summary | |
---|---|
XSLTransformFactory()
Creates a factory instance. |
Method Summary | |
---|---|
XSLTransform |
createTransform(Document stylesheet)
Creates and returns a new XSLTransform for the given stylesheet. |
XSLTransform |
createTransform(File stylesheet)
Creates and returns a new XSLTransform for the given stylesheet. |
XSLTransform |
createTransform(InputStream stylesheet,
URI baseURI)
Creates and returns a new XSLTransform for the given stylesheet. |
protected String[] |
getPreferredTransformerFactories()
Callback that returns a search list of fully qualified class names of TRAX TransformerFactory implementations, given in order of
preference from left to right. |
protected void |
initFactory(TransformerFactory factory)
Callback that initializes the supplied TransformerFactory with application-specific attributes and a URIResolver, if so desired. |
protected XSLTransform |
newTransform(Document stylesheet,
TransformerFactory transformerFactory)
Callback that creates and returns a new XSLTransform for the given
stylesheet and TransformerFactory. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public XSLTransformFactory()
Method Detail |
---|
public XSLTransform createTransform(Document stylesheet) throws XSLException
XSLTransform
for the given stylesheet.
stylesheet
- the stylesheet to compile
XSLException
- if the XSLTransform can't be created, e.g. because of an XSL syntax error.public XSLTransform createTransform(File stylesheet) throws XSLException, ParsingException, IOException
XSLTransform
for the given stylesheet.
stylesheet
- the stylesheet to compile
IOException
- if an I/O error occurs while reading from the stream
ParsingException
- if the stylesheet is not well-formed XML
XSLException
- if the XSLTransform can't be created, e.g. because of an XSL syntax error.public XSLTransform createTransform(InputStream stylesheet, URI baseURI) throws XSLException, ParsingException, IOException
XSLTransform
for the given stylesheet.
stylesheet
- the stylesheet to compilebaseURI
- the (absolute) baseURI of the stylesheet (may be null
)
Need not be the stream's actual URI.
IOException
- if an I/O error occurs while reading from the stream
ParsingException
- if the stylesheet is not well-formed XML
XSLException
- if the XSLTransform can't be created, e.g. because of an XSL syntax error.protected XSLTransform newTransform(Document stylesheet, TransformerFactory transformerFactory) throws XSLException
XSLTransform
for the given
stylesheet and TransformerFactory.
Override this method if you want to create custom subclasses of XSLTransform.
stylesheet
- the stylesheet to compiletransformerFactory
- the TransformerFactory
XSLException
- if no XSLTransform can be obtained for the given stylesheet;
in particular when the supplied stylesheet is not
syntactically correct XSLTprotected String[] getPreferredTransformerFactories()
TransformerFactory
implementations, given in order of
preference from left to right. May return null
.
Override this method for custom behaviour. This default implementation returns a search list for the most popular TRAX implementations.
protected void initFactory(TransformerFactory factory)
Override this method if you need custom attributes/resolvers. This default implementation does nothing.
Note: Attributes and resolver are not part of the constructor because they may well be stateful and mutable, hence it may well be unsafe to share them among multiple XSLTransforms in a multi-threaded context. By providing this method, an application can create attributes/resolvers as needed via straightforward subclassing/overriding of this method.
factory
- the factory to initialize
|
Nux 1.6 | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |