org.apache.cocoon.components.xslt
Class XSLTProcessorImpl

java.lang.Object
  extended byorg.apache.cocoon.util.AbstractLogEnabled
      extended byorg.apache.cocoon.components.xslt.XSLTProcessorImpl
All Implemented Interfaces:
URIResolver, XSLTProcessor

public class XSLTProcessorImpl
extends org.apache.cocoon.util.AbstractLogEnabled
implements XSLTProcessor, URIResolver

Adaptation of Excalibur's XSLTProcessor implementation to allow for better error reporting. This is a bean implementation that can be configured in a spring context.

Version:
$Id: XSLTProcessorImpl.html 1304280 2012-03-23 11:18:01Z ilgrosso $

Nested Class Summary
static class XSLTProcessorImpl.MyTransformerHandlerAndValidity
          Subclass to allow for instanciation, as for some unknown reason the constructor is protected....
 
Nested classes inherited from class org.apache.cocoon.components.xslt.XSLTProcessor
XSLTProcessor.TransformerHandlerAndValidity
 
Field Summary
protected  boolean checkIncludes
          Check included stylesheets
protected  SAXTransformerFactory factory
          The trax TransformerFactory this component uses
protected  Map includesMap
          Map of pairs of System ID's / validities of the included stylesheets
protected  boolean incrementalProcessing
          Is incremental processing turned on? (default for Xalan: no)
protected  SourceResolver resolver
          Resolver used to resolve XSLT document() calls, imports and includes
protected  org.apache.cocoon.core.xml.SAXParser saxParser
           
protected  Store store
          The store service instance
protected  String transformerFactory
          The configured transformer factory to use
 
Constructor Summary
XSLTProcessorImpl()
           
 
Method Summary
 TransformerHandler getTransformerHandler(Source stylesheet)
          Same as getTransformerHandler(Source,XMLFilter), with filter set to null.
 TransformerHandler getTransformerHandler(Source stylesheet, XMLFilter filter)
          Return a TransformerHandler for a given stylesheet Source.
 XSLTProcessor.TransformerHandlerAndValidity getTransformerHandlerAndValidity(Source stylesheet)
          Same as getTransformerHandlerAndValidity(Source,XMLFilter), with filter set to null.
 XSLTProcessor.TransformerHandlerAndValidity getTransformerHandlerAndValidity(Source stylesheet, XMLFilter filter)
          Return a TransformerHandler and SourceValidity for a given stylesheet Source.
 void init()
          Initialize this component.
 Source resolve(String href, String base)
          Called by the processor when it encounters an xsl:include, xsl:import, or document() function.
 void setCheckIncludes(boolean checkIncludes)
           
 void setIncrementalProcessing(boolean incrementalProcessing)
           
 void setResolver(SourceResolver resolver)
           
 void setSaxParser(org.apache.cocoon.core.xml.SAXParser saxParser)
           
 void setStore(Store store)
           
 void setTransformerFactory(String classname)
          Set the transformer factory used by this component
 void transform(Source source, Source stylesheet, Map params, Result result)
          Applies an XSLT stylesheet to an XML document.
 
Methods inherited from class org.apache.cocoon.util.AbstractLogEnabled
getLogger, setLogger
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

store

protected Store store
The store service instance


transformerFactory

protected String transformerFactory
The configured transformer factory to use


factory

protected SAXTransformerFactory factory
The trax TransformerFactory this component uses


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


checkIncludes

protected boolean checkIncludes
Check included stylesheets


includesMap

protected Map includesMap
Map of pairs of System ID's / validities of the included stylesheets


saxParser

protected org.apache.cocoon.core.xml.SAXParser saxParser
Constructor Detail

XSLTProcessorImpl

public XSLTProcessorImpl()
Method Detail

init

public void init()
          throws Exception
Initialize this component.

Throws:
Exception

setStore

public void setStore(Store store)

setIncrementalProcessing

public void setIncrementalProcessing(boolean incrementalProcessing)

setResolver

public void setResolver(SourceResolver resolver)

setCheckIncludes

public void setCheckIncludes(boolean checkIncludes)

setSaxParser

public void setSaxParser(org.apache.cocoon.core.xml.SAXParser saxParser)

setTransformerFactory

public void setTransformerFactory(String classname)
Set the transformer factory used by this component


getTransformerHandler

public TransformerHandler getTransformerHandler(Source stylesheet)
                                         throws XSLTProcessorException
Description copied from interface: XSLTProcessor
Same as XSLTProcessor.getTransformerHandler(Source,XMLFilter), with filter set to null.

Specified by:
getTransformerHandler in interface XSLTProcessor
Parameters:
stylesheet - a Source value
Returns:
a TransformerHandler value
Throws:
XSLTProcessorException - if an error occurs
See Also:
XSLTProcessor.getTransformerHandler(org.apache.excalibur.source.Source)

getTransformerHandler

public TransformerHandler getTransformerHandler(Source stylesheet,
                                                XMLFilter filter)
                                         throws XSLTProcessorException
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
Parameters:
stylesheet - a Source value
filter - a XMLFilter value
Returns:
a TransformerHandler value
Throws:
XSLTProcessorException - if an error occurs
See Also:
XSLTProcessor.getTransformerHandler(org.apache.excalibur.source.Source, org.xml.sax.XMLFilter)

getTransformerHandlerAndValidity

public XSLTProcessor.TransformerHandlerAndValidity getTransformerHandlerAndValidity(Source stylesheet)
                                                                             throws XSLTProcessorException
Description copied from interface: XSLTProcessor
Same as XSLTProcessor.getTransformerHandlerAndValidity(Source,XMLFilter), with filter set to null.

Specified by:
getTransformerHandlerAndValidity in interface XSLTProcessor
Parameters:
stylesheet - a Source value
Returns:
a XSLTProcessor.TransformerHandlerAndValidity value
Throws:
XSLTProcessorException - if an error occurs
See Also:
XSLTProcessor.getTransformerHandlerAndValidity(org.apache.excalibur.source.Source)

getTransformerHandlerAndValidity

public XSLTProcessor.TransformerHandlerAndValidity getTransformerHandlerAndValidity(Source stylesheet,
                                                                                    XMLFilter filter)
                                                                             throws XSLTProcessorException
Description copied from interface: XSLTProcessor

Return a TransformerHandler and SourceValidity 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:
getTransformerHandlerAndValidity in interface XSLTProcessor
Parameters:
stylesheet - a Source value
filter - a XMLFilter value
Returns:
a TransformerHandlerAndValidity value
Throws:
XSLTProcessorException - if an error occurs
See Also:
XSLTProcessor.getTransformerHandlerAndValidity(org.apache.excalibur.source.Source, org.xml.sax.XMLFilter)

transform

public void transform(Source source,
                      Source stylesheet,
                      Map params,
                      Result result)
               throws XSLTProcessorException
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
Parameters:
source - a Source value
stylesheet - a Source value
params - a Map
result - a Result value
Throws:
XSLTProcessorException - if an error occurs
See Also:
XSLTProcessor.transform(org.apache.excalibur.source.Source, org.apache.excalibur.source.Source, java.util.Map, javax.xml.transform.Result)

resolve

public Source resolve(String href,
                      String base)
               throws TransformerException
Called by the processor when it encounters an xsl:include, xsl:import, or document() function.

Specified by:
resolve in interface 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:
TransformerException - if an error occurs when trying to resolve the URI.


Copyright © 1999-2008 The Apache Software Foundation. All Rights Reserved.