org.apache.cocoon.components.xslt
Class XSLTProcessorImpl

java.lang.Object
  |
  +--org.apache.avalon.framework.logger.AbstractLoggable
        |
        +--org.apache.cocoon.components.xslt.XSLTProcessorImpl
All Implemented Interfaces:
org.apache.avalon.framework.component.Component, org.apache.avalon.framework.component.Composable, org.apache.avalon.framework.activity.Disposable, org.apache.avalon.framework.logger.Loggable, org.apache.avalon.framework.parameters.Parameterizable, javax.xml.transform.URIResolver, XSLTProcessor

public class XSLTProcessorImpl
extends org.apache.avalon.framework.logger.AbstractLoggable
implements XSLTProcessor, org.apache.avalon.framework.component.Composable, org.apache.avalon.framework.activity.Disposable, org.apache.avalon.framework.parameters.Parameterizable, javax.xml.transform.URIResolver

This class defines the implementation of the XSLTProcessor component. To configure it, add the following lines in the cocoon.xconf file:

 <xslt-processor class="org.apache.cocoon.components.xslt.XSLTProcessorImpl">
    <parameter name="use-store" value="true"/>
    <parameter name="transformer-factory" value="org.apache.xalan.processor.TransformerFactoryImpl"/>
 </xslt-processor>
 
The <use-store> configuration forces the transformer to put the Templates generated from the XSLT stylesheet into the Store. This property is true by default.

The <transformer-factory> configuration tells the transformer to use a particular implementation of javax.xml.transform.TransformerFactory. This allows to force the use of a given TRAX implementation (e.g. xalan or saxon) if several are available in the classpath. If this property is not set, the transformer uses the standard TRAX mechanism (TransformerFactory.newInstance()).

Since:
July 11, 2001
Version:
CVS $Id: XSLTProcessorImpl.java,v 1.18.2.6 2002/09/21 04:03:51 vgritsenko Exp $
Author:
Ovidiu Predescu

Field Summary
protected  java.util.List includes
          List accumulating included stylesheets
protected  boolean incrementalProcessing
          Is incremental processing turned on?
protected  org.apache.avalon.framework.component.ComponentManager manager
           
protected  SourceResolver resolver
          Resolver used to resolve XSLT document() calls, imports and includes
protected  Store store
          The store service instance
protected  javax.xml.transform.sax.SAXTransformerFactory tfactory
          The trax TransformerFactory
protected  java.lang.Class tfactoryClass
          The factory class used to create tfactory
protected  boolean useStore
          Is the store turned on?
 
Fields inherited from interface org.apache.cocoon.components.xslt.XSLTProcessor
ROLE
 
Constructor Summary
XSLTProcessorImpl()
           
 
Method Summary
 void compose(org.apache.avalon.framework.component.ComponentManager manager)
          Compose.
 void dispose()
          Dispose
 javax.xml.transform.sax.TransformerHandler getTransformerHandler(Source stylesheet)
          Same as getTransformerHandler(Source,XMLFilter), with filter set to null.
 javax.xml.transform.sax.TransformerHandler getTransformerHandler(Source stylesheet, org.xml.sax.XMLFilter filter)
          Return a TransformerHandler for a given stylesheet Source.
 CacheValidity getTransformerValidity(Source stylesheet)
          Return a CacheValidity for a given stylesheet Source.
 void parameterize(org.apache.avalon.framework.parameters.Parameters params)
          Configure the component
 javax.xml.transform.Source resolve(java.lang.String href, java.lang.String base)
          Called by the processor when it encounters an xsl:include, xsl:import, or document() function.
 void setSourceResolver(SourceResolver resolver)
          Set the SourceResolver for this instance.
 void transform(Source source, Source stylesheet, org.apache.avalon.framework.parameters.Parameters params, javax.xml.transform.Result result)
          Applies an XSLT stylesheet to an XML document.
 
Methods inherited from class org.apache.avalon.framework.logger.AbstractLoggable
getLogger, setLogger, setupLogger, setupLogger, setupLogger
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

manager

protected org.apache.avalon.framework.component.ComponentManager manager

store

protected Store store
The store service instance

tfactory

protected javax.xml.transform.sax.SAXTransformerFactory tfactory
The trax TransformerFactory

tfactoryClass

protected java.lang.Class tfactoryClass
The factory class used to create tfactory

useStore

protected boolean useStore
Is the store turned on? (default is on)

incrementalProcessing

protected boolean incrementalProcessing
Is incremental processing turned on? (default for Xalan: no)

resolver

protected SourceResolver resolver
Resolver used to resolve XSLT document() calls, imports and includes

includes

protected java.util.List includes
List accumulating included stylesheets
Constructor Detail

