org.apache.fulcrum.xslt
Class DefaultXSLTService

java.lang.Object
  extended by org.apache.avalon.framework.logger.AbstractLogEnabled
      extended by org.apache.fulcrum.xslt.DefaultXSLTService
All Implemented Interfaces:
org.apache.avalon.framework.activity.Initializable, org.apache.avalon.framework.configuration.Configurable, org.apache.avalon.framework.context.Contextualizable, org.apache.avalon.framework.logger.LogEnabled, org.apache.avalon.framework.service.Serviceable, XSLTService

public class DefaultXSLTService
extends org.apache.avalon.framework.logger.AbstractLogEnabled
implements XSLTService, org.apache.avalon.framework.activity.Initializable, org.apache.avalon.framework.configuration.Configurable, org.apache.avalon.framework.context.Contextualizable, org.apache.avalon.framework.service.Serviceable

Implementation of the Turbine XSLT Service. It transforms xml with a given xsl file. XSL stylesheets are compiled and cached (if the service property is set) to improve speeds.

Author:
Leon Messerschmidt, Sam Ruby, Eric Pugh, Thomas Vandahl

Field Summary
protected  Hashtable cache
          Cache of compiled Templates.
protected  boolean caching
          Property to control the caching of Templates.
protected  String path
          Path to style sheets used for tranforming well-formed XML documents.
protected static String STYLESHEET_CACHING
           
protected static String STYLESHEET_PATH
           
 
Fields inherited from interface org.apache.fulcrum.xslt.XSLTService
ROLE
 
Constructor Summary
DefaultXSLTService()
           
 
Method Summary
protected  Templates compileTemplates(URL source)
          Compile Templates from an input file.
 void configure(org.apache.avalon.framework.configuration.Configuration conf)
          Avalon component lifecycle method This method processes the repository path, to make it relative to the web application root, if neccessary.
 void contextualize(org.apache.avalon.framework.context.Context context)
           
protected  Templates getTemplates(String xslName)
          Retrieves Templates.
 Transformer getTransformer(String xslName)
          Retrieve a transformer for the given stylesheet name.
 void initialize()
          Initializes the service.
 void service(org.apache.avalon.framework.service.ServiceManager manager)
          Avalon component lifecycle method
 String transform(String xslName, Map params)
          Uses an xsl file without any input.
 String transform(String xslName, Node in)
          Uses an xsl file to transform xml input from a DOM note and returns a string containing the transformed output.
 String transform(String xslName, Node in, Map params)
          Uses an xsl file to transform xml input from a DOM note and returns a string containing the transformed output.
 void transform(String xslName, Node in, Writer out)
          Uses an xsl file to transform xml input from a DOM note and writes the output to a writer.
 void transform(String xslName, Node in, Writer out, Map params)
          Uses an xsl file to transform xml input from a DOM note and writes the output to a writer.
 String transform(String xslName, Reader in)
          Uses an xsl file to transform xml input from a reader and returns a string containing the transformed output.
 String transform(String xslName, Reader in, Map params)
          Uses an xsl file to transform xml input from a reader and returns a string containing the transformed output.
 void transform(String xslName, Reader in, Writer out)
          Uses an xsl file to transform xml input from a reader and writes the output to a writer.
 void transform(String xslName, Reader in, Writer out, Map params)
          Uses an xsl file to transform xml input from a reader and writes the output to a writer.
protected  void transform(String xslName, Source xmlin, Result xmlout, Map params)
           
 void transform(String xslName, Writer out, Map params)
          Uses an xsl file without any xml input (simplified stylesheet)
 
Methods inherited from class org.apache.avalon.framework.logger.AbstractLogEnabled
enableLogging, getLogger, setupLogger, setupLogger, setupLogger
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

caching

protected boolean caching
Property to control the caching of Templates.


path

protected String path
Path to style sheets used for tranforming well-formed XML documents. The path is relative to the webapp context.


cache

protected Hashtable cache
Cache of compiled Templates.


STYLESHEET_PATH

protected static final String STYLESHEET_PATH
See Also:
Constant Field Values

STYLESHEET_CACHING

protected static final String STYLESHEET_CACHING
See Also:
Constant Field Values
Constructor Detail

DefaultXSLTService

public DefaultXSLTService()
Method Detail

compileTemplates

protected Templates compileTemplates(URL source)
                              throws Exception
Compile Templates from an input file.

Parameters:
source - the source URL
Returns:
the compiled template
Throws:
Exception - the compilation failed

getTemplates

protected Templates getTemplates(String xslName)
                          throws Exception
Retrieves Templates. If caching is switched on the first attempt is to load Templates from the cache. If caching is switched of or if the Stylesheet is not found in the cache new Templates are compiled from an input file.

This method is synchronized on the xsl cache so that a thread does not attempt to load Templates from the cache while it is still being compiled.

Parameters:
xslName - the name of the XSL file
Returns:
the correspondint template or null if the XSL was not found
Throws:
Exception - getting the template failed

transform

protected void transform(String xslName,
                         Source xmlin,
                         Result xmlout,
                         Map params)
                  throws Exception
Throws:
Exception

transform

public void transform(String xslName,
                      Reader in,
                      Writer out)
               throws Exception
Uses an xsl file to transform xml input from a reader and writes the output to a writer.

Specified by:
transform in interface XSLTService
Parameters:
xslName - The name of the file that contains the xsl stylesheet.
in - The reader that passes the xml to be transformed
out - The writer for the transformed output
Throws:
Exception - the transformation failed

