|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.deegree.commons.xml.stax.XMLStreamUtils
public class XMLStreamUtils
General XML stream manipulation utilities.
This class provides static utility methods for operations on XMLStreamReaders
/ XMLStreamWriters
.
Constructor Summary | |
---|---|
XMLStreamUtils()
|
Method Summary | |
---|---|
static QName |
asQName(XMLStreamReader xmlStream,
String s)
|
static void |
copy(XMLStreamWriter writer,
XMLStreamReader reader)
Copies an XML element (including all attributes and subnodes) from the given XMLStreamReader to the given
XMLStreamWriter . |
static Document |
getAsDocument(XMLStreamReader xmlStreamReader)
makes a Document out of a XMLStreamReader |
static Map<QName,String> |
getAttributes(XMLStreamReader reader)
Returns the attributes of the element that the given XMLStreamReader points to. |
static String |
getAttributeValue(XMLStreamReader xmlStream,
String localName)
|
static boolean |
getAttributeValueAsBoolean(XMLStreamReader xmlStream,
String namespaceURI,
String localName,
boolean defaultValue)
|
static QName |
getAttributeValueAsQName(XMLStreamReader xmlStream,
String namespaceURI,
String localName,
QName defaultValue)
|
static String |
getCurrentEventInfo(XMLStreamReader xmlStream)
Creates printable (debug) information about the event that the cursor of the given XMLStreamReader
currently points at. |
static boolean |
getElementTextAsBoolean(XMLStreamReader xmlStream)
|
static boolean |
getElementTextAsBoolean(XMLStreamReader reader,
QName elementName,
boolean defaultValue,
boolean nextElemOnSucces)
Post: reader will be unchanged or at XMLStreamConstants.END_ELEMENT of the matching element or at
#START_ELEMENT of the next element if requested. |
static double |
getElementTextAsDouble(XMLStreamReader reader,
QName elementName,
double defaultValue,
boolean nextElemOnSucces)
Post: reader will be unchanged or on success at #END_ELEMENT of the matching element
or at #START_ELEMENT of the next element if requested. |
static int |
getElementTextAsInteger(XMLStreamReader reader,
QName elementName,
int defaultValue,
boolean nextElemOnSucces)
Post: reader will be unchanged or on success at #END_ELEMENT of the matching element
or at #START_ELEMENT of the next element if requested. |
static QName |
getElementTextAsQName(XMLStreamReader xmlStream)
|
static String |
getEventTypeString(int eventType)
|
static String |
getRequiredAttributeValue(XMLStreamReader xmlStream,
String localName)
|
static String |
getRequiredAttributeValue(XMLStreamReader xmlStream,
String namespaceURI,
String localName)
|
static boolean |
getRequiredAttributeValueAsBoolean(XMLStreamReader xmlStream,
String namespaceURI,
String localName)
|
static QName |
getRequiredAttributeValueAsQName(XMLStreamReader xmlStream,
String namespaceURI,
String localName)
|
static double |
getRequiredElementTextAsDouble(XMLStreamReader reader,
QName elementName,
boolean nextElemOnSucces)
Returns the text in the required element as a double. |
static String |
getRequiredText(XMLStreamReader reader,
QName elementName,
boolean nextElemOnSucces)
Get the text of the given element which must be an element with given name. |
static String[] |
getSimpleUnboundedAsStrings(XMLStreamReader reader,
QName name)
The reader must be on a StartElement, any attributes will be skipped. |
static String |
getText(XMLStreamReader reader,
QName elemName,
String defaultText,
boolean nextElemOnSucces)
Get the text of the element or if the reader does not match the given elementName the default text will be returned. |
static boolean |
moveReaderToFirstMatch(XMLStreamReader reader,
Collection<QName> alowedElements)
Move the reader to the first element which matches one of the given name(s). |
static boolean |
moveReaderToFirstMatch(XMLStreamReader reader,
QName elementName)
Move the reader to the first element which matches the given name. |
static int |
nextElement(XMLStreamReader xmlReader)
Move the reader to the next #START_ELEMENT or #END_ELEMENT
event. |
static void |
require(XMLStreamReader xmlStream,
int eventType)
|
static void |
requireNextTag(XMLStreamReader xmlStream,
int eventType)
|
static void |
requireStartElement(XMLStreamReader xmlStream,
Collection<QName> expectedElements)
|
static URL |
resolve(String url,
XMLStreamReader in)
|
static StreamBufferStore |
serialize(XMLStreamReader reader)
Serializes the XML element (including all attributes and subnodes) from the given XMLStreamReader into a
StreamBufferStore . |
static void |
skipElement(XMLStreamReader xmlStream)
Skips all events that belong to the current element (including descendant elements), so that the XMLStreamReader cursor points at the corresponding END_ELEMENT event. |
static void |
skipRequiredElement(XMLStreamReader reader,
QName elementName)
Skips to the next element if the reader points the required element. |
static void |
skipStartDocument(XMLStreamReader xmlStream)
|
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public XMLStreamUtils()
Method Detail |
---|
public static final String getCurrentEventInfo(XMLStreamReader xmlStream)
XMLStreamReader
currently points at.
xmlStream
-
public static void skipElement(XMLStreamReader xmlStream) throws XMLStreamException
XMLStreamReader
cursor points at the corresponding END_ELEMENT
event.
xmlStream
-
XMLStreamException
public static URL resolve(String url, XMLStreamReader in) throws MalformedURLException
url
- in
-
MalformedURLException
public static QName asQName(XMLStreamReader xmlStream, String s)
xmlStream
- s
- may not be null
public static void skipStartDocument(XMLStreamReader xmlStream) throws XMLStreamException
XMLStreamException
public static String getAttributeValue(XMLStreamReader xmlStream, String localName) throws XMLParsingException
XMLParsingException
public static String getRequiredAttributeValue(XMLStreamReader xmlStream, String localName) throws XMLParsingException
XMLParsingException
public static String getRequiredAttributeValue(XMLStreamReader xmlStream, String namespaceURI, String localName) throws XMLParsingException
XMLParsingException
public static QName getRequiredAttributeValueAsQName(XMLStreamReader xmlStream, String namespaceURI, String localName) throws XMLParsingException
XMLParsingException
public static QName getAttributeValueAsQName(XMLStreamReader xmlStream, String namespaceURI, String localName, QName defaultValue) throws XMLParsingException
XMLParsingException
public static boolean getElementTextAsBoolean(XMLStreamReader xmlStream) throws XMLStreamException
xmlStream
-
XMLStreamException
public static boolean getElementTextAsBoolean(XMLStreamReader reader, QName elementName, boolean defaultValue, boolean nextElemOnSucces) throws XMLStreamException
XMLStreamConstants.END_ELEMENT
of the matching element or at
#START_ELEMENT
of the next element if requested.
reader
- elementName
- defaultValue
- nextElemOnSucces
- if true the reader will be moved to the next tag if the retrieval was successful.
XMLStreamException
public static boolean getAttributeValueAsBoolean(XMLStreamReader xmlStream, String namespaceURI, String localName, boolean defaultValue) throws XMLParsingException
XMLParsingException
public static QName getElementTextAsQName(XMLStreamReader xmlStream) throws XMLParsingException, XMLStreamException
XMLParsingException
XMLStreamException
public static void requireStartElement(XMLStreamReader xmlStream, Collection<QName> expectedElements) throws XMLParsingException
XMLParsingException
public static void require(XMLStreamReader xmlStream, int eventType) throws XMLParsingException
XMLParsingException
public static void requireNextTag(XMLStreamReader xmlStream, int eventType) throws XMLParsingException, XMLStreamException
XMLParsingException
XMLStreamException
public static final String getEventTypeString(int eventType)
public static boolean getRequiredAttributeValueAsBoolean(XMLStreamReader xmlStream, String namespaceURI, String localName)
public static String getText(XMLStreamReader reader, QName elemName, String defaultText, boolean nextElemOnSucces) throws XMLStreamException
XMLStreamConstants.END_ELEMENT
of the matching element or
at #START_ELEMENT
of the next element if requested.
reader
- elemName
- defaultText
- nextElemOnSucces
- if true the reader will be moved to the next tag if the retrieval was successful.
XMLStreamException
public static void skipRequiredElement(XMLStreamReader reader, QName elementName) throws XMLStreamException
XMLStreamConstants.START_ELEMENT
of the next element.
reader
- elementName
-
XMLStreamException
public static String getRequiredText(XMLStreamReader reader, QName elementName, boolean nextElemOnSucces) throws XMLStreamException
XMLStreamConstants.END_ELEMENT
of matching element or at #START_ELEMENT
of the
next element if requested.
reader
- elementName
- nextElemOnSucces
- if true the reader will be moved to the next tag if the retrieval was successful.
XMLStreamException
public static String[] getSimpleUnboundedAsStrings(XMLStreamReader reader, QName name) throws XMLStreamException
XMLStreamConstants.START_ELEMENT
of the first element after the last matching element
reader
- name
- of the elements
XMLStreamException
public static int nextElement(XMLStreamReader xmlReader) throws XMLStreamException, NoSuchElementException
#START_ELEMENT
or #END_ELEMENT
event.
xmlReader
-
XMLStreamException
NoSuchElementException
- if the end of the document is reachedpublic static double getElementTextAsDouble(XMLStreamReader reader, QName elementName, double defaultValue, boolean nextElemOnSucces) throws XMLStreamException
#END_ELEMENT
of the matching element
or at #START_ELEMENT
of the next element if requested.
reader
- pointing to the current element.elementName
- of the current element.defaultValue
- to return if the current name was not the one given or the value could not be parsed as a double.nextElemOnSucces
- if true the reader will be moved to the next tag if the retrieval was successful.
XMLStreamException
- from XMLStreamReader.getElementText()
.public static int getElementTextAsInteger(XMLStreamReader reader, QName elementName, int defaultValue, boolean nextElemOnSucces) throws XMLStreamException
#END_ELEMENT
of the matching element
or at #START_ELEMENT
of the next element if requested.
reader
- pointing to the current element.elementName
- of the current element.defaultValue
- to return if the current name was not the one given or the value could not be parsed as a integer.nextElemOnSucces
- if true the reader will be moved to the next tag if the retrieval was successful.
XMLStreamException
- from XMLStreamReader.getElementText()
.public static double getRequiredElementTextAsDouble(XMLStreamReader reader, QName elementName, boolean nextElemOnSucces) throws XMLStreamException
#END_ELEMENT
of the matching element or at
#START_ELEMENT
of the next element if requested.
reader
- elementName
- nextElemOnSucces
- if true the reader will be move to the next element if the operation was successful.
XMLStreamException
public static boolean moveReaderToFirstMatch(XMLStreamReader reader, QName elementName) throws XMLStreamException
XMLStreamConstants.START_ELEMENT
event or after the XMLStreamConstants.END_DOCUMENT
which ever
comes first.
reader
- to positionelementName
- name of the element to move forward to.
XMLStreamException
public static boolean moveReaderToFirstMatch(XMLStreamReader reader, Collection<QName> alowedElements) throws XMLStreamException
XMLStreamConstants.START_ELEMENT
event or after the XMLStreamConstants.END_DOCUMENT
which ever
comes first.
reader
- to positionalowedElements
- name of the element to move forward to.
XMLStreamException
public static Map<QName,String> getAttributes(XMLStreamReader reader)
XMLStreamReader
points to.
reader
- xml stream, must not be null
and point to a XMLStreamConstants.START_ELEMENT
null
public static Document getAsDocument(XMLStreamReader xmlStreamReader) throws XMLStreamException, FactoryConfigurationError, ParserConfigurationException, SAXException, IOException
Document
out of a XMLStreamReader
xmlStreamReader
- the xmlStreamRader to convert
Document
FactoryConfigurationError
XMLStreamException
ParserConfigurationException
IOException
SAXException
public static void copy(XMLStreamWriter writer, XMLStreamReader reader) throws XMLStreamException
XMLStreamReader
to the given
XMLStreamWriter
.
writer
- XMLStreamWriter
that the xml is appended toreader
- cursor must point at a START_ELEMENT
event and points at the corresponding
END_ELEMENT
event afterwards
XMLStreamException
public static StreamBufferStore serialize(XMLStreamReader reader) throws IOException, XMLStreamException, FactoryConfigurationError
XMLStreamReader
into a
StreamBufferStore
.
reader
- cursor must point at a START_ELEMENT
event and points at the corresponding
END_ELEMENT
event afterwards
null
IOException
FactoryConfigurationError
XMLStreamException
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |