org.apache.xalan.xsltc.trax
Class TransformerImpl

java.lang.Object
  extended by javax.xml.transform.Transformer
      extended by org.apache.xalan.xsltc.trax.TransformerImpl
All Implemented Interfaces:
javax.xml.transform.ErrorListener, DOMCache

public final class TransformerImpl
extends javax.xml.transform.Transformer
implements DOMCache, javax.xml.transform.ErrorListener


Nested Class Summary
(package private) static class TransformerImpl.MessageHandler
          This class wraps an ErrorListener into a MessageHandler in order to capture messages reported via xsl:message.
 
Field Summary
private  DOM _dom
          A reference to a internal DOM represenation of the input.
private  XSLTCDTMManager _dtmManager
          A reference to the XSLTCDTMManager which is used to build the DOM/DTM for this transformer.
private  java.lang.String _encoding
          The output encoding of this transformation.
private  javax.xml.transform.ErrorListener _errorListener
          An error listener for runtime errors.
private  int _indentNumber
          Number of indent spaces to add when indentation is on.
private  boolean _isIdentity
          A flag indicating whether this transformer implements the identity transform.
private  boolean _isSecureProcessing
          State of the secure processing feature.
private  java.lang.String _method
          The output method of this transformation.
private  java.io.OutputStream _ostream
          A reference to the output stream, if we create one in our code.
private  Hashtable _parameters
          A hashtable to store parameters for the identity transform.
private  java.util.Properties _properties
          Output properties of this transformer instance.
private  java.util.Properties _propertiesClone
          Output properties of this transformer instance.
private  XMLReaderManager _readerManager
          A reference to an object that creates and caches XMLReader objects.
private  java.lang.String _sourceSystemId
          The systemId set in input source.
private  TransformerFactoryImpl _tfactory
          A reference to the transformer factory that this templates object belongs to.
private  TransletOutputHandlerFactory _tohFactory
          A reference to an output handler factory.
private  AbstractTranslet _translet
          A reference to the translet or null if the identity transform.
private  javax.xml.transform.URIResolver _uriResolver
          A reference to a URI resolver for calls to document().
private static java.lang.String EMPTY_STRING
           
private static java.lang.String LEXICAL_HANDLER_PROPERTY
           
private static java.lang.String NAMESPACE_FEATURE
           
private static java.lang.String NO_STRING
           
private static java.lang.String XML_STRING
           
private static java.lang.String YES_STRING
           
 
Constructor Summary
protected TransformerImpl(java.util.Properties outputProperties, int indentNumber, TransformerFactoryImpl tfactory)
           
protected TransformerImpl(Translet translet, java.util.Properties outputProperties, int indentNumber, TransformerFactoryImpl tfactory)
           
 
Method Summary
 void clearParameters()
          Implements JAXP's Transformer.clearParameters() Clear all parameters set with setParameter.
private  java.util.Properties createOutputProperties(java.util.Properties outputProperties)
          Internal method to create the initial set of properties.
 void error(javax.xml.transform.TransformerException e)
          Receive notification of a recoverable error.
 void fatalError(javax.xml.transform.TransformerException e)
          Receive notification of a non-recoverable error.
private  DOM getDOM(javax.xml.transform.Source source)
          Builds an internal DOM from a TrAX Source object
 javax.xml.transform.ErrorListener getErrorListener()
          Implements JAXP's Transformer.getErrorListener() Get the error event handler in effect for the transformation.
 SerializationHandler getOutputHandler(javax.xml.transform.Result result)
          Create an output handler for the transformation output based on the type and contents of the TrAX Result object passed to the transform() method.
 java.util.Properties getOutputProperties()
          Implements JAXP's Transformer.getOutputProperties().
 java.lang.String getOutputProperty(java.lang.String name)
          Implements JAXP's Transformer.getOutputProperty().
 java.lang.Object getParameter(java.lang.String name)
          Implements JAXP's Transformer.getParameter() Returns the value of a given parameter.
protected  TransformerFactoryImpl getTransformerFactory()
          Returns the TransformerFactoryImpl object that create this Transformer.
