public class XIncludeStreamReader extends StreamReaderProxy
XMLStreamReader interface that adapts an XMLStreamReader adding
support for XInclude. | Modifier and Type | Field and Description |
|---|---|
private int |
depth
The current depth in the XML tree relative to the first "include" tag of the XInclude namespace that is currently
active.
|
private XMLInputFactory |
factory
The factory used to create additional readers.
|
private boolean |
fallback
This flag indicates whether we are actively inside a fallback section.
|
private XMLStreamReader |
includeReader
The reader to the current XInclude document or
null if we currently have no active XInclude. |
private String |
includeText
The included text or
null if currently no text is to be included. |
private InputStream |
inputStream
The StAX resource management sucks: we need to manage the underlying input stream ourselves.
|
private static org.slf4j.Logger |
LOGGER
The
Logger to use. |
private XMLStreamReader |
mainReader
The reader to the main document.
|
private XIncludeStreamReader |
parent
the parent reader or
null if this is the root. |
private DataResource |
resource
The resource pointing to the main document.
|
ATTRIBUTE, CDATA, CHARACTERS, COMMENT, DTD, END_DOCUMENT, END_ELEMENT, ENTITY_DECLARATION, ENTITY_REFERENCE, NAMESPACE, NOTATION_DECLARATION, PROCESSING_INSTRUCTION, SPACE, START_DOCUMENT, START_ELEMENT| Modifier | Constructor and Description |
|---|---|
|
XIncludeStreamReader(XMLInputFactory factory,
DataResource resource)
The constructor.
|
protected |
XIncludeStreamReader(XMLInputFactory factory,
DataResource resource,
XIncludeStreamReader parent)
The constructor.
|
| Modifier and Type | Method and Description |
|---|---|
void |
close()
ATTENTION:
This method violates the StAX API and closes the underlying input stream! The StAX API has a bad design mistake about the close() method NOT to close the underlying input stream. |
protected void |
closeInitialInclude()
This method ascends the XML until the initial include is closed.
|
protected void |
detectRecursiveInclusion(DataResource dataResource)
This method detects if a recursive inclusion takes place.
|
String |
getText() |
char[] |
getTextCharacters() |
int |
getTextLength() |
int |
getTextStart() |
int |
next() |
protected int |
resolveInclude()
This method is called when an include tag of the XInclude namespace was started.
|
nextTaggetAttributeCount, getAttributeLocalName, getAttributeName, getAttributeNamespace, getAttributePrefix, getAttributeType, getAttributeValue, getAttributeValue, getCharacterEncodingScheme, getElementText, getEncoding, getEventType, getLocalName, getLocation, getName, getNamespaceContext, getNamespaceCount, getNamespacePrefix, getNamespaceURI, getNamespaceURI, getNamespaceURI, getParent, getPIData, getPITarget, getPrefix, getProperty, getTextCharacters, getVersion, hasName, hasNext, hasText, isAttributeSpecified, isCharacters, isEndElement, isStandalone, isStartElement, isWhiteSpace, require, setParent, standaloneSetprivate static final org.slf4j.Logger LOGGER
Logger to use.private final XIncludeStreamReader parent
null if this is the root.private final XMLInputFactory factory
private final XMLStreamReader mainReader
private final DataResource resource
private final InputStream inputStream
private XMLStreamReader includeReader
null if we currently have no active XInclude.private String includeText
null if currently no text is to be included.private int depth
0 if we are outside of an XInclude.private boolean fallback
public XIncludeStreamReader(XMLInputFactory factory, DataResource resource)
factory - is the XMLInputFactory required to create new XMLStreamReader instances for
includes.resource - is the DataResource pointing to the XML content.protected XIncludeStreamReader(XMLInputFactory factory, DataResource resource, XIncludeStreamReader parent) throws XmlException, RuntimeIoException
factory - is the input factory used to create raw XML-readers.resource - is where to read the XML from.parent - is the parent XMLStreamReader.XmlException - in case of an XML error.RuntimeIoException - is case of an input/output error.protected void detectRecursiveInclusion(DataResource dataResource) throws XMLStreamException
dataResource - is the current data-resource to include.XMLStreamException - if the given dataResource has already been included causing an infinity loop.public void close()
throws XMLStreamException
close() method NOT to close the underlying input stream.
Besides the XMLStreamReader the user also has to manage the input stream what will lead in additional
programming mistakes ending up with open file-handles. Since many XMLStreamReader implementations have an
empty body for this method developers, may tend to take it NOT as serious as e.g. InputStream.close().
Since this implementation has to open new streams behind the scenes the only senseful implementation of this method
is to close the underlying stream (and recursively closing all included streams). You have to ensure this reader is
safely closed via this method so remaining open streams are closed.close in interface XMLStreamReaderclose in class StreamReaderDelegateXMLStreamExceptionprotected int resolveInclude()
throws XMLStreamException
XMLStreamException - if the XML stream processing caused an error.protected void closeInitialInclude()
throws XMLStreamException
XMLStreamException - if the XML stream processing caused an error.public int next()
throws XMLStreamException
next in interface XMLStreamReadernext in class StreamReaderDelegateXMLStreamExceptionpublic String getText()
getText in interface XMLStreamReadergetText in class StreamReaderDelegatepublic char[] getTextCharacters()
getTextCharacters in interface XMLStreamReadergetTextCharacters in class StreamReaderDelegatepublic int getTextLength()
getTextLength in interface XMLStreamReadergetTextLength in class StreamReaderDelegatepublic int getTextStart()
getTextStart in interface XMLStreamReadergetTextStart in class StreamReaderDelegateCopyright © 2001–2016 mmm-Team. All rights reserved.