Class StAXDocumentSerializer

  • All Implemented Interfaces:
    javax.xml.stream.XMLStreamWriter, FastInfosetSerializer, LowLevelFastInfosetStreamWriter, org.xml.sax.ContentHandler, org.xml.sax.DTDHandler, org.xml.sax.EntityResolver, org.xml.sax.ErrorHandler

    public class StAXDocumentSerializer
    extends Encoder
    implements javax.xml.stream.XMLStreamWriter, LowLevelFastInfosetStreamWriter
    The Fast Infoset StAX serializer.

    Instantiate this serializer to serialize a fast infoset document in accordance with the StAX API.

    More than one fast infoset document may be encoded to the OutputStream.

    • Field Detail

      • _encoding

        protected java.lang.String _encoding
      • _currentLocalName

        protected java.lang.String _currentLocalName
        Local name of current element.
      • _currentUri

        protected java.lang.String _currentUri
        Namespace of current element.
      • _currentPrefix

        protected java.lang.String _currentPrefix
        Prefix of current element.
      • _inStartElement

        protected boolean _inStartElement
        This flag indicates when there is a pending start element event.
      • _isEmptyElement

        protected boolean _isEmptyElement
        This flag indicates if the current element is empty.
      • _attributesArray

        protected java.lang.String[] _attributesArray
        List of attributes qnames and values defined in the current element.
      • _attributesArrayIndex

        protected int _attributesArrayIndex
      • _nsSupportContextStack

        protected boolean[] _nsSupportContextStack
      • _stackCount

        protected int _stackCount
      • _namespacesArray

        protected java.lang.String[] _namespacesArray
        List of namespaces defined in the current element.
      • _namespacesArrayIndex

        protected int _namespacesArrayIndex
    • Constructor Detail

      • StAXDocumentSerializer

        public StAXDocumentSerializer()
      • StAXDocumentSerializer

        public StAXDocumentSerializer​(java.io.OutputStream outputStream)
      • StAXDocumentSerializer

        public StAXDocumentSerializer​(java.io.OutputStream outputStream,
                                      StAXManager manager)
    • Method Detail

      • writeStartDocument

        public void writeStartDocument()
                                throws javax.xml.stream.XMLStreamException
        Specified by:
        writeStartDocument in interface javax.xml.stream.XMLStreamWriter
        Throws:
        javax.xml.stream.XMLStreamException
      • writeStartDocument

        public void writeStartDocument​(java.lang.String version)
                                throws javax.xml.stream.XMLStreamException
        Specified by:
        writeStartDocument in interface javax.xml.stream.XMLStreamWriter
        Throws:
        javax.xml.stream.XMLStreamException
      • writeStartDocument

        public void writeStartDocument​(java.lang.String encoding,
                                       java.lang.String version)
                                throws javax.xml.stream.XMLStreamException
        Specified by:
        writeStartDocument in interface javax.xml.stream.XMLStreamWriter
        Throws:
        javax.xml.stream.XMLStreamException
      • writeEndDocument

        public void writeEndDocument()
                              throws javax.xml.stream.XMLStreamException
        Specified by:
        writeEndDocument in interface javax.xml.stream.XMLStreamWriter
        Throws:
        javax.xml.stream.XMLStreamException
      • close

        public void close()
                   throws javax.xml.stream.XMLStreamException
        Specified by:
        close in interface javax.xml.stream.XMLStreamWriter
        Throws:
        javax.xml.stream.XMLStreamException
      • flush

        public void flush()
                   throws javax.xml.stream.XMLStreamException
        Specified by:
        flush in interface javax.xml.stream.XMLStreamWriter
        Throws:
        javax.xml.stream.XMLStreamException
      • writeStartElement

        public void writeStartElement​(java.lang.String localName)
                               throws javax.xml.stream.XMLStreamException
        Specified by:
        writeStartElement in interface javax.xml.stream.XMLStreamWriter
        Throws:
        javax.xml.stream.XMLStreamException
      • writeStartElement

        public void writeStartElement​(java.lang.String namespaceURI,
                                      java.lang.String localName)
                               throws javax.xml.stream.XMLStreamException
        Specified by:
        writeStartElement in interface javax.xml.stream.XMLStreamWriter
        Throws:
        javax.xml.stream.XMLStreamException
      • writeStartElement

        public void writeStartElement​(java.lang.String prefix,
                                      java.lang.String localName,
                                      java.lang.String namespaceURI)
                               throws javax.xml.stream.XMLStreamException
        Specified by:
        writeStartElement in interface javax.xml.stream.XMLStreamWriter
        Throws:
        javax.xml.stream.XMLStreamException
      • writeEmptyElement

        public void writeEmptyElement​(java.lang.String localName)
                               throws javax.xml.stream.XMLStreamException
        Specified by:
        writeEmptyElement in interface javax.xml.stream.XMLStreamWriter
        Throws:
        javax.xml.stream.XMLStreamException
      • writeEmptyElement

        public void writeEmptyElement​(java.lang.String namespaceURI,
                                      java.lang.String localName)
                               throws javax.xml.stream.XMLStreamException
        Specified by:
        writeEmptyElement in interface javax.xml.stream.XMLStreamWriter
        Throws:
        javax.xml.stream.XMLStreamException
      • writeEmptyElement

        public void writeEmptyElement​(java.lang.String prefix,
                                      java.lang.String localName,
                                      java.lang.String namespaceURI)
                               throws javax.xml.stream.XMLStreamException
        Specified by:
        writeEmptyElement in interface javax.xml.stream.XMLStreamWriter
        Throws:
        javax.xml.stream.XMLStreamException
      • writeEndElement

        public void writeEndElement()
                             throws javax.xml.stream.XMLStreamException
        Specified by:
        writeEndElement in interface javax.xml.stream.XMLStreamWriter
        Throws:
        javax.xml.stream.XMLStreamException
      • writeAttribute

        public void writeAttribute​(java.lang.String localName,
                                   java.lang.String value)
                            throws javax.xml.stream.XMLStreamException
        Specified by:
        writeAttribute in interface javax.xml.stream.XMLStreamWriter
        Throws:
        javax.xml.stream.XMLStreamException
      • writeAttribute

        public void writeAttribute​(java.lang.String namespaceURI,
                                   java.lang.String localName,
                                   java.lang.String value)
                            throws javax.xml.stream.XMLStreamException
        Specified by:
        writeAttribute in interface javax.xml.stream.XMLStreamWriter
        Throws:
        javax.xml.stream.XMLStreamException
      • writeAttribute

        public void writeAttribute​(java.lang.String prefix,
                                   java.lang.String namespaceURI,
                                   java.lang.String localName,
                                   java.lang.String value)
                            throws javax.xml.stream.XMLStreamException
        Specified by:
        writeAttribute in interface javax.xml.stream.XMLStreamWriter
        Throws:
        javax.xml.stream.XMLStreamException
      • writeNamespace

        public void writeNamespace​(java.lang.String prefix,
                                   java.lang.String namespaceURI)
                            throws javax.xml.stream.XMLStreamException
        Specified by:
        writeNamespace in interface javax.xml.stream.XMLStreamWriter
        Throws:
        javax.xml.stream.XMLStreamException
      • writeDefaultNamespace

        public void writeDefaultNamespace​(java.lang.String namespaceURI)
                                   throws javax.xml.stream.XMLStreamException
        Specified by:
        writeDefaultNamespace in interface javax.xml.stream.XMLStreamWriter
        Throws:
        javax.xml.stream.XMLStreamException
      • writeComment

        public void writeComment​(java.lang.String data)
                          throws javax.xml.stream.XMLStreamException
        Specified by:
        writeComment in interface javax.xml.stream.XMLStreamWriter
        Throws:
        javax.xml.stream.XMLStreamException
      • writeProcessingInstruction

        public void writeProcessingInstruction​(java.lang.String target)
                                        throws javax.xml.stream.XMLStreamException
        Specified by:
        writeProcessingInstruction in interface javax.xml.stream.XMLStreamWriter
        Throws:
        javax.xml.stream.XMLStreamException
      • writeProcessingInstruction

        public void writeProcessingInstruction​(java.lang.String target,
                                               java.lang.String data)
                                        throws javax.xml.stream.XMLStreamException
        Specified by:
        writeProcessingInstruction in interface javax.xml.stream.XMLStreamWriter
        Throws:
        javax.xml.stream.XMLStreamException
      • writeCData

        public void writeCData​(java.lang.String text)
                        throws javax.xml.stream.XMLStreamException
        Specified by:
        writeCData in interface javax.xml.stream.XMLStreamWriter
        Throws:
        javax.xml.stream.XMLStreamException
      • writeDTD

        public void writeDTD​(java.lang.String dtd)
                      throws javax.xml.stream.XMLStreamException
        Specified by:
        writeDTD in interface javax.xml.stream.XMLStreamWriter
        Throws:
        javax.xml.stream.XMLStreamException
      • writeEntityRef

        public void writeEntityRef​(java.lang.String name)
                            throws javax.xml.stream.XMLStreamException
        Specified by:
        writeEntityRef in interface javax.xml.stream.XMLStreamWriter
        Throws:
        javax.xml.stream.XMLStreamException
      • writeCharacters

        public void writeCharacters​(java.lang.String text)
                             throws javax.xml.stream.XMLStreamException
        Specified by:
        writeCharacters in interface javax.xml.stream.XMLStreamWriter
        Throws:
        javax.xml.stream.XMLStreamException
      • writeCharacters

        public void writeCharacters​(char[] text,
                                    int start,
                                    int len)
                             throws javax.xml.stream.XMLStreamException
        Specified by:
        writeCharacters in interface javax.xml.stream.XMLStreamWriter
        Throws:
        javax.xml.stream.XMLStreamException
      • getPrefix

        public java.lang.String getPrefix​(java.lang.String uri)
                                   throws javax.xml.stream.XMLStreamException
        Specified by:
        getPrefix in interface javax.xml.stream.XMLStreamWriter
        Throws:
        javax.xml.stream.XMLStreamException
      • setPrefix

        public void setPrefix​(java.lang.String prefix,
                              java.lang.String uri)
                       throws javax.xml.stream.XMLStreamException
        Specified by:
        setPrefix in interface javax.xml.stream.XMLStreamWriter
        Throws:
        javax.xml.stream.XMLStreamException
      • setDefaultNamespace

        public void setDefaultNamespace​(java.lang.String uri)
                                 throws javax.xml.stream.XMLStreamException
        Specified by:
        setDefaultNamespace in interface javax.xml.stream.XMLStreamWriter
        Throws:
        javax.xml.stream.XMLStreamException
      • setNamespaceContext

        public void setNamespaceContext​(javax.xml.namespace.NamespaceContext context)
                                 throws javax.xml.stream.XMLStreamException
        Sets the current namespace context for prefix and uri bindings. This context becomes the root namespace context for writing and will replace the current root namespace context. Subsequent calls to setPrefix and setDefaultNamespace will bind namespaces using the context passed to the method as the root context for resolving namespaces. This method may only be called once at the start of the document. It does not cause the namespaces to be declared. If a namespace URI to prefix mapping is found in the namespace context it is treated as declared and the prefix may be used by the StreamWriter.
        Specified by:
        setNamespaceContext in interface javax.xml.stream.XMLStreamWriter
        Parameters:
        context - the namespace context to use for this writer, may not be null
        Throws:
        javax.xml.stream.XMLStreamException
      • getNamespaceContext

        public javax.xml.namespace.NamespaceContext getNamespaceContext()
        Specified by:
        getNamespaceContext in interface javax.xml.stream.XMLStreamWriter
      • getProperty

        public java.lang.Object getProperty​(java.lang.String name)
                                     throws java.lang.IllegalArgumentException
        Specified by:
        getProperty in interface javax.xml.stream.XMLStreamWriter
        Throws:
        java.lang.IllegalArgumentException
      • setManager

        public void setManager​(StAXManager manager)
      • setEncoding

        public void setEncoding​(java.lang.String encoding)
      • writeOctets

        public void writeOctets​(byte[] b,
                                int start,
                                int len)
                         throws javax.xml.stream.XMLStreamException
        Throws:
        javax.xml.stream.XMLStreamException
      • encodeTerminationAndCurrentElement

        protected void encodeTerminationAndCurrentElement​(boolean terminateAfter)
                                                   throws javax.xml.stream.XMLStreamException
        Throws:
        javax.xml.stream.XMLStreamException
      • getNextElementIndex

        public final int getNextElementIndex()
        Description copied from interface: LowLevelFastInfosetStreamWriter
        Get the next index to apply to an Element Information Item.

        This will increment the next obtained index such that:

         i = w.getNextElementIndex();
         j = w.getNextElementIndex();
         i == j + 1;
         
        Specified by:
        getNextElementIndex in interface LowLevelFastInfosetStreamWriter
        Returns:
        the index.
      • getNextAttributeIndex

        public final int getNextAttributeIndex()
        Description copied from interface: LowLevelFastInfosetStreamWriter
        Get the next index to apply to an Attribute Information Item. This will increment the next obtained index such that:
         i = w.getNextAttributeIndex();
         j = w.getNextAttributeIndex();
         i == j + 1;
         
        Specified by:
        getNextAttributeIndex in interface LowLevelFastInfosetStreamWriter
        Returns:
        the index.
      • getNextLocalNameIndex

        public final int getNextLocalNameIndex()
        Description copied from interface: LowLevelFastInfosetStreamWriter
        Get the next index to apply to an [local name] of an Element or Attribute Information Item. This will increment the next obtained index such that:
         i = w.getNextLocalNameIndex();
         j = w.getNextLocalNameIndex();
         i == j + 1;
         
        Specified by:
        getNextLocalNameIndex in interface LowLevelFastInfosetStreamWriter
        Returns:
        the index.
      • writeLowLevelStartElement

        public final boolean writeLowLevelStartElement​(int type,
                                                       java.lang.String prefix,
                                                       java.lang.String localName,
                                                       java.lang.String namespaceURI)
                                                throws java.io.IOException
        Description copied from interface: LowLevelFastInfosetStreamWriter
        Write the start of an element.
        Specified by:
        writeLowLevelStartElement in interface LowLevelFastInfosetStreamWriter
        Returns:
        true if element is indexed, otherwise false.
        Throws:
        java.io.IOException
      • writeLowLevelNamespace

        public final void writeLowLevelNamespace​(java.lang.String prefix,
                                                 java.lang.String namespaceName)
                                          throws java.io.IOException
        Specified by:
        writeLowLevelNamespace in interface LowLevelFastInfosetStreamWriter
        Throws:
        java.io.IOException
      • writeLowLevelAttribute

        public final boolean writeLowLevelAttribute​(java.lang.String prefix,
                                                    java.lang.String namespaceURI,
                                                    java.lang.String localName)
                                             throws java.io.IOException
        Description copied from interface: LowLevelFastInfosetStreamWriter
        Write an attribute.
        Specified by:
        writeLowLevelAttribute in interface LowLevelFastInfosetStreamWriter
        Returns:
        true if attribute is indexed, otherwise false.
        Throws:
        java.io.IOException
      • writeLowLevelStartNameLiteral

        public final void writeLowLevelStartNameLiteral​(int type,
                                                        java.lang.String prefix,
                                                        byte[] utf8LocalName,
                                                        java.lang.String namespaceURI)
                                                 throws java.io.IOException
        Specified by:
        writeLowLevelStartNameLiteral in interface LowLevelFastInfosetStreamWriter
        Throws:
        java.io.IOException
      • writeLowLevelStartNameLiteral

        public final void writeLowLevelStartNameLiteral​(int type,
                                                        java.lang.String prefix,
                                                        int localNameIndex,
                                                        java.lang.String namespaceURI)
                                                 throws java.io.IOException
        Specified by:
        writeLowLevelStartNameLiteral in interface LowLevelFastInfosetStreamWriter
        Throws:
        java.io.IOException
      • encodeElement

        private boolean encodeElement​(int type,
                                      java.lang.String namespaceURI,
                                      java.lang.String prefix,
                                      java.lang.String localName)
                               throws java.io.IOException
        Throws:
        java.io.IOException
      • encodeAttribute

        private boolean encodeAttribute​(java.lang.String namespaceURI,
                                        java.lang.String prefix,
                                        java.lang.String localName)
                                 throws java.io.IOException
        Throws:
        java.io.IOException
      • encodeLiteralHeader

        private void encodeLiteralHeader​(int type,
                                         java.lang.String namespaceURI,
                                         java.lang.String prefix)
                                  throws java.io.IOException
        Throws:
        java.io.IOException
      • encodeLiteral

        private void encodeLiteral​(int type,
                                   java.lang.String namespaceURI,
                                   java.lang.String prefix,
                                   java.lang.String localName)
                            throws java.io.IOException
        Throws:
        java.io.IOException