Class IdentityTransformer

  • Direct Known Subclasses:
    StreamingTransformerImpl, TransformerImpl

    public class IdentityTransformer
    extends javax.xml.transform.Transformer
    Saxon implementation of the JAXP IdentityTransformer. This is used mainly for serializing various kinds of source under the control of serialization parameters.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void clearParameters()
      Clear all parameters set with setParameter.
      Configuration getConfiguration()  
      javax.xml.transform.ErrorListener getErrorListener()
      Get the error event handler in effect for the transformation.
      protected java.util.Properties getLocalOutputProperties()
      Get the local output properties held in this Transformer object, that is the properties explicitly requested using setOutputProperty() or setOutputProperties()
      java.util.Properties getOutputProperties()
      Get the output properties for the transformation.
      java.lang.String getOutputProperty​(java.lang.String name)
      Get an output property that is in effect for the transformer.
      java.lang.Object getParameter​(java.lang.String name)
      Get a parameter that was explicitly set with setParameter.
      protected java.util.Properties getStylesheetOutputProperties()
      Get the output properties defined in the stylesheet.
      javax.xml.transform.URIResolver getURIResolver()
      Get an object that will be used to resolve URIs used in document().
      protected void reportFatalError​(XPathException err)  
      void reset()
      Reset this Transformer to its original configuration.
      void setErrorListener​(javax.xml.transform.ErrorListener listener)
      Set the error event listener in effect for the transformation.
      void setOutputProperties​(java.util.Properties properties)
      Set the output properties for the transformation.
      void setOutputProperty​(java.lang.String name, java.lang.String value)
      Set an output property that will be in effect for the transformation.
      void setParameter​(java.lang.String name, java.lang.Object value)
      Add a parameter for the transformation.
      void setURIResolver​(javax.xml.transform.URIResolver resolver)
      Set an object that will be used to resolve URIs used in document().
      void transform​(javax.xml.transform.Source source, javax.xml.transform.Result result)
      Perform identify transformation from Source to Result
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • IdentityTransformer

        protected IdentityTransformer​(Configuration config)
    • Method Detail

      • reset

        public void reset()

        Reset this Transformer to its original configuration.

        Transformer is reset to the same state as when it was created with TransformerFactory.newTransformer(), TransformerFactory.newTransformer(javax.xml.transform.Source source) or Templates.newTransformer(). reset() is designed to allow the reuse of existing Transformers thus saving resources associated with the creation of new Transformers.

        The reset Transformer is not guaranteed to have the same URIResolver or ErrorListener Objects, e.g. Object.equals(Object obj). It is guaranteed to have a functionally equal URIResolver and ErrorListener.

        Overrides:
        reset in class javax.xml.transform.Transformer
        Throws:
        java.lang.UnsupportedOperationException - When implementation does not override this method.
        Since:
        1.5
      • setURIResolver

        public void setURIResolver​(javax.xml.transform.URIResolver resolver)
        Set an object that will be used to resolve URIs used in document().

        If the resolver argument is null, the URIResolver value will be cleared and the transformer will no longer have a resolver.

        Specified by:
        setURIResolver in class javax.xml.transform.Transformer
        Parameters:
        resolver - An object that implements the URIResolver interface, or null.
      • getURIResolver

        public javax.xml.transform.URIResolver getURIResolver()
        Get an object that will be used to resolve URIs used in document().
        Specified by:
        getURIResolver in class javax.xml.transform.Transformer
        Returns:
        An object that implements the URIResolver interface, or null.
      • setErrorListener

        public void setErrorListener​(javax.xml.transform.ErrorListener listener)
                              throws java.lang.IllegalArgumentException
        Set the error event listener in effect for the transformation.
        Specified by:
        setErrorListener in class javax.xml.transform.Transformer
        Parameters:
        listener - The new error listener.
        Throws:
        java.lang.IllegalArgumentException - if listener is null.
      • getErrorListener

        public javax.xml.transform.ErrorListener getErrorListener()
        Get the error event handler in effect for the transformation. Implementations must provide a default error listener.
        Specified by:
        getErrorListener in class javax.xml.transform.Transformer
        Returns:
        The current error handler, which should never be null.
      • setOutputProperties

        public void setOutputProperties​(java.util.Properties properties)
        Set the output properties for the transformation. These properties will override properties set in the Templates with xsl:output.

        If argument to this function is null, any properties previously set are removed, and the value will revert to the value defined in the templates object.

        Pass a qualified property key name as a two-part string, the namespace URI enclosed in curly braces ({}), followed by the local name. If the name has a null URL, the String only contain the local name. An application can safely check for a non-null URI by testing to see if the first character of the name is a '{' character.

        For example, if a URI and local name were obtained from an element defined with <xyz:foo xmlns:xyz="http://xyz.foo.com/yada/baz.html"/>, then the qualified name would be "{http://xyz.foo.com/yada/baz.html}foo". Note that no prefix is used.

        An IllegalArgumentException is thrown if any of the argument keys are not recognized and are not namespace qualified.

        As well as the properties defined in the JAXP OutputKeys class, Saxon defines an additional set of properties in SaxonOutputKeys. These fall into two categories: Constants representing serialization properties defined in XSLT 2.0 (which are not yet supported by JAXP), and constants supporting Saxon extensions to the set of serialization

        properties.
        Specified by:
        setOutputProperties in class javax.xml.transform.Transformer
        Parameters:
        properties - A set of output properties that will be used to override any of the same properties in affect for the transformation.
        Throws:
        java.lang.IllegalArgumentException - When keys are not recognized and are not namespace qualified.
        See Also:
        OutputKeys, Properties
      • getOutputProperties

        public java.util.Properties getOutputProperties()
        Get the output properties for the transformation.

        As well as the properties defined in the JAXP OutputKeys class, Saxon defines an additional set of properties in SaxonOutputKeys. These fall into two categories: Constants representing serialization properties defined in XSLT 2.0 (which are not yet supported by JAXP), and constants supporting Saxon extensions to the set of serialization properties.

        Specified by:
        getOutputProperties in class javax.xml.transform.Transformer
        Returns:
        the output properties being used for the transformation, including properties defined in the stylesheet for the unnamed output format
        See Also:
        SaxonOutputKeys
      • getStylesheetOutputProperties

        protected java.util.Properties getStylesheetOutputProperties()
        Get the output properties defined in the stylesheet. For an identity transformer this is an empty set, but the method is overridden in subclasses.
        Returns:
        the serialization properties defined in the stylesheet, if any.
      • getLocalOutputProperties

        protected java.util.Properties getLocalOutputProperties()
        Get the local output properties held in this Transformer object, that is the properties explicitly requested using setOutputProperty() or setOutputProperties()
        Returns:
        the local output properties
      • getOutputProperty

        public java.lang.String getOutputProperty​(java.lang.String name)
                                           throws java.lang.IllegalArgumentException

        Get an output property that is in effect for the transformer.

        If a property has been set using setOutputProperty(java.lang.String, java.lang.String), that value will be returned. Otherwise, if a property is explicitly specified in the stylesheet, that value will be returned. If the value of the property has been defaulted, that is, if no value has been set explicitly either with setOutputProperty(java.lang.String, java.lang.String) or in the stylesheet, the result may vary depending on implementation and input stylesheet.

        Specified by:
        getOutputProperty in class javax.xml.transform.Transformer
        Parameters:
        name - A non-null String that specifies an output property name, which may be namespace qualified.
        Returns:
        The string value of the output property, or null if no property was found.
        Throws:
        java.lang.IllegalArgumentException - If the property is not supported.
        See Also:
        OutputKeys
      • setOutputProperty

        public void setOutputProperty​(java.lang.String name,
                                      java.lang.String value)
                               throws java.lang.IllegalArgumentException
        Set an output property that will be in effect for the transformation.

        Pass a qualified property name as a two-part string, the namespace URI enclosed in curly braces ({}), followed by the local name. If the name has a null URL, the String only contain the local name. An application can safely check for a non-null URI by testing to see if the first character of the name is a '{' character.

        For example, if a URI and local name were obtained from an element defined with <xyz:foo xmlns:xyz="http://xyz.foo.com/yada/baz.html"/>, then the qualified name would be "{http://xyz.foo.com/yada/baz.html}foo". Note that no prefix is used.

        The Properties object that was passed to setOutputProperties(java.util.Properties) won't be effected by calling this method.

        Specified by:
        setOutputProperty in class javax.xml.transform.Transformer
        Parameters:
        name - A non-null String that specifies an output property name, which may be namespace qualified.
        value - The non-null string value of the output property.
        Throws:
        java.lang.IllegalArgumentException - If the property is not supported, and is not qualified with a namespace.
        See Also:
        OutputKeys
      • setParameter

        public void setParameter​(java.lang.String name,
                                 java.lang.Object value)
        Add a parameter for the transformation.

        Pass a qualified name as a two-part string, the namespace URI enclosed in curly braces ({}), followed by the local name. If the name has a null URL, the String only contain the local name. An application can safely check for a non-null URI by testing to see if the first character of the name is a '{' character.

        For example, if a URI and local name were obtained from an element defined with <xyz:foo xmlns:xyz="http://xyz.foo.com/yada/baz.html"/>, then the qualified name would be "{http://xyz.foo.com/yada/baz.html}foo". Note that no prefix is used.

        Specified by:
        setParameter in class javax.xml.transform.Transformer
        Parameters:
        name - The name of the parameter, which may begin with a namespace URI in curly braces ({}).
        value - The value object. This can be any valid Java object. It is up to the processor to provide the proper object coersion or to simply pass the object on for use in an extension.
        Throws:
        java.lang.NullPointerException - If value is null.
      • getParameter

        public java.lang.Object getParameter​(java.lang.String name)
        Get a parameter that was explicitly set with setParameter.

        This method does not return a default parameter value, which cannot be determined until the node context is evaluated during the transformation process.

        The Saxon implementation for an IdentityTransformer always returns null, since parameters have no effect on an identity transformation.

        Specified by:
        getParameter in class javax.xml.transform.Transformer
        Parameters:
        name - of Object to get
        Returns:
        A parameter that has been set with setParameter.
      • clearParameters

        public void clearParameters()
        Clear all parameters set with setParameter.
        Specified by:
        clearParameters in class javax.xml.transform.Transformer
      • transform

        public void transform​(javax.xml.transform.Source source,
                              javax.xml.transform.Result result)
                       throws javax.xml.transform.TransformerException
        Perform identify transformation from Source to Result
        Specified by:
        transform in class javax.xml.transform.Transformer
        Throws:
        javax.xml.transform.TransformerException
      • reportFatalError

        protected void reportFatalError​(XPathException err)