protected  AbstractTranslet getTranslet()
          Returns the translet wrapped inside this Transformer or null if this is the identity transform.
protected  TransletOutputHandlerFactory getTransletOutputHandlerFactory()
          Returns the TransletOutputHandlerFactory object that create the TransletOutputHandler.
 javax.xml.transform.URIResolver getURIResolver()
          Implements JAXP's Transformer.getURIResolver() Set the object currently used to resolve URIs used in document().
private  boolean isDefaultProperty(java.lang.String name, java.util.Properties properties)
          Checks if a given output property is default (2nd layer only)
 boolean isIdentity()
           
 boolean isSecureProcessing()
          Return the state of the secure processing feature.
private  java.lang.String makeCDATAString(Hashtable cdata)
          The translet stores all CDATA sections set in the element in a Hashtable.
private  void postErrorToListener(java.lang.String message)
          Inform TrAX error listener of an error
private  void postWarningToListener(java.lang.String message)
          Inform TrAX error listener of a warning
 void reset()
          This method resets the Transformer to its original configuration Transformer code is reset to the same state it was when it was created
 DOM retrieveDocument(java.lang.String baseURI, java.lang.String href, Translet translet)
          This class should only be used as a DOMCache for the translet if the URIResolver has been set.
private  void setDefaults(java.util.Properties props, java.lang.String method)
          Internal method to get the default properties from the serializer factory and set them on the property object.
protected  void setDOM(DOM dom)
          Set the internal DOM that will be used for the next transformation
 void setErrorListener(javax.xml.transform.ErrorListener listener)
          Implements JAXP's Transformer.setErrorListener() Set the error event listener in effect for the transformation.
 void setOutputProperties(java.util.Properties properties)
          Implements JAXP's Transformer.setOutputProperties().
 void setOutputProperty(java.lang.String name, java.lang.String value)
          Implements JAXP's Transformer.setOutputProperty().
 void setParameter(java.lang.String name, java.lang.Object value)
          Implements JAXP's Transformer.setParameter() Add a parameter for the transformation.
 void setSecureProcessing(boolean flag)
          Set the state of the secure processing feature.
 void setURIResolver(javax.xml.transform.URIResolver resolver)
          Implements JAXP's Transformer.setURIResolver() Set an object that will be used to resolve URIs used in document().
private  void transferOutputProperties(AbstractTranslet translet)
          Internal method to pass any properties to the translet prior to initiating the transformation
 void transferOutputProperties(SerializationHandler handler)
          This method is used to pass any properties to the output handler when running the identity transform.
 void transform(javax.xml.transform.Source source, javax.xml.transform.Result result)
          Implements JAXP's Transformer.transform()
private  void transform(javax.xml.transform.Source source, SerializationHandler handler, java.lang.String encoding)
          Internal transformation method - uses the internal APIs of XSLTC
private  void transformIdentity(javax.xml.transform.Source source, SerializationHandler handler)
           
private  boolean validOutputProperty(java.lang.String name)
          Verifies if a given output property name is a property defined in the JAXP 1.1 / TrAX spec
 void warning(javax.xml.transform.TransformerException e)
          Receive notification of a warning.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

EMPTY_STRING

private static final java.lang.String EMPTY_STRING
See Also:
Constant Field Values

NO_STRING

private static final java.lang.String NO_STRING
See Also:
Constant Field Values

YES_STRING

private static final java.lang.String YES_STRING
See Also:
Constant Field Values

XML_STRING

private static final java.lang.String XML_STRING
See Also:
Constant Field Values

LEXICAL_HANDLER_PROPERTY

private static final java.lang.String LEXICAL_HANDLER_PROPERTY
See Also:
Constant Field Values

NAMESPACE_FEATURE

private static final java.lang.String NAMESPACE_FEATURE
See Also:
Constant Field Values

_translet

private AbstractTranslet _translet
A reference to the translet or null if the identity transform.


_method

private java.lang.String _method
The output method of this transformation.


_encoding

private java.lang.String _encoding
The output encoding of this transformation.


_sourceSystemId

private java.lang.String _sourceSystemId
The systemId set in input source.


_errorListener

