Package com.ctc.wstx.sr
Class InputElementStack
java.lang.Object
com.ctc.wstx.sr.InputElementStack
- All Implemented Interfaces:
NamespaceContext
,org.codehaus.stax2.AttributeInfo
,org.codehaus.stax2.validation.ValidationContext
public final class InputElementStack
extends Object
implements org.codehaus.stax2.AttributeInfo, NamespaceContext, org.codehaus.stax2.validation.ValidationContext
Shared base class that defines API stream reader uses to communicate
with the element stack implementation, independent of whether it's
operating in namespace-aware or non-namespace modes.
Element stack class is used for storing nesting information about open
elements, and for namespace-aware mode, also information about
namespaces active (including default namespace), during parsing of
XML input.
This class also implements NamespaceContext
, since it has all
the information necessary, so parser can just return element stack
instance as necesary.
-
Field Summary
FieldsModifier and TypeFieldDescription(package private) static final int
protected final AttributeCollector
protected final ReaderConfig
protected Element
Currently open element, if any; null outside root element.protected int
protected Element
protected int
Index of the attribute with type of ID, if known (most likely due to Xml:id support); -1 if not available, or no ID attribute for current element.protected String
protected QName
protected BaseNsContext
Last potentially shareable NamespaceContext created by this stack.protected String
protected String
protected boolean
protected final StringVector
Vector that contains all currently active namespaces; one String for prefix, another for matching URI.protected final boolean
protected NsDefaultProvider
Object that will need to be consulted about namespace bindings, since it has some knowledge about default namespace declarations (has default attribute value expansion).protected InputProblemReporter
protected long
protected org.codehaus.stax2.validation.XMLValidator
Optional validator object that will get called if set, and that can validate xml content. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionint
addDefaultAttribute
(String localName, String uri, String prefix, String value) Method called by actual validator instances when attributes with default values have no explicit values for the element; if so, default value needs to be added as if it was parsed from the element.void
addNsBinding
(String prefix, String uri) Callback method called by the namespace default provider.protected org.codehaus.stax2.validation.XMLValidator
addValidator
(org.codehaus.stax2.validation.XMLValidator vld) protected void
Method called to construct a non-transient NamespaceContext instance; generally needed when creating events to return from event-based iterators.final int
findAttributeIndex
(String nsURI, String localName) final AttributeCollector
Method called byBasicStreamReader
, to retrieve the attribute collector it needs for some direct access.final int
getAttributeLocalName
(int index) getAttributeNamespace
(int index) getAttributePrefix
(int index) final String
getAttributeType
(int index) getAttributeValue
(int index) getAttributeValue
(String nsURI, String localName) final QName
final int
final String
final int
getDepth()
final int
Default implementation just indicates it does not know of such attributes; this because that requires DTD information that only some implementations have.final String
final String
getLocalNsPrefix
(int index) final String
getLocalNsURI
(int index) final String
getNamespaceURI
(String prefix) final int
Default implementation just indicates it does not know of such attributes; this because that requires DTD information that only some implementations have.final String
getNsURI()
final String
final String
getPrefixes
(String nsURI) final String
final int
final String
final boolean
isEmpty()
final boolean
boolean
isNotationDeclared
(String name) boolean
isPrefixLocallyDeclared
(String internedPrefix) boolean
final boolean
final boolean
pop()
Method called by the stream reader to remove the topmost (start) element from the stack; called when an end element is encountered during parsing.final void
Method called by the stream reader to add new (start) element into the stack in namespace-aware mode; called when a start element is encountered during parsing, but only in ns-aware mode.protected boolean
This is a method called by the reader to ensure that we have at least one 'real' validator.void
reportProblem
(org.codehaus.stax2.validation.XMLValidationProblem problem) int
Method called to resolve element and attribute namespaces (in namespace-aware mode), and do optional validation using pluggable validator object.protected void
setAutomaticDTDValidator
(org.codehaus.stax2.validation.XMLValidator validator, NsDefaultProvider nsDefs) Method called to connect the automatically handled DTD validator (one detected from DOCTYPE, loaded and completely handled by the stream reader without application calling validation methods).org.codehaus.stax2.validation.XMLValidator
stopValidatingAgainst
(org.codehaus.stax2.validation.XMLValidationSchema schema) org.codehaus.stax2.validation.XMLValidator
stopValidatingAgainst
(org.codehaus.stax2.validation.XMLValidator validator) private void
throwIllegalIndex
(int index, int localCount) org.codehaus.stax2.validation.XMLValidator
validateAgainst
(org.codehaus.stax2.validation.XMLValidationSchema schema) int
Method called after parsing (but before returning) end element, to allow for pluggable validators to verify correctness of the content model for the closing element.final void
validateText
(TextBuffer tb, boolean lastTextSegment) final void
validateText
(String contents, boolean lastTextSegment)
-
Field Details
-
ID_ATTR_NONE
static final int ID_ATTR_NONE- See Also:
-
mNsAware
protected final boolean mNsAware -
mAttrCollector
-
mConfig
-
mReporter
-
mNsDefaultProvider
Object that will need to be consulted about namespace bindings, since it has some knowledge about default namespace declarations (has default attribute value expansion). -
mDepth
protected int mDepth -
mTotalElements
protected long mTotalElements -
mNamespaces
Vector that contains all currently active namespaces; one String for prefix, another for matching URI. Does also include default name spaces (at most one per level). -
mCurrElement
Currently open element, if any; null outside root element. -
mMayHaveNsDefaults
protected boolean mMayHaveNsDefaults -
mValidator
protected org.codehaus.stax2.validation.XMLValidator mValidatorOptional validator object that will get called if set, and that can validate xml content. Note that it is possible that this is set to a proxy object that calls multiple validators in sequence. -
mIdAttrIndex
protected int mIdAttrIndexIndex of the attribute with type of ID, if known (most likely due to Xml:id support); -1 if not available, or no ID attribute for current element. -
mLastLocalName
-
mLastPrefix
-
mLastNsURI
-
mLastName
-
mLastNsContext
Last potentially shareable NamespaceContext created by this stack. This reference is cleared each time bindings change (either due to a start element with new bindings, or due to the matching end element that closes scope of such binding(s)). -
mFreeElement
-
-
Constructor Details
-
InputElementStack
-
-
Method Details
-
connectReporter
-
addValidator
protected org.codehaus.stax2.validation.XMLValidator addValidator(org.codehaus.stax2.validation.XMLValidator vld) -
setAutomaticDTDValidator
protected void setAutomaticDTDValidator(org.codehaus.stax2.validation.XMLValidator validator, NsDefaultProvider nsDefs) Method called to connect the automatically handled DTD validator (one detected from DOCTYPE, loaded and completely handled by the stream reader without application calling validation methods). Handled separately, since its behaviour is potentially different from that of explicitly added validators. -
validateAgainst
public org.codehaus.stax2.validation.XMLValidator validateAgainst(org.codehaus.stax2.validation.XMLValidationSchema schema) throws XMLStreamException - Throws:
XMLStreamException
-
stopValidatingAgainst
public org.codehaus.stax2.validation.XMLValidator stopValidatingAgainst(org.codehaus.stax2.validation.XMLValidationSchema schema) throws XMLStreamException - Throws:
XMLStreamException
-
stopValidatingAgainst
public org.codehaus.stax2.validation.XMLValidator stopValidatingAgainst(org.codehaus.stax2.validation.XMLValidator validator) throws XMLStreamException - Throws:
XMLStreamException
-
reallyValidating
protected boolean reallyValidating()This is a method called by the reader to ensure that we have at least one 'real' validator. This is only needed to ensure that validation problems that the reader can detect (illegal textual content) can be reported as validity errors. Since the validator API does not have a good way to cleanly deal with such a possibility, the check is rather fragile, but should work for now: essentially we need at least one validator object that either is not a sub-class ofDTDValidatorBase
or returns true forreallyValidating
.!!! TODO: remove need for this method (and method itself) with Woodstox 4.0, by adding necessary support in Stax2 XMLValidator interface.
-
getAttrCollector
Method called byBasicStreamReader
, to retrieve the attribute collector it needs for some direct access. -
createNonTransientNsContext
Method called to construct a non-transient NamespaceContext instance; generally needed when creating events to return from event-based iterators. -
push
Method called by the stream reader to add new (start) element into the stack in namespace-aware mode; called when a start element is encountered during parsing, but only in ns-aware mode.- Throws:
XMLStreamException
-
pop
Method called by the stream reader to remove the topmost (start) element from the stack; called when an end element is encountered during parsing.- Returns:
- True if stack has more elements; false if not (that is, root element closed)
- Throws:
XMLStreamException
-
resolveAndValidateElement
Method called to resolve element and attribute namespaces (in namespace-aware mode), and do optional validation using pluggable validator object.- Returns:
- Text content validation state that should be effective for the fully resolved element context
- Throws:
XMLStreamException
-
validateEndElement
Method called after parsing (but before returning) end element, to allow for pluggable validators to verify correctness of the content model for the closing element.- Returns:
- Validation state that should be effective for the parent element state
- Throws:
XMLStreamException
-
getAttributeCount
public final int getAttributeCount()- Specified by:
getAttributeCount
in interfaceorg.codehaus.stax2.AttributeInfo
- Specified by:
getAttributeCount
in interfaceorg.codehaus.stax2.validation.ValidationContext
-
findAttributeIndex
- Specified by:
findAttributeIndex
in interfaceorg.codehaus.stax2.AttributeInfo
- Specified by:
findAttributeIndex
in interfaceorg.codehaus.stax2.validation.ValidationContext
-
getIdAttributeIndex
public final int getIdAttributeIndex()Default implementation just indicates it does not know of such attributes; this because that requires DTD information that only some implementations have.- Specified by:
getIdAttributeIndex
in interfaceorg.codehaus.stax2.AttributeInfo
-
getNotationAttributeIndex
public final int getNotationAttributeIndex()Default implementation just indicates it does not know of such attributes; this because that requires DTD information that only some implementations have.- Specified by:
getNotationAttributeIndex
in interfaceorg.codehaus.stax2.AttributeInfo
-
getNamespaceURI
- Specified by:
getNamespaceURI
in interfaceNamespaceContext
- Specified by:
getNamespaceURI
in interfaceorg.codehaus.stax2.validation.ValidationContext
-
getPrefix
- Specified by:
getPrefix
in interfaceNamespaceContext
-
getPrefixes
- Specified by:
getPrefixes
in interfaceNamespaceContext
-
getXmlVersion
- Specified by:
getXmlVersion
in interfaceorg.codehaus.stax2.validation.ValidationContext
-
getAttributeLocalName
- Specified by:
getAttributeLocalName
in interfaceorg.codehaus.stax2.validation.ValidationContext
-
getAttributeNamespace
- Specified by:
getAttributeNamespace
in interfaceorg.codehaus.stax2.validation.ValidationContext
-
getAttributePrefix
- Specified by:
getAttributePrefix
in interfaceorg.codehaus.stax2.validation.ValidationContext
-
getAttributeValue
- Specified by:
getAttributeValue
in interfaceorg.codehaus.stax2.validation.ValidationContext
-
getAttributeValue
- Specified by:
getAttributeValue
in interfaceorg.codehaus.stax2.validation.ValidationContext
-
isNotationDeclared
- Specified by:
isNotationDeclared
in interfaceorg.codehaus.stax2.validation.ValidationContext
-
isUnparsedEntityDeclared
- Specified by:
isUnparsedEntityDeclared
in interfaceorg.codehaus.stax2.validation.ValidationContext
-
getBaseUri
- Specified by:
getBaseUri
in interfaceorg.codehaus.stax2.validation.ValidationContext
-
getCurrentElementName
- Specified by:
getCurrentElementName
in interfaceorg.codehaus.stax2.validation.ValidationContext
-
getValidationLocation
- Specified by:
getValidationLocation
in interfaceorg.codehaus.stax2.validation.ValidationContext
-
reportProblem
public void reportProblem(org.codehaus.stax2.validation.XMLValidationProblem problem) throws XMLStreamException - Specified by:
reportProblem
in interfaceorg.codehaus.stax2.validation.ValidationContext
- Throws:
XMLStreamException
-
addDefaultAttribute
public int addDefaultAttribute(String localName, String uri, String prefix, String value) throws XMLStreamException Method called by actual validator instances when attributes with default values have no explicit values for the element; if so, default value needs to be added as if it was parsed from the element.- Specified by:
addDefaultAttribute
in interfaceorg.codehaus.stax2.validation.ValidationContext
- Throws:
XMLStreamException
-
isPrefixLocallyDeclared
-
addNsBinding
Callback method called by the namespace default provider. At this point we can trust it to only call this method with somewhat valid arguments (no dups etc). -
validateText
- Throws:
XMLStreamException
-
validateText
- Throws:
XMLStreamException
-
isNamespaceAware
public final boolean isNamespaceAware() -
isEmpty
public final boolean isEmpty() -
getDepth
public final int getDepth()- Returns:
- Number of open elements in the stack; 0 when parser is in prolog/epilog, 1 inside root element and so on.
-
getDefaultNsURI
-
getNsURI
-
getPrefix
-
getLocalName
-
matches
-
getTopElementDesc
-
getTotalNsCount
public final int getTotalNsCount()- Returns:
- Number of active prefix/namespace mappings for current scope, including mappings from enclosing elements.
-
getCurrentNsCount
public final int getCurrentNsCount()- Returns:
- Number of active prefix/namespace mappings for current scope, NOT including mappings from enclosing elements.
-
getLocalNsPrefix
-
getLocalNsURI
-
throwIllegalIndex
private void throwIllegalIndex(int index, int localCount) -
getAttributeType
- Specified by:
getAttributeType
in interfaceorg.codehaus.stax2.validation.ValidationContext
- Returns:
- Schema (DTD, RNG, W3C Schema) based type of the attribute in specified index
-