Package com.ctc.wstx.evt
Class WstxEventReader
- java.lang.Object
-
- com.ctc.wstx.evt.WstxEventReader
-
- All Implemented Interfaces:
Iterator<Object>,XMLEventReader,XMLStreamConstants,org.codehaus.stax2.XMLEventReader2
public class WstxEventReader extends Object implements org.codehaus.stax2.XMLEventReader2, XMLStreamConstants
Woodstox version ofXMLEventReader2(andXMLEventReader).NOTE: up to Woodstox 5.1, this was based on Stax2 Reference Implementation (
Stax2EventReaderImpl), but due to various issues has temporarily (?) been cut-paste-modified here. Ideally it would be reconciled once Stax2-api version 4.2 can be relied as baseline, but that may take time.
-
-
Field Summary
Fields Modifier and Type Field Description protected static intERR_GETELEMTEXT_NON_TEXT_EVENTEncountered non-textual event (other than closing END_ELEMENT) when collecting text for getElementText()protected static intERR_GETELEMTEXT_NOT_START_ELEMCurrent state when getElementText() called not START_ELEMENTprotected static intERR_NEXTTAG_NON_WS_TEXTEncountered CHARACTERS or CDATA that contains non-white space char(s), when trying to locate tag with nextTag()protected static intERR_NEXTTAG_WRONG_TYPEEncountered non-skippable non-text/element event with nextTag()protected XMLEventAllocatormAllocatorprotected booleanmCfgMultiDocModeMarker flag to allow specialized handling in "multi-document" reading mode.protected XMLEventmPeekedEventEvent that has been peeked, ie.protected intmPrePeekEventThis variable keeps track of the type of the 'previous' event when peeking for the next Event.protected org.codehaus.stax2.XMLStreamReader2mReaderprotected intmStateHigh-level state indicator, with currently three values: whether we are initializing (need to synthetize START_DOCUMENT), at END_OF_INPUT (end-of-doc), or otherwise, normal operation.protected static intSTATE_CONTENTprotected static intSTATE_END_OF_INPUTprotected static intSTATE_INITIAL-
Fields inherited from interface javax.xml.stream.XMLStreamConstants
ATTRIBUTE, CDATA, CHARACTERS, COMMENT, DTD, END_DOCUMENT, END_ELEMENT, ENTITY_DECLARATION, ENTITY_REFERENCE, NAMESPACE, NOTATION_DECLARATION, PROCESSING_INSTRUCTION, SPACE, START_DOCUMENT, START_ELEMENT
-
-
Constructor Summary
Constructors Constructor Description WstxEventReader(XMLEventAllocator a, org.codehaus.stax2.XMLStreamReader2 r)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected XMLStreamException_checkUnwrap(RuntimeException rex)voidclose()protected XMLEventcreateNextEvent(boolean checkEOD, int type)protected XMLEventcreateStartDocumentEvent()Method called to create the very first event (START_DOCUMENT).protected StringfindErrorDesc(int errorType, int currEvent)Method used to locate error message description to use.StringgetElementText()protected StringgetErrorDesc(int errorType, int currEvent)Method called upon encountering a problem that should result in an exception being thrown.ObjectgetProperty(String name)protected XMLStreamReadergetStreamReader()booleanhasNext()booleanhasNextEvent()Note: although the interface allows implementations to throw anXMLStreamException, the reference implementation doesn't currently need to.booleanisPropertySupported(String name)Objectnext()XMLEventnextEvent()XMLEventnextTag()XMLEventpeek()voidremove()Note: only here because we implement Iterator interface.protected voidreportProblem(String msg)protected voidreportProblem(String msg, Location loc)booleansetProperty(String name, Object value)protected voidthrowEndOfInput()protected voidthrowUnchecked(XMLStreamException sex)protected voidupdateStateEndDocument()Method called when we are about to returnEND_DOCUMENTevent.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface java.util.Iterator
forEachRemaining
-
-
-
-
Field Detail
-
STATE_INITIAL
protected static final int STATE_INITIAL
- See Also:
- Constant Field Values
-
STATE_END_OF_INPUT
protected static final int STATE_END_OF_INPUT
- See Also:
- Constant Field Values
-
STATE_CONTENT
protected static final int STATE_CONTENT
- See Also:
- Constant Field Values
-
ERR_GETELEMTEXT_NOT_START_ELEM
protected static final int ERR_GETELEMTEXT_NOT_START_ELEM
Current state when getElementText() called not START_ELEMENT- See Also:
- Constant Field Values
-
ERR_GETELEMTEXT_NON_TEXT_EVENT
protected static final int ERR_GETELEMTEXT_NON_TEXT_EVENT
Encountered non-textual event (other than closing END_ELEMENT) when collecting text for getElementText()- See Also:
- Constant Field Values
-
ERR_NEXTTAG_NON_WS_TEXT
protected static final int ERR_NEXTTAG_NON_WS_TEXT
Encountered CHARACTERS or CDATA that contains non-white space char(s), when trying to locate tag with nextTag()- See Also:
- Constant Field Values
-
ERR_NEXTTAG_WRONG_TYPE
protected static final int ERR_NEXTTAG_WRONG_TYPE
Encountered non-skippable non-text/element event with nextTag()- See Also:
- Constant Field Values
-
mAllocator
protected final XMLEventAllocator mAllocator
-
mReader
protected final org.codehaus.stax2.XMLStreamReader2 mReader
-
mPeekedEvent
protected XMLEvent mPeekedEvent
Event that has been peeked, ie. loaded without call tonextEvent(); will be returned and cleared by call tonextEvent()(or, returned again if peeked again)
-
mState
protected int mState
High-level state indicator, with currently three values: whether we are initializing (need to synthetize START_DOCUMENT), at END_OF_INPUT (end-of-doc), or otherwise, normal operation. Useful in simplifying some methods, as well as to make sure that independent of how stream reader handles things, event reader can reliably detect End-Of-Document.
-
mPrePeekEvent
protected int mPrePeekEvent
This variable keeps track of the type of the 'previous' event when peeking for the next Event. It is needed for some functionality, to remember state even when underlying parser has to move to peek the next event.
-
mCfgMultiDocMode
protected final boolean mCfgMultiDocMode
Marker flag to allow specialized handling in "multi-document" reading mode.
-
-
Constructor Detail
-
WstxEventReader
public WstxEventReader(XMLEventAllocator a, org.codehaus.stax2.XMLStreamReader2 r)
-
-
Method Detail
-
isPropertySupported
public boolean isPropertySupported(String name)
- Specified by:
isPropertySupportedin interfaceorg.codehaus.stax2.XMLEventReader2
-
setProperty
public boolean setProperty(String name, Object value)
- Specified by:
setPropertyin interfaceorg.codehaus.stax2.XMLEventReader2
-
getErrorDesc
protected String getErrorDesc(int errorType, int currEvent)
Method called upon encountering a problem that should result in an exception being thrown. If non-null String is returned. that will be used as the message of exception thrown; if null, a standard message will be used instead.- Parameters:
errorType- Type of the problem, one ofERR_constantseventType- Type of the event that triggered the problem, if any; -1 if not available.
-
close
public void close() throws XMLStreamException- Specified by:
closein interfaceXMLEventReader- Throws:
XMLStreamException
-
getElementText
public String getElementText() throws XMLStreamException
- Specified by:
getElementTextin interfaceXMLEventReader- Throws:
XMLStreamException
-
getProperty
public Object getProperty(String name)
- Specified by:
getPropertyin interfaceXMLEventReader
-
hasNext
public boolean hasNext()
- Specified by:
hasNextin interfaceIterator<Object>- Specified by:
hasNextin interfaceXMLEventReader
-
nextEvent
public XMLEvent nextEvent() throws XMLStreamException
- Specified by:
nextEventin interfaceXMLEventReader- Throws:
XMLStreamException
-
nextTag
public XMLEvent nextTag() throws XMLStreamException
- Specified by:
nextTagin interfaceXMLEventReader- Throws:
XMLStreamException
-
peek
public XMLEvent peek() throws XMLStreamException
- Specified by:
peekin interfaceXMLEventReader- Throws:
XMLStreamException
-
remove
public void remove()
Note: only here because we implement Iterator interface. Will not work, don't bother calling it.
-
updateStateEndDocument
protected void updateStateEndDocument() throws XMLStreamExceptionMethod called when we are about to returnEND_DOCUMENTevent. Usually this should change state toSTATE_END_OF_INPUT, but may vary for some alternative read modes (like multi-document)- Throws:
XMLStreamException- Since:
- 4.2
-
hasNextEvent
public boolean hasNextEvent() throws XMLStreamExceptionNote: although the interface allows implementations to throw an
XMLStreamException, the reference implementation doesn't currently need to. It's still declared, in case in future there is need to throw such an exception.- Specified by:
hasNextEventin interfaceorg.codehaus.stax2.XMLEventReader2- Throws:
XMLStreamException
-
createNextEvent
protected XMLEvent createNextEvent(boolean checkEOD, int type) throws XMLStreamException
- Throws:
XMLStreamException
-
_checkUnwrap
protected XMLStreamException _checkUnwrap(RuntimeException rex)
-
createStartDocumentEvent
protected XMLEvent createStartDocumentEvent() throws XMLStreamException
Method called to create the very first event (START_DOCUMENT).- Throws:
XMLStreamException
-
throwEndOfInput
protected void throwEndOfInput()
-
throwUnchecked
protected void throwUnchecked(XMLStreamException sex)
-
reportProblem
protected void reportProblem(String msg) throws XMLStreamException
- Throws:
XMLStreamException
-
reportProblem
protected void reportProblem(String msg, Location loc) throws XMLStreamException
- Throws:
XMLStreamException
-
getStreamReader
protected XMLStreamReader getStreamReader()
-
findErrorDesc
protected final String findErrorDesc(int errorType, int currEvent)
Method used to locate error message description to use. Calls sub-classesgetErrorDesc()first, and only if no message found, uses default messages defined here.
-
-