Class ExportXmlStreamWriter

    • Constructor Detail

      • ExportXmlStreamWriter

        public ExportXmlStreamWriter​(XMLStreamWriter xmlWriter,
                                     boolean prettyPrint,
                                     boolean forceOptimizedPrefix)
        Constructor of XmlStreamWriter with prettyPrint and utf-8 encoding
        Parameters:
        xmlWriter - the target XMLStreamWriter, cannot be null
        prettyPrint - enable write XML elements with indentation by level
        forceOptimizedPrefix - enable force write prefix for QNames with known XML namespace
      • ExportXmlStreamWriter

        public ExportXmlStreamWriter​(OutputStream outputStream,
                                     boolean prettyPrint,
                                     boolean forceOptimizedPrefix)
                              throws XMLStreamException,
                                     FactoryConfigurationError
        Constructor of XmlStreamWriter with prettyPrint and utf-8 encoding
        Parameters:
        outputStream - the stream to write to, cannot be null
        prettyPrint - enable write XML elements with indentation by level
        forceOptimizedPrefix - enable force write prefix for QNames with known XML namespace
        Throws:
        XMLStreamException - if an error occurred of write in stream
        FactoryConfigurationError - if an instance of XMLOutputFactory cannot be loaded
    • Method Detail

      • beginDocument

        public void beginDocument​(String xmlVersion)
                           throws XMLStreamException,
                                  ExportException

        Write xml document header with namespaces and extended xml version attribute

        Parameters:
        xmlVersion - the xml format version, cannot be null
        Throws:
        XMLStreamException - if an error occurred of write in stream
        ExportException - if export processing errors
      • writeStartDocument

        public void writeStartDocument​(String encoding,
                                       String version)
                                throws XMLStreamException
        Write the XML Declaration. Note that the encoding parameter does not set the actual encoding of the underlying output. That must be set when the instance of the XMLStreamWriter is created using the XMLOutputFactory.
        Parameters:
        encoding - encoding of the xml declaration, cannot be null
        version - version of the xml document, can be null to write default XML version
        Throws:
        XMLStreamException - if an error occurred of write in stream
      • writeStartDocument

        public void writeStartDocument​(String encoding,
                                       String version,
                                       boolean writeBom)
                                throws XMLStreamException
        Write the XML Declaration. Note that the encoding parameter does not set the actual encoding of the underlying output. That must be set when the instance of the XMLStreamWriter is created using the XMLOutputFactory.
        Parameters:
        encoding - encoding of the xml declaration, cannot be null
        version - version of the xml document, can be null to write default XML version
        writeBom - set true for writing UTF-8 BOM in start of file, or false in otherwice
        Throws:
        XMLStreamException - if an error occurred of write in stream
      • writeEndDocument

        public void writeEndDocument()
                              throws XMLStreamException
        Closes any start tags and writes corresponding end tags.
        Throws:
        XMLStreamException - if an error occurred of write in stream
      • writeAttribute

        public void writeAttribute​(String localName,
                                   Object value)
                            throws XMLStreamException,
                                   ExportException
        Write xml attribute in current element with prefix
        Parameters:
        localName - of attribute, cannot be null
        value - of attribute, cannot be null
        Throws:
        XMLStreamException - if an error occurred of write in stream
        ExportException - if an error occurred of write invalid data
      • writeAttribute

        public void writeAttribute​(String localName,
                                   String value)
                            throws XMLStreamException,
                                   ExportException
        Write xml attribute in current element without prefix
        Parameters:
        localName - of attribute, cannot be null
        value - of attribute, cannot be null
        Throws:
        XMLStreamException - if an error occurred of write in stream
        ExportException - if an error occurred of write invalid data
      • writeAttribute

        public void writeAttribute​(QName qName,
                                   Object value)
                            throws XMLStreamException,
                                   ExportException
        Write xml attribute in current element with prefix
        Parameters:
        qName - of attribute, cannot be null
        value - of attribute, cannot be null
        Throws:
        XMLStreamException - if an error occurred of write in stream
        ExportException - if an error occurred of write invalid data
      • writeAttribute

        public void writeAttribute​(QName qName,
                                   String value)
                            throws XMLStreamException,
                                   ExportException
        Write xml attribute in current element with prefix
        Parameters:
        qName - of attribute, cannot be null
        value - of attribute, cannot be null
        Throws:
        XMLStreamException - if an error occurred of write in stream
        ExportException - if an error occurred of write invalid data
      • writeCharacters

        public void writeCharacters​(String text)
                             throws XMLStreamException
        Write text to the output
        Parameters:
        text - the value to write, cannot be null
        Throws:
        XMLStreamException - if an error occurred of write in stream
      • writeDefaultNamespace

        public void writeDefaultNamespace​(String namespaceURI)
                                   throws XMLStreamException
        Writes the default namespace to the stream
        Parameters:
        namespaceURI - the uri to bind the default namespace to, cannot be null
        Throws:
        XMLStreamException - if an error occurred of write in stream
      • writeNamespace

        public void writeNamespace​(String prefix,
                                   String namespaceURI)
                            throws XMLStreamException
        Writes a namespace to the output stream If the prefix argument to this method is the empty string, "xmlns", or null this method will delegate to writeDefaultNamespace.
        Parameters:
        prefix - the prefix to bind this namespace to, cannot be null
        namespaceURI - the uri to bind the prefix to, cannot be null
        Throws:
        XMLStreamException - if an error occurred of write in stream
      • writeEmptyElement

        public void writeEmptyElement​(QName qName)
                               throws XMLStreamException
        Writes an empty element tag to the output
        Parameters:
        qName - the name of the tag, cannot be null
        Throws:
        XMLStreamException - if an error occurred of write in stream
      • writeEmptyElement

        public void writeEmptyElement​(String localName)
                               throws XMLStreamException
        Writes an empty element tag to the output
        Parameters:
        localName - the local name of the tag, cannot be null
        Throws:
        XMLStreamException - if an error occurred of write in stream
      • writeEndElement

        public void writeEndElement()
                             throws XMLStreamException
        Writes an end tag to the output relying on the internal state of the writer to determine the prefix and local name of the event.
        Throws:
        XMLStreamException - if an error occurred of write in stream
      • writeInlineEndElement

        public void writeInlineEndElement()
                                   throws XMLStreamException
        Writes an end tag to the output relying on the internal state of the writer to determine the prefix and local name of the event.
        Throws:
        XMLStreamException - if an error occurred of write in stream
      • writeStartElement

        public void writeStartElement​(String localName)
                               throws XMLStreamException
        Writes a start tag to the output
        Parameters:
        localName - local name of the tag, cannot be null
        Throws:
        XMLStreamException
      • writeStartElement

        public void writeStartElement​(QName qName)
                               throws XMLStreamException
        Writes a start tag to the output
        Parameters:
        qName - the name of the tag, cannot be null
        Throws:
        XMLStreamException - if an error occurred of write in stream
      • writeTextElement

        public void writeTextElement​(QName qName,
                                     Object obj)
                              throws XMLStreamException
        Writes a tag with text to the output
        Parameters:
        qName - the name of the tag, cannot be null
        obj - the value to write, cannot be null
        Throws:
        XMLStreamException - if an error occurred of write in stream
      • writeTextElement

        public void writeTextElement​(QName qName,
                                     String text)
                              throws XMLStreamException
        Writes a tag with text to the output
        Parameters:
        qName - the name of tag, cannot be null
        text - the value to write, cannot be null
        Throws:
        XMLStreamException - if an error occurred of write in stream
      • getPrefix

        public String getPrefix​(String uri)
                         throws XMLStreamException
        Gets the prefix the uri is bound to
        Parameters:
        uri - target namespace uri, cannot be null
        Returns:
        the prefix or null if no prifix registred for specifed URI
        Throws:
        XMLStreamException - if an error occurred of write in stream
      • getNewPrefix

        public String getNewPrefix​(String uri)
                            throws XMLStreamException
        Gets the prefix or generate new local prefix the uri is bound to
        Parameters:
        uri - target namespace uri, cannot be null
        Returns:
        the registred or generate prefix value, never null
        Throws:
        XMLStreamException - if an error occurred of write in stream
      • addKnownPrefix

        protected void addKnownPrefix​(String prefix,
                                      String namespaceURI)
        Add new alias from namespace URI to prefix.

        This prefix will be used for elements with specifed namespaceURI if this prefix not overided in XML.

        Parameters:
        prefix - the String presentation of prefix, cannot be null
        namespaceURI - the String presentation of namespace URI, cannot be null
      • optimizeQName

        protected QName optimizeQName​(QName name)
                               throws XMLStreamException
        Optimize QName before writing.

        Enable only if forceOptimizedPrefix sets true in constructor, in otherwise return given name as is.

        Parameters:
        name - input QName value to optimize, cannot be null
        Returns:
        optimized QName value, never null
        Throws:
        XMLStreamException - if an error occurred of write in stream
      • getIndent

        protected int getIndent()
        Returns the current indent value.
        Returns:
        the current indent value
      • decreaseIndent

        protected void decreaseIndent()
        Decrease indent value.
      • increaseIndent

        protected void increaseIndent()
        Increase indent value.