Class TransformerBase

  • Direct Known Subclasses:
    FeatureTransformer, FeatureTypeTransformer, FilterTransformer, GeometryTransformer, SLDTransformer

    public abstract class TransformerBase
    extends Object
    TransformerBase provides support for writing Object->XML encoders. The basic pattern for usage is to extend TransformerBase and implement the createTranslator(ContentHandler) method. This is easiest done by extending the inner class TranslatorSupport. A Translator uses a ContentHandler to issue SAX events to a javax.xml.transform.Transformer. If possible, make the translator public so it can be used by others as well.
    Author:
    Ian Schneider
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static String XMLNS_NAMESPACE  
    • Constructor Summary

      Constructors 
      Constructor Description
      TransformerBase()  
    • Method Summary

      All Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      Transformer createTransformer()
      Create a Transformer which is initialized with the settings of this TransformerBase.
      TransformerBase.Task createTransformTask​(Object object, StreamResult result)
      Create a Transformation task.
      abstract Translator createTranslator​(ContentHandler handler)
      Create a Translator to issue SAXEvents to a ContentHandler.
      TransformerBase.XMLReaderSupport createXMLReader​(Object object)
      Create an XMLReader to use in the transformation.
      Charset getEncoding()
      Gets the charset to declare in the header of the response.
      int getIndentation()
      Get the number of spaces to indent the output xml.
      boolean isNamespaceDeclartionEnabled()
      Should this transformer declare namespace prefixes in the first element it outputs?
      boolean isOmitXMLDeclaration()
      Will this transformation omit the standard XML declaration.
      void setEncoding​(Charset charset)
      Sets the charset to declare in the xml header returned.
      void setIndentation​(int amt)
      Set the number of spaces to indent the output xml.
      void setNamespaceDeclarationEnabled​(boolean enabled)
      Enable declaration of namespace prefixes in the first element.
      void setOmitXMLDeclaration​(boolean xmlDecl)
      Set this transformer to omit/include the XML declaration.
      String transform​(Object object)
      Perform the XML encoding of the given object into an internal buffer and return the resulting String.
      void transform​(Object object, OutputStream out)
      Perform the XML encoding on the given object to the given OutputStream.
      void transform​(Object object, Writer out)
      Perform the XML encoding on the given object to the given Writer.
      void transform​(Object object, StreamResult result)
      Perform the XML encoding on the given object to the given OutputStream.
      • Methods inherited from class Object

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

      • TransformerBase

        public TransformerBase()
    • Method Detail

      • createTranslator

        public abstract Translator createTranslator​(ContentHandler handler)
        Create a Translator to issue SAXEvents to a ContentHandler.
      • createTransformer

        public Transformer createTransformer()
                                      throws TransformerException
        Create a Transformer which is initialized with the settings of this TransformerBase.
        Throws:
        TransformerException
      • transform

        public void transform​(Object object,
                              OutputStream out)
                       throws TransformerException
        Perform the XML encoding on the given object to the given OutputStream. Calls transform(Object,StreamResult);
        Throws:
        TransformerException
      • transform

        public void transform​(Object object,
                              Writer out)
                       throws TransformerException
        Perform the XML encoding on the given object to the given Writer. Calls transform(Object,StreamResult);
        Throws:
        TransformerException
      • transform

        public void transform​(Object object,
                              StreamResult result)
                       throws TransformerException
        Perform the XML encoding on the given object to the given OutputStream. Calls createTransformer(),createXMLReader() and Transformer.transform().
        Throws:
        TransformerException
      • createTransformTask

        public TransformerBase.Task createTransformTask​(Object object,
                                                        StreamResult result)
                                                 throws TransformerException
        Create a Transformation task. This is a Runnable task which supports aborting any processing. It will not start until the run method is called.
        Throws:
        TransformerException
      • transform

        public String transform​(Object object)
                         throws TransformerException
        Perform the XML encoding of the given object into an internal buffer and return the resulting String. Calls transform(Object,Writer). It should be noted the most efficient mechanism of encoding is using the OutputStream or Writer methods
        Throws:
        TransformerException
      • getIndentation

        public int getIndentation()
        Get the number of spaces to indent the output xml. Defaults to -1.
        Returns:
        The number of spaces to indent, or -1, to disable.
      • setIndentation

        public void setIndentation​(int amt)
        Set the number of spaces to indent the output xml. Default to -1.
        Parameters:
        amt - The number of spaces to indent if > 0, otherwise disable.
      • getEncoding

        public Charset getEncoding()
        Gets the charset to declare in the header of the response.
        Returns:
        the charset to encode with.
      • setEncoding

        public void setEncoding​(Charset charset)
        Sets the charset to declare in the xml header returned.
        Parameters:
        charset - A charset object of the desired encoding
      • isOmitXMLDeclaration

        public boolean isOmitXMLDeclaration()
        Will this transformation omit the standard XML declaration. Defaults to false
        Returns:
        true if the XML declaration will be omitted, false otherwise.
      • setOmitXMLDeclaration

        public void setOmitXMLDeclaration​(boolean xmlDecl)
        Set this transformer to omit/include the XML declaration. Defaults to false
        Parameters:
        xmlDecl - Omit/include the XML declaration.
      • isNamespaceDeclartionEnabled

        public boolean isNamespaceDeclartionEnabled()
        Should this transformer declare namespace prefixes in the first element it outputs? Defaults to true.
        Returns:
        true if namespaces will be declared, false otherwise
      • setNamespaceDeclarationEnabled

        public void setNamespaceDeclarationEnabled​(boolean enabled)
        Enable declaration of namespace prefixes in the first element. Defaults to true;
        Parameters:
        enabled - Enable namespace declaration.