XSLTProcessorImpl

public XSLTProcessorImpl()
Method Detail

compose

public void compose(org.apache.avalon.framework.component.ComponentManager manager)
             throws org.apache.avalon.framework.component.ComponentException
Compose. Try to get the store
Specified by:
compose in interface org.apache.avalon.framework.component.Composable

dispose

public void dispose()
Dispose
Specified by:
dispose in interface org.apache.avalon.framework.activity.Disposable

parameterize

public void parameterize(org.apache.avalon.framework.parameters.Parameters params)
                  throws org.apache.avalon.framework.parameters.ParameterException
Configure the component
Specified by:
parameterize in interface org.apache.avalon.framework.parameters.Parameterizable

getTransformerValidity

public CacheValidity getTransformerValidity(Source stylesheet)
Description copied from interface: XSLTProcessor

Return a CacheValidity for a given stylesheet Source. This can be used in a pipeline to handle caching of a transformation results.

This method accesses cache of the Templates objects to obtain list of included stylesheets, which is built when stylesheet is created.

Specified by:
getTransformerValidity in interface XSLTProcessor
Following copied from interface: org.apache.cocoon.components.xslt.XSLTProcessor
Parameters:
stylesheet - a Source value
Returns:
a CacheValidity value

getTransformerHandler

public javax.xml.transform.sax.TransformerHandler getTransformerHandler(Source stylesheet)
                                                                 throws ProcessingException
Description copied from interface: XSLTProcessor
Same as XSLTProcessor.getTransformerHandler(Source,XMLFilter), with filter set to null.
Specified by:
getTransformerHandler in interface XSLTProcessor
Following copied from interface: org.apache.cocoon.components.xslt.XSLTProcessor
Parameters:
stylesheet - a Source value
Returns:
a TransformerHandler value
Throws:
ProcessingException - if an error occurs
See Also:
TraxTransformer.setConsumer(org.apache.cocoon.xml.XMLConsumer)

getTransformerHandler

public javax.xml.transform.sax.TransformerHandler getTransformerHandler(Source stylesheet,
                                                                        org.xml.sax.XMLFilter filter)
                                                                 throws ProcessingException
Description copied from interface: XSLTProcessor

Return a TransformerHandler for a given stylesheet Source. This can be used in a pipeline to handle the transformation of a stream of SAX events. See TraxTransformer.setConsumer(org.apache.cocoon.xml.XMLConsumer) for an example of how to use this method.

The additional filter argument, if it's not null, is inserted in the chain SAX events as an XML filter during the parsing or the source document.

This method caches the Templates object with meta information (modification time and list of included stylesheets) and performs a reparsing only if this changes.

Specified by:
getTransformerHandler in interface XSLTProcessor
Following copied from interface: org.apache.cocoon.components.xslt.XSLTProcessor
Parameters:
stylesheet - a Source value
filter - a XMLFilter value
Returns:
a TransformerHandler value
Throws:
ProcessingException - if an error occurs

transform

public void transform(Source source,
                      Source stylesheet,
                      org.apache.avalon.framework.parameters.Parameters params,
                      javax.xml.transform.Result result)
               throws ProcessingException
Description copied from interface: XSLTProcessor
Applies an XSLT stylesheet to an XML document. The source and stylesheet documents are specified as Source objects. The result of the transformation is placed in result, which should be properly initialized before invoking this method. Any additional parameters passed in params will become arguments to the stylesheet.
Specified by:
transform in interface XSLTProcessor
Following copied from interface: org.apache.cocoon.components.xslt.XSLTProcessor
Parameters:
source - a Source value
stylesheet - a Source value
params - a Parameters value
result - a Result value
Throws:
ProcessingException - if an error occurs

resolve

public javax.xml.transform.Source resolve(java.lang.String href,
                                          java.lang.String base)
                                   throws javax.xml.transform.TransformerException
Called by the processor when it encounters an xsl:include, xsl:import, or document() function.
Specified by:
resolve in interface javax.xml.transform.URIResolver
Parameters:
href - An href attribute, which may be relative or absolute.
base - The base URI in effect when the href attribute was encountered.
Returns:
A Source object, or null if the href cannot be resolved, and the processor should try to resolve the URI itself.
Throws:
javax.xml.transform.TransformerException - if an error occurs when trying to resolve the URI.

setSourceResolver

public void setSourceResolver(SourceResolver resolver)
Description copied from interface: XSLTProcessor
Set the SourceResolver for this instance. The resolver is invoked to return a Source object, given an HREF.
Specified by:
setSourceResolver in interface XSLTProcessor
Following copied from interface: org.apache.cocoon.components.xslt.XSLTProcessor
Parameters:
resolver - a SourceResolver value


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