public abstract class SMInputCursor extends Object
Implementation Note: as cursors are thin wrappers around
XMLStreamReader2
,
and since not all Stax implementations implement
XMLStreamReader2
, some wrapping may be needed to expose
basic Stax 1.0 XMLStreamReader
s as Stax2
XMLStreamReader2
readers.
But without native support, not all stax2 features may be available
for such stream readers.
This should usuall not be a problem with cursor functionality,
as cursors will try to limit their usage to known working subset,
but care must be taken if application code wants to directly
access underlying stream reader.
Modifier and Type | Class and Description |
---|---|
static class |
CursorBase.State
State constants are used for keeping track of state of individual
cursors.
|
static class |
SMInputCursor.Tracking
Different tracking behaviors available for cursors.
|
Modifier and Type | Field and Description |
---|---|
protected int |
_baseDepth
Depth the underlying stream reader had when this cursor was
created (which is the number of currently open parent elements).
|
protected SMInputCursor |
_childCursor
Cursor that has been opened for iterating child nodes of the
start element node this cursor points to.
|
protected SMInputContext |
_context |
protected SMEvent |
_currEvent
Event that this cursor currently points to, if valid, or
it last pointed to if not (including null if cursor has not
yet been advanced).
|
protected int |
_elemCount
Number of start elements iterated over by this cursor, including the
current one.
|
protected int |
_nodeCount
Number of nodes iterated over by this cursor, including the
current one.
|
protected SMElementInfo |
_parentTrackedElement
Element that the parent of this cursor tracked (if any),
when this cursor was created.
|
protected CursorBase.State |
_state
Current state of the cursor.
|
protected org.codehaus.stax2.XMLStreamReader2 |
_streamReader
Underlying stream reader used.
|
protected SMElementInfo |
_trackedElement
Element that was last "tracked"; element over which cursor was
moved, and of which state has been saved for further use.
|
protected Object |
mData
Non-typesafe payload data that applications can use, to pass
an extra argument along with cursors.
|
protected ElementInfoFactory |
mElemInfoFactory
Optional factory instance that is used to create element info
objects if element tracking is enabled.
|
protected SMInputCursor.Tracking |
mElemTracking
Whether element information is to be tracked or not, and if it is,
how much of it will be stored.
|
protected SMFilter |
mFilter
Optional filter object that can be used to filter out events of
types caller is not interested in.
|
Constructor and Description |
---|
SMInputCursor(SMInputContext ctxt,
SMInputCursor parent,
SMFilter filter) |
Modifier and Type | Method and Description |
---|---|
protected org.codehaus.stax2.XMLStreamReader2 |
_getStreamReader()
Internal method (but available to sub-classes) that allows
access to the underlying stream reader.
|
protected void |
_markConsumed()
Method to call to notify that textual contents of this cursor have been
read; typically when a call has been made that will traverse contents
and make stream point to matching
END_ELEMENT . |
protected XMLStreamException |
_notAccessible(String method)
Internal method for throwing a stream exception that indicates
that given method can not be called because the cursor does
not point to event of expected type.
|
protected XMLStreamException |
_wrongState(String method,
SMEvent expState) |
SMInputCursor |
advance()
Method that does what
getNext() does, but instead of
returning resulting event type, returns this cursor. |
XMLEvent |
asEvent()
Method for accessing information regarding event this
cursor points to, as an instance of
XMLEvent . |
SMInputCursor |
childCursor()
Method that will create a new nested cursor for iterating
over all (immediate) child nodes of the start element this cursor
currently points to.
|
SMInputCursor |
childCursor(SMFilter f)
Method that will create a new nested cursor for iterating
over all (immediate) child nodes of the start element this cursor
currently points to that are passed by the specified filter.
|
SMInputCursor |
childElementCursor()
Convenience method; equivalent to
childCursor(SMFilterFactory.getElementOnlyFilter()); |
SMInputCursor |
childElementCursor(QName elemName)
Convenience method; equivalent to
childCursor(SMFilterFactory.getElementOnlyFilter(elemName));
Will only return START_ELEMENT and END_ELEMENT events, whose element
name matches given qname. |
SMInputCursor |
childElementCursor(String elemLocalName)
Convenience method; equivalent to
childCursor(SMFilterFactory.getElementOnlyFilter(elemName));
Will only return START_ELEMENT and END_ELEMENT events, whose element's
local name matches given local name, and that does not belong to
a namespace. |
SMInputCursor |
childMixedCursor()
Convenience method; equivalent to
childCursor(SMFilterFactory.getMixedFilter()); |
String |
collectDescendantText()
Same as calling
collectDescendantText(boolean) with 'false':
that is, do not include ignorable white space (as determined by DTD
or Schema) in the result text. |
String |
collectDescendantText(boolean includeIgnorable)
Method that can collect all text contained within START_ELEMENT
currently pointed by this cursor.
|
protected abstract SMInputCursor |
constructChildCursor(SMFilter f)
Abstract method that concrete sub-classes implement, and is used
for all instantiation of child cursors by this cursor instance.
|
protected abstract SMInputCursor |
constructDescendantCursor(SMFilter f)
Abstract method that concrete sub-classes implement, and is used
for all instantiation of descendant cursors by this cursor instance.
|
protected SMElementInfo |
constructElementInfo(SMElementInfo parent,
SMElementInfo prevSibling)
Method cursor calls when it needs to track element state information;
if so, it calls this method to take a snapshot of the element.
|
XMLStreamException |
constructStreamException(String msg)
Method for constructing stream exception with given message,
and location that matches that of the underlying stream
regardless of whether this cursor is valid (that is,
will indicate location of the stream which may differ from
where this cursor was last valid)
|
protected String |
currentEventStr()
Method for constructing human-readable description of the event
this cursor points to (if cursor valid) or last pointed to (if
not valid; possibly null if cursor has not yet been advanced).
|
SMInputCursor |
descendantCursor()
Method that will create a new nested cursor for iterating
over all the descendant (children and grandchildren) nodes of
the start element this cursor currently points to.
|
SMInputCursor |
descendantCursor(SMFilter f)
Method that will create a new nested cursor for iterating
over all the descendant (children and grandchildren) nodes of
the start element this cursor currently points to
that are accepted by the specified filter.
|
SMInputCursor |
descendantElementCursor()
Convenience method; equivalent to
descendantCursor(SMFilterFactory.getElementOnlyFilter()); |
SMInputCursor |
descendantElementCursor(QName elemName)
Convenience method; equivalent to
descendantCursor(SMFilterFactory.getElementOnlyFilter(elemName));
Will only return START_ELEMENT and END_ELEMENT events, whose element
name matches given qname. |
SMInputCursor |
descendantElementCursor(String elemLocalName)
Convenience method; equivalent to
descendantCursor(SMFilterFactory.getElementOnlyFilter(elemLocalName)); . |
SMInputCursor |
descendantMixedCursor()
Convenience method; equivalent to
descendantCursor(SMFilterFactory.getMixedFilter()); |
protected static SMEvent |
eventObjectByEventId(int type)
Note: no checks are done regarding validity of passed-in
type.
|
int |
findAttrIndex(String uri,
String localName)
Method that can be called when this cursor points to START_ELEMENT,
and which will return index of specified attribute, if it
exists for this element.
|
byte[] |
getAttrBinaryValue(int index)
Method for accessing value of a base64-encoded attribute, using
default base64 encoding variant (as per
Base64Variants.getDefaultVariant() . |
byte[] |
getAttrBinaryValue(int index,
org.codehaus.stax2.typed.Base64Variant variant)
Method for accessing value of a base64-encoded attribute, using
specified base64 encoding variant.
|
boolean |
getAttrBooleanValue(int index)
Method for accessing value of specified attribute as boolean.
|
boolean |
getAttrBooleanValue(int index,
boolean defValue)
Method for accessing value of specified attribute as boolean.
|
int |
getAttrCount()
Method that can be called when this cursor points to START_ELEMENT,
and which will return number of attributes with values for the
start element.
|
double |
getAttrDoubleValue(int index)
Method for accessing value of specified attribute as double.
|
double |
getAttrDoubleValue(int index,
double defValue)
Method for accessing value of specified attribute as double.
|
<T extends Enum<T>> |
getAttrEnumValue(int index,
Class<T> enumType)
Method for accessing value of specified attribute as an
Enum value of specified type, if content non-empty.
|
int |
getAttrIntValue(int index)
Method for accessing value of specified attribute as integer.
|
int |
getAttrIntValue(int index,
int defValue)
Method for accessing value of specified attribute as integer.
|
int |
getAttrIntValue(String uri,
String localName)
Deprecated.
Use combination of
findAttrIndex(java.lang.String, java.lang.String) and
getAttrIntValue(int) instead. |
int |
getAttrIntValue(String uri,
String localName,
int defValue)
Deprecated.
Use combination of
findAttrIndex(java.lang.String, java.lang.String) and
getAttrIntValue(int,int) instead. |
String |
getAttrLocalName(int index)
Method that can be called when this cursor points to START_ELEMENT,
and returns local name
of the attribute at specified index.
|
long |
getAttrLongValue(int index)
Method for accessing value of specified attribute as long.
|
long |
getAttrLongValue(int index,
long defValue)
Method for accessing value of specified attribute as long.
|
QName |
getAttrName(int index)
Method that can be called when this cursor points to START_ELEMENT,
and returns fully qualified name
of the attribute at specified index.
|
String |
getAttrNsUri(int index)
Method that can be called when this cursor points to START_ELEMENT,
and returns namespace URI
of the attribute at specified index (non-empty String if it has
one, and empty String if attribute does not belong to a namespace)
Index has to be between [0,
getAttrCount() [; otherwise
IllegalArgumentException will be thrown. |
String |
getAttrPrefix(int index)
Method that can be called when this cursor points to START_ELEMENT,
and returns namespace prefix
of the attribute at specified index (if it has any), or
empty String if attribute has no prefix (does not belong to
a namespace).
|
String |
getAttrValue(int index)
Method that can be called when this cursor points to START_ELEMENT,
and returns unmodified textual value
of the attribute at specified index (non-empty String if it has
one, and empty String if attribute does not belong to a namespace)
Index has to be between [0,
getAttrCount() [; otherwise
IllegalArgumentException will be thrown. |
String |
getAttrValue(String localName)
Convenience accessor method to access an attribute that is
not in a namespace (has no prefix).
|
String |
getAttrValue(String namespaceURI,
String localName)
Method that can be called when this cursor points to START_ELEMENT,
and returns unmodified textual value
of the specified attribute (if element has it), or null if
element has no value for such attribute.
|
protected int |
getBaseParentCount()
This method is needed by flattening cursors when they
have child cursors: if so, they can determine their
depth relative to child cursor's base parent count
(and can not check stream -- as it may have moved --
nor want to have separate field to track this information)
|
SMEvent |
getCurrEvent()
Returns the type of event this cursor either currently points to
(if in valid state), or pointed to (if ever iterated forward), or
null if just created.
|
int |
getCurrEventCode()
Convenience method for accessing type of the current event
(as would be returned by
getCurrEvent() ) as
one of event types defined in XMLStreamConstants
(like XMLStreamConstants.START_ELEMENT ). |
protected String |
getCurrEventDesc() |
Location |
getCursorLocation()
Method to access starting Location of event (as defined by Stax
specification)
that this cursor points to.
|
Object |
getData()
Method for accessing application-provided data set previously
by a
setData(java.lang.Object) call. |
byte[] |
getElemBinaryValue()
Method for accessing value current element, which isbase64-encoded
binary data, by decoding contents using the default base64 variant
|
byte[] |
getElemBinaryValue(org.codehaus.stax2.typed.Base64Variant variant)
Method for accessing value current element, which isbase64-encoded
binary data, by decoding contents using specified variant.
|
boolean |
getElemBooleanValue()
Method that can collect text directly contained within
START_ELEMENT currently pointed by this cursor and convert
it to a boolean value.
|
boolean |
getElemBooleanValue(boolean defValue)
Similar to
getElemBooleanValue() , but instead of failing
on invalid value, returns given default value. |
double |
getElemDoubleValue()
Method that can collect text directly contained within
START_ELEMENT currently pointed by this cursor and convert
it to a double value.
|
double |
getElemDoubleValue(double defValue)
Similar to
getElemDoubleValue() , but instead of failing
on invalid value, returns given default value. |
int |
getElementCount()
Method to access number of start elements cursor has traversed
(including ones that were filtered out, if any).
|
ElementInfoFactory |
getElementInfoFactory() |
SMInputCursor.Tracking |
getElementTracking() |
<T extends Enum<T>> |
getElemEnumValue(Class<T> enumType)
Method that can collect text directly contained within
START_ELEMENT currently pointed by this cursor and convert
it to one of enumerated values of given type, if textual
value non-type, and otherwise to null.
|
int |
getElemIntValue()
Method that can collect text directly contained within
START_ELEMENT currently pointed by this cursor and convert
it to a int value.
|
int |
getElemIntValue(int defValue)
Similar to
getElemIntValue() , but instead of failing
on invalid value, returns given default value. |
long |
getElemLongValue()
Method that can collect text directly contained within
START_ELEMENT currently pointed by this cursor and convert
it to a long value.
|
long |
getElemLongValue(long defValue)
Similar to
getElemLongValue() , but instead of failing
on invalid value, returns given default value. |
String |
getElemStringValue()
Method that can collect text directly contained within
START_ELEMENT currently pointed by this cursor.
|
String |
getLocalName()
For events with fully qualified names (START_ELEMENT, END_ELEMENT,
ATTRIBUTE, NAMESPACE) returns the local component of the full
name; for events with only non-qualified name (PROCESSING_INSTRUCTION,
entity and notation declarations, references) returns the name, and
for other events, returns null.
|
Location |
getLocation()
Deprecated.
|
abstract SMEvent |
getNext()
Main iterating method.
|
int |
getNodeCount()
Method to access number of nodes cursor has traversed
(including ones that were filtered out, if any).
|
String |
getNsUri()
Method for accessing namespace URI of the START_ELEMENT this
cursor points to.
|
abstract int |
getParentCount()
Number of parent elements that the token/event cursor points to has,
if it points to one.
|
SMElementInfo |
getParentTrackedElement() |
String |
getPathDesc()
Method that generates developer-readable description of
the logical path of the event this cursor points to,
assuming that element tracking is enabled.
|
String |
getPrefix()
Method for accessing namespace prefix of the START_ELEMENT this
cursor points to.
|
String |
getPrefixedName()
Returns a String representation of either the fully-qualified name
(if the event has full name) or the local name (if event does not
have full name but has local name); or if no name available, throws
stream exception.
|
QName |
getQName() |
protected String |
getStateDesc() |
Location |
getStreamLocation()
Method to access Location that the underlying stream reader points
to.
|
org.codehaus.stax2.XMLStreamReader2 |
getStreamReader()
Method that can be used to get direct access to the underlying
stream reader.
|
String |
getText()
Method that can be used when this cursor points to a textual
event; something for which
XMLStreamReader.getText() can
be called. |
SMElementInfo |
getTrackedElement() |
boolean |
hasLocalName(String expName)
Method for verifying whether current named event (one for which
getLocalName() can be called)
has the specified local name or not. |
boolean |
hasName(QName qname)
Equivalent to calling
hasName(String, String) with
namespace URI and local name contained in the argument QName |
boolean |
hasName(String expNsURI,
String expLN)
Method for verifying whether current named event (one for which
getLocalName() can be called) has the specified
fully-qualified name or not. |
protected void |
invalidate()
Method called by the parent cursor, to indicate it has to
traverse over xml content and that child cursor as well
as all of its descendant cursors (if any) are to be
considered invalid.
|
boolean |
isRootCursor()
Method for determining whether this cursor iterates over root level of
the underlying stream reader
|
void |
processDescendantText(Writer w,
boolean includeIgnorable)
Method similar to
collectDescendantText(boolean) , but will write
the text to specified Writer instead of collecting it into a
String. |
boolean |
readerAccessible()
Method that can be used to check whether this cursor is
currently valid; that is, it is the cursor that points
to the event underlying stream is at.
|
protected void |
rewindPastChild()
Method called to skim through the content that the child
cursor(s) are pointing to, end return once next call to
XMLStreamReader2.next() will return the next event
this cursor should see.
|
void |
setData(Object o)
Method for assigning per-cursor application-managed data,
readable using
getData() . |
void |
setElementInfoFactory(ElementInfoFactory f)
Set element info factory used for constructing
SMElementInfo instances during traversal for this
cursor, as well as all of its children. |
void |
setElementTracking(SMInputCursor.Tracking tracking)
Changes tracking mode of this cursor to the new specified
mode.
|
void |
setFilter(SMFilter f)
Method for setting filter used for selecting which events
are to be returned to the caller when
getNext()
is called. |
void |
throwStreamException(String msg)
Method for constructing and throwing stream exception with given
message.
|
String |
toString()
Overridden implementation will just display description of
the event this cursor points to (or last pointed to, if not
valid)
|
protected SMFilter mFilter
protected SMInputCursor.Tracking mElemTracking
SMInputCursor.Tracking
for details.protected ElementInfoFactory mElemInfoFactory
Note that by default, this factory will be passed down to child and descendant cursors this cursor creates, so usually one only needs to set the factory of the root cursor.
protected Object mData
protected final SMInputContext _context
protected final org.codehaus.stax2.XMLStreamReader2 _streamReader
XMLStreamReader2
instance, or a regular (Stax 1.0)
XMLStreamReader
wrapped in an
adapter.protected final int _baseDepth
protected CursorBase.State _state
protected SMEvent _currEvent
protected int _nodeCount
protected int _elemCount
protected SMElementInfo _trackedElement
protected SMElementInfo _parentTrackedElement
protected SMInputCursor _childCursor
public SMInputCursor(SMInputContext ctxt, SMInputCursor parent, SMFilter filter)
public final void setFilter(SMFilter f)
getNext()
is called.public final void setElementTracking(SMInputCursor.Tracking tracking)
SMInputCursor.Tracking.NONE
for root cursors with no parent.
See also getPathDesc()
for information on how
to display tracked path/element information.
public final SMInputCursor.Tracking getElementTracking()
public final void setElementInfoFactory(ElementInfoFactory f)
SMElementInfo
instances during traversal for this
cursor, as well as all of its children.public final ElementInfoFactory getElementInfoFactory()
public int getNodeCount()
XMLStreamReader.next()
method
is called, but not counting child cursors' node counts.
Whether END_ELEMENTs (end tags) are included depends on type
of cursor: for nested (which do not return events for end tags)
they are not counted, but for flattened one (that do return)
they are counted as nodes.public int getElementCount()
XMLStreamReader.next()
method
is called and has moved over a start element, but not counting
child cursors' element counts.public abstract int getParentCount()
For example, here are expected return values for an example XML document:
<!-- Comment outside tree --> [0] <root> [0] Text [1] <branch> [1] Inner text [2] <child /> [2]/[2] </branch> [1] </root> [0]Numbers in bracket are depths that would be returned when the cursor points to the node.
Note: depths are different from what many other xml processing APIs (such as Stax and XmlPull)return.
public SMEvent getCurrEvent()
public int getCurrEventCode()
getCurrEvent()
) as
one of event types defined in XMLStreamConstants
(like XMLStreamConstants.START_ELEMENT
).public final boolean isRootCursor()
public SMElementInfo getTrackedElement()
public SMElementInfo getParentTrackedElement()
public final boolean readerAccessible()
public final org.codehaus.stax2.XMLStreamReader2 getStreamReader()
Note that this method should not be needed (or extensively used) for regular StaxMate usage, because direct access to the stream may cause cursor's understanding of stream reader state to be incompatible with its actual state.
public Location getCursorLocation() throws XMLStreamException
readerAccessible()
); if not,
an exception is thrownXMLStreamException
public Location getStreamLocation()
@Deprecated public Location getLocation() throws XMLStreamException
getCursorLocation()
XMLStreamException
public String getText() throws XMLStreamException
XMLStreamReader.getText()
can
be called. Note that it does not advance the cursor, or combine
multiple textual events.XMLStreamException
- if either the underlying parser has
problems (possibly including event type not being of textual
type, see Stax 1.0 specs for details); or if this cursor does
not currently point to an event.public String collectDescendantText(boolean includeIgnorable) throws XMLStreamException
includeIgnorable
- Whether text for events of type SPACE should
be ignored in the results or not. If false, SPACE events will be
skipped; if true, white space will be included in results.XMLStreamException
public final String collectDescendantText() throws XMLStreamException
collectDescendantText(boolean)
with 'false':
that is, do not include ignorable white space (as determined by DTD
or Schema) in the result text.
Note: it is not common to have have ignorable white space; it usually results from indentation, but its detection requires DTD/schema-aware processing
XMLStreamException
public void processDescendantText(Writer w, boolean includeIgnorable) throws IOException, XMLStreamException
collectDescendantText(boolean)
, but will write
the text to specified Writer instead of collecting it into a
String.w
- Writer to use for outputting text foundincludeIgnorable
- Whether text for events of type SPACE should
be ignored in the results or not. If false, SPACE events will be
skipped; if true, white space will be included in results.IOException
XMLStreamException
public QName getQName() throws XMLStreamException
XMLStreamException
public String getLocalName() throws XMLStreamException
XMLStreamException
public String getPrefix() throws XMLStreamException
XMLStreamException
- if cursor does not point to START_ELEMENTpublic String getNsUri() throws XMLStreamException
XMLStreamException
- if cursor does not point to START_ELEMENTpublic String getPrefixedName() throws XMLStreamException
XMLStreamException
public boolean hasLocalName(String expName) throws XMLStreamException
getLocalName()
can be called)
has the specified local name or not.XMLStreamException
public boolean hasName(String expNsURI, String expLN) throws XMLStreamException
getLocalName()
can be called) has the specified
fully-qualified name or not.
Both namespace URI and local name must match for the result
to be true.XMLStreamException
public boolean hasName(QName qname) throws XMLStreamException
hasName(String, String)
with
namespace URI and local name contained in the argument QNameqname
- Name to compare name of current event (if any)
against.XMLStreamException
public XMLEvent asEvent() throws XMLStreamException
XMLEvent
.
Depending on underlying input source this may be constructed
from scratch (for example, if the input cursor was not
constructed from
XMLEventReader
), or accessed
from the underlying event reader.
Calling this method does not advance the underlying stream or cursor itself.
Note, too, that it is ok to call this method at any time: if the cursor is not in valid state for accessing information null will be returned.
XMLStreamException
public int getAttrCount() throws XMLStreamException
XMLStreamException
- if either the underlying parser has
problems (cursor not valid or not pointing to START_ELEMENT)public int findAttrIndex(String uri, String localName) throws XMLStreamException
XMLStreamException
- if either the underlying parser has
problems (cursor not valid or not pointing to START_ELEMENT)public QName getAttrName(int index) throws XMLStreamException
getAttrCount()
[; otherwise
IllegalArgumentException
will be thrown.index
- Index of the attributeXMLStreamException
- if either the underlying parser has
problems (cursor not valid or not pointing to START_ELEMENT),
or if invalid attributeIllegalArgumentException
- if attribute index is invalid
(less than 0 or greater than the last valid index
[getAttributeCount()-1])public String getAttrLocalName(int index) throws XMLStreamException
getAttrCount()
[; otherwise
IllegalArgumentException
will be thrown.index
- Index of the attributeXMLStreamException
- if either the underlying parser has
problems (cursor not valid or not pointing to START_ELEMENT),
or if invalid attributeIllegalArgumentException
- if attribute index is invalid
(less than 0 or greater than the last valid index
[getAttributeCount()-1])public String getAttrPrefix(int index) throws XMLStreamException
getAttrCount()
[; otherwise
IllegalArgumentException
will be thrown.index
- Index of the attributeXMLStreamException
- if either the underlying parser has
problems (cursor not valid or not pointing to START_ELEMENT),
or if invalid attributeIllegalArgumentException
- if attribute index is invalid
(less than 0 or greater than the last valid index
[getAttributeCount()-1])public String getAttrNsUri(int index) throws XMLStreamException
getAttrCount()
[; otherwise
IllegalArgumentException
will be thrown.index
- Index of the attributeXMLStreamException
- if either the underlying parser has
problems (cursor not valid or not pointing to START_ELEMENT),
or if invalid attributeIllegalArgumentException
- if attribute index is invalid
(less than 0 or greater than the last valid index
[getAttributeCount()-1])public String getAttrValue(int index) throws XMLStreamException
getAttrCount()
[; otherwise
IllegalArgumentException
will be thrown.index
- Index of the attributeXMLStreamException
- if either the underlying parser has
problems (cursor not valid or not pointing to START_ELEMENT),
or if invalid attributeIllegalArgumentException
- if attribute index is invalid
(less than 0 or greater than the last valid index
[getAttributeCount()-1])public String getAttrValue(String localName) throws XMLStreamException
getAttrValue(String,String)
with
'null' for 'namespace URI' argumentXMLStreamException
public String getAttrValue(String namespaceURI, String localName) throws XMLStreamException
namespaceURI
- Namespace URI for the attribute, if any;
empty String or null if none.localName
- Local name of the attribute to access (in
namespace-aware mode: in non-namespace-aware mode, needs to
be the full name)XMLStreamException
- if either the underlying parser has
problems (cursor not valid or not pointing to START_ELEMENT),
or if invalid attributepublic boolean getAttrBooleanValue(int index) throws XMLStreamException
index
- Index of attribute to accessXMLStreamException
- If specified attribute can not be
accessed (due to cursor state), or if attribute value
is not a valid textual representation of booleanIllegalArgumentException
- If given attribute index is invalidpublic boolean getAttrBooleanValue(int index, boolean defValue) throws XMLStreamException
index
- Index of attribute to accessdefValue
- Value to return if attribute value exists but
is not a valid boolean valueXMLStreamException
- If specified attribute can not be
accessed (due to cursor state), or if attribute value
is not a valid textual representation of boolean.IllegalArgumentException
- If given attribute index
is invalidpublic int getAttrIntValue(int index) throws XMLStreamException
index
- Index of attribute to accessXMLStreamException
- If specified attribute can not be
accessed (due to cursor state), or if attribute value
is not a valid textual representation of integer.IllegalArgumentException
- If given attribute index
is invalidpublic int getAttrIntValue(int index, int defValue) throws XMLStreamException
index
- Index of attribute to accessdefValue
- Value to return if attribute value exists but
is not a valid integer valueXMLStreamException
- If specified attribute can not be
accessed (due to cursor state), or if attribute value
is not a valid textual representation of integer.IllegalArgumentException
- If given attribute index
is invalidpublic long getAttrLongValue(int index) throws XMLStreamException
index
- Index of attribute to accessXMLStreamException
- If specified attribute can not be
accessed (due to cursor state), or if attribute value
is not a valid textual representation of long.IllegalArgumentException
- If given attribute index
is invalidpublic long getAttrLongValue(int index, long defValue) throws XMLStreamException
index
- Index of attribute to accessdefValue
- Value to return if attribute value exists but
is not a valid long valueXMLStreamException
- If specified attribute can not be
accessed (due to cursor state), or if attribute value
is not a valid textual representation of long.IllegalArgumentException
- If given attribute index
is invalidpublic double getAttrDoubleValue(int index) throws XMLStreamException
index
- Index of attribute to accessXMLStreamException
- If specified attribute can not be
accessed (due to cursor state), or if attribute value
is not a valid textual representation of double.IllegalArgumentException
- If given attribute index
is invalidpublic double getAttrDoubleValue(int index, double defValue) throws XMLStreamException
index
- Index of attribute to accessdefValue
- Value to return if attribute value exists but
is not a valid double valueXMLStreamException
- If specified attribute can not be
accessed (due to cursor state), or if attribute value
is not a valid textual representation of double.IllegalArgumentException
- If given attribute index
is invalidpublic <T extends Enum<T>> T getAttrEnumValue(int index, Class<T> enumType) throws XMLStreamException
TypedXMLStreamException
to indicate the problem.index
- Index of attribute to accessXMLStreamException
- If specified attribute can not be
accessed (due to cursor state), or if attribute value
is not a valid textual representation of double.IllegalArgumentException
- If given attribute index
is invalidpublic byte[] getAttrBinaryValue(int index, org.codehaus.stax2.typed.Base64Variant variant) throws XMLStreamException
XMLStreamException
public byte[] getAttrBinaryValue(int index) throws XMLStreamException
Base64Variants.getDefaultVariant()
.XMLStreamException
@Deprecated public int getAttrIntValue(String uri, String localName) throws XMLStreamException
findAttrIndex(java.lang.String, java.lang.String)
and
getAttrIntValue(int)
instead.XMLStreamException
@Deprecated public int getAttrIntValue(String uri, String localName, int defValue) throws XMLStreamException
findAttrIndex(java.lang.String, java.lang.String)
and
getAttrIntValue(int,int)
instead.XMLStreamException
public String getElemStringValue() throws XMLStreamException
collectDescendantText(boolean)
in that
it does NOT work for mixed content
(child elements are not allowed:
comments and processing instructions are allowed and ignored
if encountered).
If any ignorable white space (as per schema, dtd or so) is encountered,
it will be ignored.
The main technical difference to collectDescendantText(boolean)
is
that this method tries to make use of Stax2 v3.0 Typed Access API,
if available, and can thus be more efficient.
XMLStreamException
- if content is not accessible; may also
be thrown if child elements are encountered.public boolean getElemBooleanValue() throws XMLStreamException
XMLStreamException
- if content is not accessible or
convertible to required return typepublic boolean getElemBooleanValue(boolean defValue) throws XMLStreamException
getElemBooleanValue()
, but instead of failing
on invalid value, returns given default value.XMLStreamException
public int getElemIntValue() throws XMLStreamException
XMLStreamException
- if content is not accessible or
convertible to required return typepublic int getElemIntValue(int defValue) throws XMLStreamException
getElemIntValue()
, but instead of failing
on invalid value, returns given default value.XMLStreamException
public long getElemLongValue() throws XMLStreamException
XMLStreamException
- if content is not accessible or
convertible to required return typepublic long getElemLongValue(long defValue) throws XMLStreamException
getElemLongValue()
, but instead of failing
on invalid value, returns given default value.XMLStreamException
public double getElemDoubleValue() throws XMLStreamException
XMLStreamException
- if content is not accessible or
convertible to required return typepublic double getElemDoubleValue(double defValue) throws XMLStreamException
getElemDoubleValue()
, but instead of failing
on invalid value, returns given default value.XMLStreamException
public <T extends Enum<T>> T getElemEnumValue(Class<T> enumType) throws XMLStreamException
TypedXMLStreamException
is thrown.
Element also can not contain mixed content (child elements; comments and processing instructions are allowed and ignored if encountered).
XMLStreamException
- if content is not accessible or
convertible to required return typeorg.codehaus.stax2.typed.TypedXMLStreamException
- if element value is non-empty
and not one of allowed values for the enumeration typepublic byte[] getElemBinaryValue(org.codehaus.stax2.typed.Base64Variant variant) throws XMLStreamException
XMLStreamException
public byte[] getElemBinaryValue() throws XMLStreamException
XMLStreamException
public Object getData()
setData(java.lang.Object)
call.public void setData(Object o)
getData()
.public abstract SMEvent getNext() throws XMLStreamException
Note that one side-effect of calling this method is to invalidate the child cursor, if one was active. This is done by iterating over any events child cursor (and its descendants if any) might expose.
XMLStreamConstants
, such as
XMLStreamConstants.START_ELEMENT
, if a new node was
iterated over; null
when there are no more
nodes this cursor can iterate over.XMLStreamException
- If there are underlying parsing
problems.public final SMInputCursor advance() throws XMLStreamException
getNext()
does, but instead of
returning resulting event type, returns this cursor.
The main purpose of this method is to allow for chaining
calls. This is especially useful right after constructing
a root level cursor, and needing to advance it to point to
the root element. As such, a common idiom is:
SMInputCursor positionedRoot = smFactory.rootElementCursor(file).advance();which both constructs the root element cursor, and positions it over the root element. Can be similarly used with other kinds of cursors as well, of course
XMLStreamException
public SMInputCursor childCursor(SMFilter f) throws XMLStreamException
IllegalStateException
; if it does not support
concept of child cursors, it will throw
UnsupportedOperationException
f
- Filter child cursor is to use for filtering out
'unwanted' nodes; may be null if no filtering is to be doneIllegalStateException
- If cursor can not be created due
to the state cursor is in.UnsupportedOperationException
- If cursor does not allow
creation of child cursors.XMLStreamException
public final SMInputCursor childCursor() throws XMLStreamException
IllegalStateException
; if it does not support
concept of child cursors, it will throw
UnsupportedOperationException
IllegalStateException
- If cursor can not be created due
to the state cursor is in.UnsupportedOperationException
- If cursor does not allow
creation of child cursors.XMLStreamException
public SMInputCursor descendantCursor(SMFilter f) throws XMLStreamException
IllegalStateException
; if it does not support
concept of descendant cursors, it will throw
UnsupportedOperationException
f
- Filter child cursor is to use for filtering out
'unwanted' nodes; may be null if no filtering is to be doneIllegalStateException
- If cursor can not be created due
to the state cursor is in (or for some cursors, if they never
allow creating such cursors)UnsupportedOperationException
- If cursor does not allow
creation of descendant cursors.XMLStreamException
public final SMInputCursor descendantCursor() throws XMLStreamException
IllegalStateException
; if it does not support
concept of descendant cursors, it will throw
UnsupportedOperationException
IllegalStateException
- If cursor can not be created due
to the state cursor is in (or for some cursors, if they never
allow creating such cursors)UnsupportedOperationException
- If cursor does not allow
creation of descendant cursors.XMLStreamException
public final SMInputCursor childElementCursor() throws XMLStreamException
childCursor(SMFilterFactory.getElementOnlyFilter());
XMLStreamException
public final SMInputCursor childElementCursor(QName elemName) throws XMLStreamException
childCursor(SMFilterFactory.getElementOnlyFilter(elemName));
Will only return START_ELEMENT and END_ELEMENT events, whose element
name matches given qname.XMLStreamException
public final SMInputCursor childElementCursor(String elemLocalName) throws XMLStreamException
childCursor(SMFilterFactory.getElementOnlyFilter(elemName));
Will only return START_ELEMENT and END_ELEMENT events, whose element's
local name matches given local name, and that does not belong to
a namespace.XMLStreamException
public final SMInputCursor descendantElementCursor() throws XMLStreamException
descendantCursor(SMFilterFactory.getElementOnlyFilter());
XMLStreamException
public final SMInputCursor descendantElementCursor(QName elemName) throws XMLStreamException
descendantCursor(SMFilterFactory.getElementOnlyFilter(elemName));
Will only return START_ELEMENT and END_ELEMENT events, whose element
name matches given qname.XMLStreamException
public final SMInputCursor descendantElementCursor(String elemLocalName) throws XMLStreamException
descendantCursor(SMFilterFactory.getElementOnlyFilter(elemLocalName));
.
Will only return START_ELEMENT and END_ELEMENT events, whose element
local name matches given local name, and that do not belong to a
namespaceXMLStreamException
public final SMInputCursor childMixedCursor() throws XMLStreamException
childCursor(SMFilterFactory.getMixedFilter());
XMLStreamException
public final SMInputCursor descendantMixedCursor() throws XMLStreamException
descendantCursor(SMFilterFactory.getMixedFilter());
XMLStreamException
public XMLStreamException constructStreamException(String msg)
public void throwStreamException(String msg) throws XMLStreamException
constructStreamException(java.lang.String)
constructs and returns.XMLStreamException
public String getPathDesc()
Note: while results look similar to XPath expressions, they are not accurate (or even valid) XPath. This is partly because of filtering, and partly because of differences between element/node index calculation. The idea is to make it easier to get reasonable idea of logical location, in addition to physical input location.
protected String getCurrEventDesc()
public String toString()
protected SMElementInfo constructElementInfo(SMElementInfo parent, SMElementInfo prevSibling) throws XMLStreamException
Note caller already suppresses calls so that this method is only called when information needs to be preserved. Further, previous element is only passed if such linkage is to be preserved (reason for not always doing it is the increased memory usage).
Finally, note that this method does NOT implement
ElementInfoFactory
, as its signature does not include the
cursor argument, as that's passed as this pointer already.
XMLStreamException
protected abstract SMInputCursor constructChildCursor(SMFilter f) throws XMLStreamException
Note that custom cursor implementations can be used by overriding this method.
XMLStreamException
protected abstract SMInputCursor constructDescendantCursor(SMFilter f) throws XMLStreamException
Note that custom cursor implementations can be used by overriding this method.
XMLStreamException
protected void _markConsumed()
END_ELEMENT
.protected final int getBaseParentCount()
protected final void rewindPastChild() throws XMLStreamException
XMLStreamException
protected void invalidate() throws XMLStreamException
XMLStreamException
protected final org.codehaus.stax2.XMLStreamReader2 _getStreamReader()
protected static final SMEvent eventObjectByEventId(int type)
Note: no checks are done regarding validity of passed-in type.
SMEvent
matching given typeprotected XMLStreamException _notAccessible(String method) throws XMLStreamException
XMLStreamException
protected XMLStreamException _wrongState(String method, SMEvent expState) throws XMLStreamException
XMLStreamException
protected String getStateDesc()
protected String currentEventStr()
Copyright © 2013 FasterXML. All Rights Reserved.