transform

public String transform(String xslName,
                        Reader in)
                 throws Exception
Uses an xsl file to transform xml input from a reader and returns a string containing the transformed output.

Specified by:
transform in interface XSLTService
Parameters:
xslName - The name of the file that contains the xsl stylesheet.
in - The reader that passes the xml to be transformed
Returns:
the transformed output
Throws:
Exception - the transformation failed

transform

public void transform(String xslName,
                      Node in,
                      Writer out)
               throws Exception
Uses an xsl file to transform xml input from a DOM note and writes the output to a writer.

Specified by:
transform in interface XSLTService
Parameters:
xslName - The name of the file that contains the xsl stylesheet.
in - The DOM Node to be transformed
out - The writer for the transformed output
Throws:
Exception - the transformation failed

transform

public String transform(String xslName,
                        Node in)
                 throws Exception
Uses an xsl file to transform xml input from a DOM note and returns a string containing the transformed output.

Specified by:
transform in interface XSLTService
Parameters:
xslName - The name of the file that contains the xsl stylesheet.
in - The DOM Node to be transformed
Returns:
the transformed output
Throws:
Exception - the transformation failed

transform

public void transform(String xslName,
                      Reader in,
                      Writer out,
                      Map params)
               throws Exception
Uses an xsl file to transform xml input from a reader and writes the output to a writer.

Specified by:
transform in interface XSLTService
Parameters:
xslName - The name of the file that contains the xsl stylesheet.
in - The reader that passes the xml to be transformed
out - The writer for the transformed output
params - A set of parameters that will be forwarded to the XSLT
Throws:
Exception - the transformation failed

transform

public String transform(String xslName,
                        Reader in,
                        Map params)
                 throws Exception
Uses an xsl file to transform xml input from a reader and returns a string containing the transformed output.

Specified by:
transform in interface XSLTService
Parameters:
xslName - The name of the file that contains the xsl stylesheet.
in - The reader that passes the xml to be transformed
params - A set of parameters that will be forwarded to the XSLT
Returns:
the transformed output
Throws:
Exception - the transformation failed

transform

public void transform(String xslName,
                      Node in,
                      Writer out,
                      Map params)
               throws Exception
Uses an xsl file to transform xml input from a DOM note and writes the output to a writer.

Specified by:
transform in interface XSLTService
Parameters:
xslName - The name of the file that contains the xsl stylesheet.
in - The DOM Node to be transformed
out - The writer for the transformed output
params - A set of parameters that will be forwarded to the XSLT
Throws:
Exception - the transformation failed

transform

public String transform(String xslName,
                        Node in,
                        Map params)
                 throws Exception
Uses an xsl file to transform xml input from a DOM note and returns a string containing the transformed output.

Specified by:
transform in interface XSLTService
Parameters:
xslName - The name of the file that contains the xsl stylesheet.
in - The DOM Node to be transformed
params - A set of parameters that will be forwarded to the XSLT
Returns:
the transformed output
Throws:
Exception - the transformation failed

transform

public String transform(String xslName,
                        Map params)
                 throws Exception
Uses an xsl file without any input.

Specified by:
transform in interface XSLTService
Parameters:
xslName - The name of the file that contains the xsl stylesheet.
params - A set of parameters that will be forwarded to the XSLT
Returns:
the transformed output
Throws:
Exception - the transformation failed

transform

public void transform(String xslName,
                      Writer out,
                      Map params)
               throws Exception
Uses an xsl file without any xml input (simplified stylesheet)

Specified by:
transform in interface XSLTService
Parameters:
xslName - The name of the file that contains the xsl stylesheet
out - The writer for the transformed output.
params - A set of parameters that will be forwarded to the XSLT
Throws:
Exception - the transformation failed

getTransformer

public Transformer getTransformer(String xslName)
                           throws Exception
Retrieve a transformer for the given stylesheet name. If no stylesheet is available for the provided name, an identity transformer will be returned. This allows clients of this service to perform more complex transformations (for example, where parameters must be set). When possible prefer using one of the forms of transform(java.lang.String, javax.xml.transform.Source, javax.xml.transform.Result, java.util.Map).

Parameters:
xslName - Identifies stylesheet to get transformer for
Returns:
A transformer for that stylesheet
Throws:
Exception - retrieving the transformer failed

configure

public void configure(org.apache.avalon.framework.configuration.Configuration conf)
               throws org.apache.avalon.framework.configuration.ConfigurationException
Avalon component lifecycle method This method processes the repository path, to make it relative to the web application root, if neccessary. It supports URL-style repositories.

Specified by:
configure in interface org.apache.avalon.framework.configuration.Configurable
Throws:
org.apache.avalon.framework.configuration.ConfigurationException

initialize

public void initialize()
                throws Exception
Initializes the service.

Specified by:
initialize in interface org.apache.avalon.framework.activity.Initializable
Throws:
Exception

contextualize

public void contextualize(org.apache.avalon.framework.context.Context context)
                   throws org.apache.avalon.framework.context.ContextException
Specified by:
contextualize in interface org.apache.avalon.framework.context.Contextualizable
Throws:
org.apache.avalon.framework.context.ContextException

service

public void service(org.apache.avalon.framework.service.ServiceManager manager)
Avalon component lifecycle method

Specified by:
service in interface org.apache.avalon.framework.service.Serviceable


Copyright © 2005-2009 The Apache Software Foundation. All Rights Reserved.