Package org.mycore.common.xml
Class MCRXSLTransformation
java.lang.Object
org.mycore.common.xml.MCRXSLTransformation
This class implements XSLTransformation functions to be used in all other
MyCoRe packages. The class is implemented as singleton and should be very
easy to use. So here is an example:
// Get an instance of the class
MCRXSLTransformation transformation = MCRXSLTransformation.getInstance();
// Get the template: myStylesheet could be a String (i.e. a filename),
// a File or a StreamSource Templates
templates = transformation.getStylesheet(myStylesheet);
// Next, you are in need of a TransformerHandler:
TransformerHandler th = transformation.getTransformerHandler(templates);
// Now you are able to set some properties (if you want!):
Properties parameters = new Properties(); ...
transformation.setParameters(th, parameters);
// Finally, you need an OutputStream and might get at work:
OutputStream out = response.getOutputStream();
transformation.transform(jdom, th, out);
// You might also want to transform into something different, perhaps a ZIP-File:
OutputStream out = new ZipOutputStream(response.getOutputStream());
((ZipOutputStream) out).setLevel(Deflater.BEST_COMPRESSION);
ZipEntry ze = new ZipEntry("_index.htm");
((ZipOutputStream) out).putNextEntry(ze); ...
// After all this work is done, you could close the OutputStream:
out.close();
// This is not done by transform
, the later example
// should show, why. *
- Version:
- $Revision: 1.0 $ $Date: 2003/02/03 14:57:25 $
- Author:
- Werner Gresshoff
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic MCRXSLTransformation
Method getInstance.getStylesheet
(File stylesheet) Method getStylesheet.getStylesheet
(String stylesheet) Method getStylesheet.getStylesheet
(Source stylesheet) Method getStylesheet.getTransformerHandler
(Templates stylesheet) Method getTransformerHandler.static void
setParameters
(TransformerHandler handler, Map parameters) Method setParameters.static void
setParameters
(Transformer transformer, Map parameters) Method setParameters.static Document
Method transform.static Document
Method transform.void
transform
(Document in, TransformerHandler handler, OutputStream out) Method transform.static Document
Method transform.static Document
transform
(Document in, Transformer transformer) transforms a jdom Document via XSLT.
-
Constructor Details
-
MCRXSLTransformation
public MCRXSLTransformation()
-
-
Method Details
-
getInstance
Method getInstance. Creates an instance of MCRXSLTransformation, when called the first time.- Returns:
- MCRXSLTransformation
-
getStylesheet
Method getStylesheet. Returns a precompiled stylesheet.- Parameters:
stylesheet
- Full path to the stylesheet- Returns:
- Templates The precompiled Stylesheet
-
getStylesheet
Method getStylesheet. Returns a precompiled stylesheet.- Parameters:
stylesheet
- A File with the stylesheet code- Returns:
- Templates The precompiled Stylesheet
-
getStylesheet
Method getStylesheet. Returns a precompiled stylesheet.- Parameters:
stylesheet
- A StreamSource- Returns:
- Templates The precompiled Stylesheet
-
getTransformerHandler
Method getTransformerHandler. Returns a TransformerHandler for the given Template.- Returns:
- TransformerHandler
-
setParameters
Method setParameters. Set some parameters which can be used by the Stylesheet for the transformation. -
setParameters
Method setParameters. Set some parameters which can be used by the Stylesheet for the transformation. -
transform
Method transform. Transforms a JDOM-Document to the given OutputStream -
transform
Method transform. Transforms a JDOM-Document in with a given stylesheet to a new document.- Parameters:
in
- A JDOM-Document.stylesheet
- The Filename with complete path (this is not a servlet!) of the stylesheet.- Returns:
- Document The new document or null, if an exception was thrown.
-
transform
Method transform. Transforms a JDOM-Document in with a given stylesheet to a new document.- Parameters:
in
- A JDOM-Document.stylesheet
- The Filename with complete path (this is not a servlet!) of the stylesheet.parameters
- parameters used by the stylesheet for transformation- Returns:
- Document The new document or null, if an exception was thrown.
-
transform
Method transform. Transforms a JDOM-Document in with a given stylesheet to a new document.- Parameters:
in
- A JDOM-Document.stylesheet
- The Filename with complete path (this is not a servlet!) of the stylesheet.parameters
- parameters used by the stylesheet for transformation- Returns:
- Document The new document or null, if an exception was thrown.
-
transform
transforms a jdom Document via XSLT.- Parameters:
in
- Document inputtransformer
- Transformer handling the transformation process- Returns:
- the transformation result as jdom Document
- Throws:
TransformerException
- if transformation fails
-