public class XMLStreamReaderUtils extends Object
XMLStreamReaderobjects, including the extension defined by
DataHandlerReader. In addition to
DataHandlerReadersupport, this class also provides support for the legacy extension mechanism described below.
XMLStreamReader instances supporting the legacy extension must conform to the following
Boolean.TRUEfor the property identified by
OMConstants.IS_DATA_HANDLERS_AWARE, regardless of the current event. The property is assumed to be immutable and its value must not change during the lifetime of the
To maintain compatibility with consumers that are unaware of the extensions described here, the
implementation should make sure that
XMLStreamReader.getTextCharacters(int, char, int, int) and
XMLStreamReader.getElementText() behave as expected for this type of event, i.e. return
the base64 representation of the binary content.
Boolean.TRUEfor the property identified by
OMConstants.IS_BINARYif the current event is a
XMLStreamConstants.CHARACTERSevent representing base64 encoded binary content and for which a
DataHandleris available. For all other events, the returned value must be
If for a given event, the implementation returned
Boolean.TRUE for the
OMConstants.IS_BINARY property, then a call to
XMLStreamReader.getProperty(String) with argument
OMConstants.DATA_HANDLER must return the corresponding
OMConstants.DATA_HANDLER property is undefined for any other type
of event. This implies that the consumer of the
XMLStreamReader must check the
OMConstants.IS_BINARY property before retrieving the
|Modifier and Type||Method and Description|
Get the text content of the current element as a
Searches the wrapper and delegate classes to find the original
Helper method to implement
Get the character data for the current event from the given reader and write it to the given writer.
public static DataHandlerReader getDataHandlerReader(XMLStreamReader reader)
DataHandlerReaderextension for a given
XMLStreamReader, if available. If the
XMLStreamReaderonly supports the legacy extension (as described above), then this method will return a compatibility wrapper. Note that this wrapper doesn't support deferred loading of the binary content.
public static Object processGetProperty(DataHandlerReader extension, String propertyName)
XMLStreamReader.getProperty(String). This method processes the properties defined by
DataHandlerReader.PROPERTYand the legacy extension mechanism (as described above). It can therefore be used to make a
XMLStreamReaderimplementation compatible with code that expects it to implement this legacy extension.
extension- the reference to the
DataHandlerReaderextension for the
propertyName- the name of the property, as passed to the
DataHandlerReaderor legacy extension;
nullif the property is not specified by any of these two extensions
public static DataHandler getDataHandlerFromElement(XMLStreamReader reader) throws XMLStreamException
DataHandlerfor the binary data encoded in an element. The method supports base64 encoded character data as well as optimized binary data through the
Precondition: the reader is on a
Postcondition: the reader is on the corresponding
reader- the stream to read the data from
public static void writeTextTo(XMLStreamReader reader, Writer writer) throws XMLStreamException, IOException
reader- the reader to get the character data from
writer- the writer to write the character data to
XMLStreamException- if the underlying XML source is not well-formed
IOException- if an I/O error occurs when writing the character data
IllegalStateException- if this state is not a valid text state.
public static Reader getElementTextAsStream(XMLStreamReader reader, boolean allowNonTextChildren)
reader- The XML stream reader to read the element text from. The reader must be positioned on a
allowNonTextChildren- If set to
true, non text child nodes are allowed and skipped. If set to
falseonly text nodes are allowed and the presence of any other type of child node will trigger an exception.
XMLStreamConstants.END_ELEMENTevent corresponding to the initial
Reader.close()on the returned reader has no effect. Any parser exception will be reported by the reader using
IllegalStateException- if the XML stream reader is not positioned on a
public static XMLStreamReader getOriginalXMLStreamReader(XMLStreamReader parser)
XMLStreamReader. This method should only be used when a consumer of Axiom really needs to access the original stream reader.
parser- XMLStreamReader used by Axiom
Copyright ? The Apache Software Foundation. All Rights Reserved.