Class StAXStreamReader

  • All Implemented Interfaces:
    java.lang.Cloneable

    public final class StAXStreamReader
    extends java.lang.Object
    implements java.lang.Cloneable
    Represents a JDOM document as a StAX XMLStreamReader that can be read from.

    The StAXStreamReader can manage many styles of document formatting, from untouched to 'pretty' printed. The default is to output the document content exactly as created, but this can be changed by setting a new Format object:

    There is only one output(Document) method that exposes a JDOM Document as a StAX Stream.

    If changing the Format settings are insufficient for your output needs you can customise this StAXStreamReader further by setting a different StAXStreamReaderProcessor with the setStAXAsStreamProcessor(StAXStreamReaderProcessor) method or an appropriate constructor. A fully-enabled Abstract class AbstractStAXStreamReaderProcessor is available to be further extended to your needs if all you want to do is tweak some details.

    Since:
    JDOM 2.1.0
    Author:
    Rolf Lear
    • Constructor Detail

      • StAXStreamReader

        public StAXStreamReader​(Format format,
                                StAXStreamReaderProcessor processor)
        This will create an XMLOutputter with the specified format characteristics.

        Note: the format object is cloned internally before use. If you want to modify the Format after constructing the XMLOutputter you can modify the Format instance getFormat() returns.

        Parameters:
        format - The Format instance to use. This instance will be cloned() and as a consequence, changes made to the specified format instance will not be reflected in this XMLOutputter. A null input format indicates that XMLOutputter should use the default Format.getRawFormat()
        processor - The XMLOutputProcessor to delegate output to. If null the XMLOutputter will use the default XMLOutputProcessor.
      • StAXStreamReader

        public StAXStreamReader​(StAXStreamReader that)
        This will create an XMLOutputter with the same customisations set in the given XMLOutputter instance. Note that XMLOutputter two = one.clone(); would work equally well.
        Parameters:
        that - the XMLOutputter to clone
      • StAXStreamReader

        public StAXStreamReader​(Format format)
        This will create an XMLOutputter with the specified format characteristics.

        Note: the format object is cloned internally before use.

        Parameters:
        format - The Format instance to use. This instance will be cloned() and as a consequence, changes made to the specified format instance will not be reflected in this XMLOutputter. A null input format indicates that XMLOutputter should use the default Format.getRawFormat()
      • StAXStreamReader

        public StAXStreamReader​(StAXStreamReaderProcessor processor)
        This will create an XMLOutputter with the specified XMLOutputProcessor.
        Parameters:
        processor - The XMLOutputProcessor to delegate output to. If null the XMLOutputter will use the default XMLOutputProcessor.
    • Method Detail

      • setFormat

        public void setFormat​(Format newFormat)
        Sets the new format logic for the XMLOutputter. Note the Format object is cloned internally before use.
        Parameters:
        newFormat - the format to use for subsequent output
        See Also:
        getFormat()
      • getFormat

        public Format getFormat()
        Returns the current format in use by the XMLOutputter. Note the Format object returned is not a clone of the one used internally, thus, an XMLOutputter instance is able to have its Format changed by changing the settings on the Format instance returned by this method.
        Returns:
        the current Format instance used by this XMLOutputter.
      • getStAXAsStreamProcessor

        public StAXStreamReaderProcessor getStAXAsStreamProcessor()
        Returns the current XMLOutputProcessor instance in use by the StAXStreamReader.
        Returns:
        the current XMLOutputProcessor instance.
      • setStAXAsStreamProcessor

        public void setStAXAsStreamProcessor​(StAXStreamReaderProcessor processor)
        Sets a new StAXStreamReaderProcessor instance for this StAXStreamReader. Note the processor object is expected to be thread-safe.
        Parameters:
        processor - the new XMLOutputProcesor to use for output
      • output

        public final javax.xml.stream.XMLStreamReader output​(Document doc)
        This will expose the Document as a StAX XMLStreamReader.
        Parameters:
        doc - Document to format.
        Returns:
        The XMLStreamReader representing the input Document.
        Throws:
        java.lang.NullPointerException - if the specified content is null.
      • clone

        public StAXStreamReader clone()
        Returns a cloned copy of this XMLOutputter.
        Overrides:
        clone in class java.lang.Object
      • toString

        public java.lang.String toString()
        Return a string listing of the settings for this XMLOutputter instance.
        Overrides:
        toString in class java.lang.Object
        Returns:
        a string listing the settings for this XMLOutputter instance