Package org.apache.axiom.util.stax
Class XMLStreamReaderUtils
java.lang.Object
org.apache.axiom.util.stax.XMLStreamReaderUtils
Contains utility methods to work with
XMLStreamReader objects, including the extension
defined by BlobReader.-
Method Summary
Modifier and TypeMethodDescriptionstatic BlobgetBlobFromElement(XMLStreamReader reader) Get aBlobfor the binary data encoded in an element.static BlobReadergetBlobReader(XMLStreamReader reader) Get theBlobReaderextension for a givenXMLStreamReader, if available.static ReadergetElementTextAsStream(XMLStreamReader reader, boolean allowNonTextChildren) Get the text content of the current element as aReaderobject.static XMLStreamReaderDeprecated.As of version 1.3.0, Axiom no longer permits access to the original stream reader.static ObjectprocessGetProperty(BlobReader extension, String propertyName) Helper method to implementXMLStreamReader.getProperty(String).static voidwriteTextTo(XMLStreamReader reader, Writer writer) Get the character data for the current event from the given reader and write it to the given writer.
-
Method Details
-
getBlobReader
Get theBlobReaderextension for a givenXMLStreamReader, if available.- Parameters:
reader- the stream reader to get theBlobReaderextension from- Returns:
- the implementation of the extension, or
nullif theXMLStreamReaderdoesn't expose base64 encoded binary content asBlobobjects.
-
processGetProperty
Helper method to implementXMLStreamReader.getProperty(String). This method processes the property defined byBlobReader.PROPERTY.- Parameters:
extension- the reference to theBlobReaderextension for theXMLStreamReaderimplementationpropertyName- the name of the property, as passed to theXMLStreamReader.getProperty(String)method- Returns:
- the property value as specified by the
BlobReaderextension;nullif the property doesn't match
-
getBlobFromElement
Get aBlobfor the binary data encoded in an element. The method supports base64 encoded character data as well as optimized binary data through theBlobReaderextension.Precondition: the reader is on a
XMLStreamConstants.START_ELEMENTPostcondition: the reader is on the corresponding
XMLStreamConstants.END_ELEMENT- Parameters:
reader- the stream to read the data from- Returns:
- the binary data from the element
- Throws:
XMLStreamException
-
writeTextTo
public static void writeTextTo(XMLStreamReader reader, Writer writer) throws XMLStreamException, IOException Get the character data for the current event from the given reader and write it to the given writer. The method will try to figure out the most efficient way to copy the data without unnecessary buffering or conversions between strings and character arrays.- Parameters:
reader- the reader to get the character data fromwriter- the writer to write the character data to- Throws:
XMLStreamException- if the underlying XML source is not well-formedIOException- if an I/O error occurs when writing the character dataIllegalStateException- if this state is not a valid text state.- See Also:
-
getElementTextAsStream
Get the text content of the current element as aReaderobject.- Parameters:
reader- The XML stream reader to read the element text from. The reader must be positioned on aXMLStreamConstants.START_ELEMENTevent.allowNonTextChildren- If set totrue, non text child nodes are allowed and skipped. If set tofalseonly text nodes are allowed and the presence of any other type of child node will trigger an exception.- Returns:
- The reader from which the element text can be read. After the reader has reported the
end of the stream, the XML stream reader will be positioned on the
XMLStreamConstants.END_ELEMENTevent corresponding to the initialXMLStreamConstants.START_ELEMENTevent. CallingReader.close()on the returned reader has no effect. Any parser exception will be reported by the reader usingXMLStreamIOException. - Throws:
IllegalStateException- if the XML stream reader is not positioned on aXMLStreamConstants.START_ELEMENTevent
-
getOriginalXMLStreamReader
Deprecated.As of version 1.3.0, Axiom no longer permits access to the original stream reader.Searches the wrapper and delegate classes to find the originalXMLStreamReader. This method should only be used when a consumer of Axiom really needs to access the original stream reader.- Parameters:
parser- XMLStreamReader used by Axiom- Returns:
- original parser
-