public final class StaxUtilImpl extends AbstractLoggableComponent implements StaxUtil
| Modifier and Type | Field and Description |
|---|---|
private static StaxUtil |
instance |
private StringValueConverter |
valueConverter |
private XMLInputFactory |
xmlInputFactory |
private XMLOutputFactory |
xmlOutputFactory |
| Constructor and Description |
|---|
StaxUtilImpl()
The constructor.
|
| Modifier and Type | Method and Description |
|---|---|
XMLEventReader |
createXmlEventReader(InputStream inputStream)
This method creates an
XMLEventReader. |
XMLStreamReader |
createXmlStreamReader(DataResource resource,
boolean xIncludeAware)
This method creates an
XMLStreamReader. |
XMLStreamReader |
createXmlStreamReader(InputStream inputStream)
This method creates an
XMLStreamReader. |
XMLStreamWriter |
createXmlStreamWriter(OutputStream out)
This method creates a
XMLStreamWriter. |
XMLStreamWriter |
createXmlStreamWriter(Writer writer)
This method creates a
XMLStreamWriter. |
protected void |
doInitialize()
This method performs the actual
initialization. |
String |
getEventTypeName(int eventType)
This method gets the name for the given
eventType. |
static StaxUtil |
getInstance()
This method gets the singleton instance of this
StaxUtilImpl. |
protected StringValueConverter |
getValueConverter() |
XMLInputFactory |
getXmlInputFactory()
This method gets the
XMLInputFactory to use. |
protected XMLOutputFactory |
getXmlOutputFactory()
This method gets the
XMLOutputFactory to use. |
XMLEvent |
nextElement(XMLEventReader xmlReader)
|
<V> V |
parseAttribute(XMLStreamReader xmlReader,
String namespaceUri,
String localAttributeName,
Class<V> type)
This method parses the attribute with the given
localAttributeName from the given
xmlReader as given by type. |
<V> V |
parseAttribute(XMLStreamReader xmlReader,
String namespaceUri,
String localAttributeName,
Class<V> type,
V defaultValue)
This method parses the attribute with the given
localAttributeName from the given
xmlReader as given by type. |
String |
readText(XMLStreamReader xmlReader)
This method reads the
text at the current position of the given
xmlReader . |
void |
setValueConverter(StringValueConverter valueConverter) |
void |
setXmlInputFactory(XMLInputFactory xmlInputFactory) |
void |
setXmlOutputFactory(XMLOutputFactory xmlOutputFactory)
This method sets the
XML-output-factory. |
void |
skipOpenElement(XMLEventReader xmlReader)
This method skips all events until the current element (tag) is closed.
|
void |
skipOpenElement(XMLStreamReader xmlReader)
This method skips all events until the current element (tag) is closed.
|
createLogger, getLoggerdoInitialized, getInitializationState, initializeprivate static StaxUtil instance
private XMLInputFactory xmlInputFactory
private XMLOutputFactory xmlOutputFactory
private StringValueConverter valueConverter
public static StaxUtil getInstance()
StaxUtilImpl. Cdi.GET_INSTANCE before using.protected StringValueConverter getValueConverter()
@Inject public void setValueConverter(StringValueConverter valueConverter)
valueConverter - the valueConverter to setprotected XMLOutputFactory getXmlOutputFactory()
XMLOutputFactory to use.public void setXmlOutputFactory(XMLOutputFactory xmlOutputFactory)
XML-output-factory.xmlOutputFactory - is the xmlOutputFactory to set.public XMLInputFactory getXmlInputFactory()
XMLInputFactory to use.public void setXmlInputFactory(XMLInputFactory xmlInputFactory)
xmlInputFactory - is the xmlInputFactory to setprotected void doInitialize()
AbstractComponentinitialization. It is called when AbstractComponent.initialize() is
invoked for the first time. super.AbstractComponent.doInitialize().doInitialize in class AbstractLoggableComponentpublic XMLEventReader createXmlEventReader(InputStream inputStream)
StaxUtilXMLEventReader.createXmlEventReader in interface StaxUtilinputStream - is the InputStream to read from.XMLEventReader.XMLInputFactory.createXMLEventReader(InputStream)public XMLStreamReader createXmlStreamReader(InputStream inputStream)
StaxUtilXMLStreamReader.createXmlStreamReader in interface StaxUtilinputStream - is the InputStream to read from.XMLStreamReader.XMLInputFactory.createXMLStreamReader(InputStream)public XMLStreamReader createXmlStreamReader(DataResource resource, boolean xIncludeAware) throws XmlException
StaxUtilXMLStreamReader.createXmlStreamReader in interface StaxUtilresource - is the DataResource to read from.xIncludeAware - - true if XInclude should be
supported, false otherwise.XMLStreamReader.XmlException - if the creation of the stream-reader failed (StAX not available or misconfigured).XMLInputFactory.createXMLStreamReader(InputStream)public XMLStreamWriter createXmlStreamWriter(OutputStream out)
StaxUtilXMLStreamWriter.createXmlStreamWriter in interface StaxUtilout - is the output stream where the XML will be written to.XMLOutputFactory.createXMLStreamWriter(OutputStream)public XMLStreamWriter createXmlStreamWriter(Writer writer)
StaxUtilXMLStreamWriter.createXmlStreamWriter in interface StaxUtilwriter - is the writer where the XML will be written to.XMLOutputFactory.createXMLStreamWriter(Writer)public <V> V parseAttribute(XMLStreamReader xmlReader, String namespaceUri, String localAttributeName, Class<V> type) throws ValueException
StaxUtillocalAttributeName from the given
xmlReader as given by type.parseAttribute in interface StaxUtilV - is the generic for the type.xmlReader - is where to read the XML from.namespaceUri - is the URI representing the namespace of the requested attribute or null to
ignore the namespace.localAttributeName - is the local name of the requested attribute.type - is the type the requested attribute should be converted to.type.ValueException - if the attribute is NOT defined or its value can NOT be converted to type.public <V> V parseAttribute(XMLStreamReader xmlReader, String namespaceUri, String localAttributeName, Class<V> type, V defaultValue) throws ValueException
StaxUtillocalAttributeName from the given
xmlReader as given by type.parseAttribute in interface StaxUtilV - is the generic for the type.xmlReader - is where to read the XML from.namespaceUri - is the URI representing the namespace of the requested attribute or null to
ignore the namespace.localAttributeName - is the local name of the requested attribute.type - is the type the requested attribute should be converted to.defaultValue - is the default value returned if the requested attribute is NOT defined. It may be
null .type.ValueException - if the attribute value can NOT be converted to type.public String readText(XMLStreamReader xmlReader)
StaxUtiltext at the current position of the given
xmlReader . xmlReader is pointing to
XMLStreamConstants.START_ELEMENT or
XMLStreamConstants.ATTRIBUTE all
attributes are skipped before.
For XMLEventReader use XMLEventReader.getElementText().readText in interface StaxUtilxmlReader - is the XMLStreamReader to read the XML from.text at the current position or null if there is no
text to read (e.g. XMLStreamConstants.END_ELEMENT was hit).public void skipOpenElement(XMLStreamReader xmlReader)
StaxUtil... while (xmlReader.nextTag() ==XMLStreamConstants.START_ELEMENT) { String tagname = xmlReader.getLocalName(); if (XML_TAG_FOO.equals(tagname)) { handleFoo(xmlReader); } else { // ignore all other tags staxUtil.skipOpenElement(xmlReader); } }
skipOpenElement in interface StaxUtilxmlReader - is the STaX reader currently pointing at or inside the element to skip. After the call
of this method it will point to the end-element event of the element to skip. Calling
XMLStreamReader.nextTag() will then point to start-element of the next sibling or to
end-element of the parent.public void skipOpenElement(XMLEventReader xmlReader)
StaxUtilskipOpenElement in interface StaxUtilxmlReader - is the STaX reader currently pointing at or inside the element to skip. After the call
of this method it will point to the end-element event of the element to skip. Calling
XMLEventReader.nextEvent() will then return the event after the
EndElement-Event of the skipped element.StaxUtil.skipOpenElement(XMLStreamReader)public XMLEvent nextElement(XMLEventReader xmlReader)
StaxUtilStartElement,
EndElement or EndDocument is
encountered. Unlike XMLEventReader.nextTag() no exception is
thrown according to unexpected events except if has no
next event.nextElement in interface StaxUtilxmlReader - is the XMLEventReader to read the XML from.public String getEventTypeName(int eventType)
StaxUtileventType.getEventTypeName in interface StaxUtileventType - is an event type constant declared in XMLStreamConstants.XMLStreamConstantsCopyright © 2001–2016 mmm-Team. All rights reserved.