private javax.xml.transform.ErrorListener _errorListener
An error listener for runtime errors.


_uriResolver

private javax.xml.transform.URIResolver _uriResolver
A reference to a URI resolver for calls to document().


_properties

private java.util.Properties _properties
Output properties of this transformer instance.


_propertiesClone

private java.util.Properties _propertiesClone
Output properties of this transformer instance.


_tohFactory

private TransletOutputHandlerFactory _tohFactory
A reference to an output handler factory.


_dom

private DOM _dom
A reference to a internal DOM represenation of the input.


_indentNumber

private int _indentNumber
Number of indent spaces to add when indentation is on.


_tfactory

private TransformerFactoryImpl _tfactory
A reference to the transformer factory that this templates object belongs to.


_ostream

private java.io.OutputStream _ostream
A reference to the output stream, if we create one in our code.


_dtmManager

private XSLTCDTMManager _dtmManager
A reference to the XSLTCDTMManager which is used to build the DOM/DTM for this transformer.


_readerManager

private XMLReaderManager _readerManager
A reference to an object that creates and caches XMLReader objects.


_isIdentity

private boolean _isIdentity
A flag indicating whether this transformer implements the identity transform.


_isSecureProcessing

private boolean _isSecureProcessing
State of the secure processing feature.


_parameters

private Hashtable _parameters
A hashtable to store parameters for the identity transform. These are not needed during the transformation, but we must keep track of them to be fully complaint with the JAXP API.

Constructor Detail

TransformerImpl

protected TransformerImpl(java.util.Properties outputProperties,
                          int indentNumber,
                          TransformerFactoryImpl tfactory)

TransformerImpl

protected TransformerImpl(Translet translet,
                          java.util.Properties outputProperties,
                          int indentNumber,
                          TransformerFactoryImpl tfactory)
Method Detail

isSecureProcessing

public boolean isSecureProcessing()
Return the state of the secure processing feature.


setSecureProcessing

public void setSecureProcessing(boolean flag)
Set the state of the secure processing feature.


getTranslet

protected AbstractTranslet getTranslet()
Returns the translet wrapped inside this Transformer or null if this is the identity transform.


isIdentity

public boolean isIdentity()

transform

public void transform(javax.xml.transform.Source source,
                      javax.xml.transform.Result result)
               throws javax.xml.transform.TransformerException
Implements JAXP's Transformer.transform()

Specified by:
transform in class javax.xml.transform.Transformer
Parameters:
source - Contains the input XML document
result - Will contain the output from the transformation
Throws:
javax.xml.transform.TransformerException

getOutputHandler

public SerializationHandler getOutputHandler(javax.xml.transform.Result result)
                                      throws javax.xml.transform.TransformerException
Create an output handler for the transformation output based on the type and contents of the TrAX Result object passed to the transform() method.

Throws:
javax.xml.transform.TransformerException

setDOM

protected void setDOM(DOM dom)
Set the internal DOM that will be used for the next transformation


getDOM

private DOM getDOM(javax.xml.transform.Source source)
            throws javax.xml.transform.TransformerException
Builds an internal DOM from a TrAX Source object

Throws:
javax.xml.transform.TransformerException

getTransformerFactory

protected TransformerFactoryImpl getTransformerFactory()
Returns the TransformerFactoryImpl object that create this Transformer.


getTransletOutputHandlerFactory

protected TransletOutputHandlerFactory getTransletOutputHandlerFactory()
Returns the TransletOutputHandlerFactory object that create the TransletOutputHandler.


transformIdentity

private void transformIdentity(javax.xml.transform.Source source,
                               SerializationHandler handler)
                        throws java.lang.Exception
Throws:
java.lang.Exception

transform

private void transform(javax.xml.transform.Source source,
                       SerializationHandler handler,
                       java.lang.String encoding)
                throws javax.xml.transform.TransformerException
Internal transformation method - uses the internal APIs of XSLTC

Throws:
javax.xml.transform.TransformerException

getErrorListener

public javax.xml.transform.ErrorListener getErrorListener()
Implements JAXP's Transformer.getErrorListener() Get the error event handler in effect for the transformation.

Specified by:
getErrorListener in class javax.xml.transform.Transformer
Returns:
The error event handler currently in effect

setErrorListener

public void setErrorListener(javax.xml.transform.ErrorListener listener)
                      throws java.lang.IllegalArgumentException
Implements JAXP's Transformer.setErrorListener() Set the error event listener in effect for the transformation. Register a message handler in the translet in order to forward xsl:messages to error listener.

Specified by:
setErrorListener in class javax.xml.transform.Transformer
Parameters:
listener - The error event listener to use
Throws:
java.lang.IllegalArgumentException

postErrorToListener

private void postErrorToListener(java.lang.String message)
Inform TrAX error listener of an error


postWarningToListener

private void postWarningToListener(java.lang.String message)
Inform TrAX error listener of a warning


makeCDATAString

private java.lang.String makeCDATAString(Hashtable cdata)
The translet stores all CDATA sections set in the element in a Hashtable. This method will re-construct the whitespace separated list of elements given in the element.


getOutputProperties

public java.util.Properties getOutputProperties()
Implements JAXP's Transformer.getOutputProperties(). Returns a copy of the output properties for the transformation. This is a set of layered properties. The first layer contains properties set by calls to setOutputProperty() and setOutputProperties() on this class, and the output settings defined in the stylesheet's element makes up the second level, while the default XSLT output settings are returned on the third level.

Specified by:
getOutputProperties in class javax.xml.transform.Transformer
Returns:
Properties in effect for this Transformer

getOutputProperty

public java.lang.String getOutputProperty(java.lang.String name)
                                   throws java.lang.IllegalArgumentException
Implements JAXP's Transformer.getOutputProperty(). Get an output property that is in effect for the transformation. The property specified may be a property that was set with setOutputProperty, or it may be a property specified in the stylesheet.

Specified by:
getOutputProperty in class javax.xml.transform.Transformer
Parameters:
name - A non-null string that contains the name of the property
Throws:
java.lang.IllegalArgumentException - if the property name is not known

setOutputProperties

public void setOutputProperties(java.util.Properties properties)
                         throws java.lang.IllegalArgumentException
Implements JAXP's Transformer.setOutputProperties(). Set the output properties for the transformation. These properties will override properties set in the Templates with xsl:output. Unrecognised properties will be quitely ignored.

Specified by:
setOutputProperties in class javax.xml.transform.Transformer
Parameters:
properties - The properties to use for the Transformer
Throws:
java.lang.IllegalArgumentException - Never, errors are ignored

setOutputProperty

public void setOutputProperty(java.lang.String name,
                              java.lang.String value)
                       throws java.lang.IllegalArgumentException
Implements JAXP's Transformer.setOutputProperty(). Get an output property that is in effect for the transformation. The property specified may be a property that was set with setOutputProperty(), or it may be a property specified in the stylesheet.

Specified by:
setOutputProperty in class javax.xml.transform.Transformer
Parameters:
name - The name of the property to set
value - The value to assign to the property
Throws:
java.lang.IllegalArgumentException - Never, errors are ignored

transferOutputProperties

private void transferOutputProperties(AbstractTranslet translet)
Internal method to pass any properties to the translet prior to initiating the transformation


transferOutputProperties

public void transferOutputProperties(SerializationHandler handler)
This method is used to pass any properties to the output handler when running the identity transform.


createOutputProperties

private java.util.Properties createOutputProperties(java.util.Properties outputProperties)
Internal method to create the initial set of properties. There are two layers of properties: the default layer and the base layer. The latter contains properties defined in the stylesheet or by the user using this API.


setDefaults

private void setDefaults(java.util.Properties props,
                         java.lang.String method)
Internal method to get the default properties from the serializer factory and set them on the property object.

Parameters:
props - a java.util.Property object on which the properties are set.
method - The output method type, one of "xml", "text", "html" ...

validOutputProperty

private boolean validOutputProperty(java.lang.String name)
Verifies if a given output property name is a property defined in the JAXP 1.1 / TrAX spec


isDefaultProperty

private boolean isDefaultProperty(java.lang.String name,
                                  java.util.Properties properties)
