org.apache.turbine.services.xslt
Class TurbineXSLTService

java.lang.Object
  |
  +--org.apache.turbine.services.BaseInitable
        |
        +--org.apache.turbine.services.BaseService
              |
              +--org.apache.turbine.services.TurbineBaseService
                    |
                    +--org.apache.turbine.services.xslt.TurbineXSLTService
All Implemented Interfaces:
Initable, Service, XSLTService

public class TurbineXSLTService
extends TurbineBaseService
implements XSLTService

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

Author:
Leon Messerschmidt

Field Summary
protected  java.util.Hashtable cache
          Cache of compiled StyleSheetRoots.
protected  boolean caching
          Property to control the caching of StyleSheetRoots.
protected  java.lang.String path
          Path to style sheets used for tranforming well-formed XML documents.
 
Fields inherited from class org.apache.turbine.services.BaseService
configuration, name, properties, serviceBroker
 
Fields inherited from class org.apache.turbine.services.BaseInitable
initableBroker, isInitialized
 
Fields inherited from interface org.apache.turbine.services.xslt.XSLTService
SERVICE_NAME
 
Constructor Summary
TurbineXSLTService()
           
 
Method Summary
protected  org.apache.xalan.xslt.StylesheetRoot compileStylesheetRoot(java.lang.String source)
          Compile a new StylesheetRoot from an input file.
protected  java.lang.String getFileName(java.lang.String templateName)
          Get a valid and existing filename from a template name.
protected  org.apache.xalan.xslt.StylesheetRoot getStylesheetRoot(java.lang.String xslName)
          Retrieves a StylesheetRoot.
 void init()
          Initialize the TurbineXSLT Service.
 java.lang.String transform(java.lang.String xslName, org.w3c.dom.Node in)
          Execute an xslt
 void transform(java.lang.String xslName, org.w3c.dom.Node in, java.io.Writer out)
          Execute an xslt
 java.lang.String transform(java.lang.String xslName, java.io.Reader in)
          Execute an xslt
 void transform(java.lang.String xslName, java.io.Reader in, java.io.Writer out)
          Execute an xslt
protected  void transform(java.lang.String xslName, org.apache.xalan.xslt.XSLTProcessor processor, org.apache.xalan.xslt.XSLTInputSource xmlin, org.apache.xalan.xslt.XSLTResultTarget xmlout)
           
 
Methods inherited from class org.apache.turbine.services.TurbineBaseService
init, init, init, shutdown
 
Methods inherited from class org.apache.turbine.services.BaseService
getConfiguration, getName, getProperties, getServiceBroker, setName, setServiceBroker
 
Methods inherited from class org.apache.turbine.services.BaseInitable
getInit, getInitableBroker, setInit, setInitableBroker
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 
Methods inherited from interface org.apache.turbine.services.Service
getConfiguration, getProperties, setName, setServiceBroker
 
Methods inherited from interface org.apache.turbine.services.Initable
getInit, init, setInitableBroker, shutdown
 

Field Detail

caching

protected boolean caching
Property to control the caching of StyleSheetRoots.

path

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

cache

protected java.util.Hashtable cache
Cache of compiled StyleSheetRoots.
Constructor Detail

TurbineXSLTService

public TurbineXSLTService()
Method Detail

init

public void init()
Initialize the TurbineXSLT Service. Load the path to search for xsl files and initiates the cache.
Specified by:
init in interface Initable
Overrides:
init in class TurbineBaseService
Following copied from interface: org.apache.turbine.services.Initable
Throws:
InitializationException, - if initialization of this class was not successful.

getFileName

protected java.lang.String getFileName(java.lang.String templateName)
Get a valid and existing filename from a template name. The extension is removed and replaced with .xsl. If this file does not exist the method attempts to find default.xsl. If it fails to find default.xsl it returns null.

compileStylesheetRoot

protected org.apache.xalan.xslt.StylesheetRoot compileStylesheetRoot(java.lang.String source)
                                                              throws java.lang.Exception
Compile a new StylesheetRoot from an input file.

getStylesheetRoot

protected org.apache.xalan.xslt.StylesheetRoot getStylesheetRoot(java.lang.String xslName)
                                                          throws java.lang.Exception
Retrieves a StylesheetRoot. If caching is switched on the first attempt is to load the StylesheetRoot from the cache. If caching is switched of or if the Stylesheet is not found in the cache a new StyleSheetRoot is compiled from an input file.

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


transform

protected void transform(java.lang.String xslName,
                         org.apache.xalan.xslt.XSLTProcessor processor,
                         org.apache.xalan.xslt.XSLTInputSource xmlin,
                         org.apache.xalan.xslt.XSLTResultTarget xmlout)
                  throws java.lang.Exception

transform

public void transform(java.lang.String xslName,
                      java.io.Reader in,
                      java.io.Writer out)
               throws java.lang.Exception
Execute an xslt
Specified by:
transform in interface XSLTService
Following copied from interface: org.apache.turbine.services.xslt.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

transform

public java.lang.String transform(java.lang.String xslName,
                                  java.io.Reader in)
                           throws java.lang.Exception
Execute an xslt
Specified by:
transform in interface XSLTService
Following copied from interface: org.apache.turbine.services.xslt.XSLTService
Parameters:
xslName - The name of the file that contains the xsl stylesheet.
in - The reader that passes the xml to be transformed

transform

public void transform(java.lang.String xslName,
                      org.w3c.dom.Node in,
                      java.io.Writer out)
               throws java.lang.Exception
Execute an xslt
Specified by:
transform in interface XSLTService
Following copied from interface: org.apache.turbine.services.xslt.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

transform

public java.lang.String transform(java.lang.String xslName,
                                  org.w3c.dom.Node in)
                           throws java.lang.Exception
Execute an xslt
Specified by:
transform in interface XSLTService
Following copied from interface: org.apache.turbine.services.xslt.XSLTService
Parameters:
xslName - The name of the file that contains the xsl stylesheet.
out - The writer for the transformed output


Copyright © 1999-2001 Apache Software Foundation. All Rights Reserved.