Checks if a given output property is default (2nd layer only)


setParameter

public void setParameter(java.lang.String name,
                         java.lang.Object value)
Implements JAXP's Transformer.setParameter() Add a parameter for the transformation. The parameter is simply passed on to the translet - no validation is performed - so any unused parameters are quitely ignored by the translet.

Specified by:
setParameter in class javax.xml.transform.Transformer
Parameters:
name - The name of the parameter
value - The value to assign to the parameter

clearParameters

public void clearParameters()
Implements JAXP's Transformer.clearParameters() Clear all parameters set with setParameter. Clears the translet's parameter stack.

Specified by:
clearParameters in class javax.xml.transform.Transformer

getParameter

public final java.lang.Object getParameter(java.lang.String name)
Implements JAXP's Transformer.getParameter() Returns the value of a given parameter. Note that the translet will not keep values for parameters that were not defined in the stylesheet.

Specified by:
getParameter in class javax.xml.transform.Transformer
Parameters:
name - The name of the parameter
Returns:
An object that contains the value assigned to the parameter

getURIResolver

public javax.xml.transform.URIResolver getURIResolver()
Implements JAXP's Transformer.getURIResolver() Set the object currently used to resolve URIs used in document().

Specified by:
getURIResolver in class javax.xml.transform.Transformer
Returns:
The URLResolver object currently in use

setURIResolver

public void setURIResolver(javax.xml.transform.URIResolver resolver)
Implements JAXP's Transformer.setURIResolver() Set an object that will be used to resolve URIs used in document().

Specified by:
setURIResolver in class javax.xml.transform.Transformer
Parameters:
resolver - The URIResolver to use in document()

retrieveDocument

public DOM retrieveDocument(java.lang.String baseURI,
                            java.lang.String href,
                            Translet translet)
This class should only be used as a DOMCache for the translet if the URIResolver has been set. The method implements XSLTC's DOMCache interface, which is used to plug in an external document loader into a translet. This method acts as an adapter between TrAX's URIResolver interface and XSLTC's DOMCache interface. This approach is simple, but removes the possibility of using external document caches with XSLTC.

Specified by:
retrieveDocument in interface DOMCache
Parameters:
baseURI - The base URI used by the document call.
href - The href argument passed to the document function.
translet - A reference to the translet requesting the document

error

public void error(javax.xml.transform.TransformerException e)
           throws javax.xml.transform.TransformerException
Receive notification of a recoverable error. The transformer must continue to provide normal parsing events after invoking this method. It should still be possible for the application to process the document through to the end.

Specified by:
error in interface javax.xml.transform.ErrorListener
Parameters:
e - The warning information encapsulated in a transformer exception.
Throws:
javax.xml.transform.TransformerException - if the application chooses to discontinue the transformation (always does in our case).

fatalError

public void fatalError(javax.xml.transform.TransformerException e)
                throws javax.xml.transform.TransformerException
Receive notification of a non-recoverable error. The application must assume that the transformation cannot continue after the Transformer has invoked this method, and should continue (if at all) only to collect addition error messages. In fact, Transformers are free to stop reporting events once this method has been invoked.

Specified by:
fatalError in interface javax.xml.transform.ErrorListener
Parameters:
e - The warning information encapsulated in a transformer exception.
Throws:
javax.xml.transform.TransformerException - if the application chooses to discontinue the transformation (always does in our case).

warning

public void warning(javax.xml.transform.TransformerException e)
             throws javax.xml.transform.TransformerException
Receive notification of a warning. Transformers can use this method to report conditions that are not errors or fatal errors. The default behaviour is to take no action. After invoking this method, the Transformer must continue with the transformation. It should still be possible for the application to process the document through to the end.

Specified by:
warning in interface javax.xml.transform.ErrorListener
Parameters:
e - The warning information encapsulated in a transformer exception.
Throws:
javax.xml.transform.TransformerException - if the application chooses to discontinue the transformation (never does in our case).

reset

public void reset()
This method resets the Transformer to its original configuration Transformer code is reset to the same state it was when it was created

Overrides:
reset in class javax.xml.transform.Transformer
Since:
1.5