com.ctc.wstx.dtd
public abstract class DTDValidatorBase extends XMLValidator implements NsDefaultProvider
XMLValidator
for DTD validation.
Since there are 2 sub-types -- full actual DTD validator, and a dummy
one that only adds type information and default values, with no actual
validation -- common functionality was refactored into this base
class.Modifier and Type | Field and Description |
---|---|
protected static java.util.HashMap |
EMPTY_MAP
Let's actually just reuse a local Map...
|
protected int |
mAttrCount
Number of attribute specification Objects in
mAttrSpecs ; needed to store in case type information
is requested later on. |
protected DTDAttribute[] |
mAttrSpecs
List of attribute declarations/specifications, one for each
attribute of the current element, for which there is a matching
value (either explicitly defined, or assigned via defaulting).
|
protected java.util.HashMap |
mCurrAttrDefs
Attribute definitions for attributes the current element may have
|
protected DTDElement |
mCurrElem
This is the element that is currently being validated; valid
during
validateElementStart ,
validateAttribute ,
validateElementAndAttributes calls. |
protected int |
mElemCount
Number of elements in
mElems . |
protected DTDElement[] |
mElems
Stack of element definitions matching the current active element stack.
|
protected int |
mIdAttrIndex
Index of the attribute of type ID, within current element's
attribute list.
|
protected boolean |
mNormAttrs
Flag that indicates whether parser wants the attribute values
to be normalized (according to XML specs) or not (which may be
more efficient, although not compliant with the specs)
|
protected PrefixedName |
mTmpKey |
CONTENT_ALLOW_ANY_TEXT, CONTENT_ALLOW_NONE, CONTENT_ALLOW_UNDEFINED, CONTENT_ALLOW_VALIDATABLE_TEXT, CONTENT_ALLOW_WS, CONTENT_ALLOW_WS_NONSTRICT
Constructor and Description |
---|
DTDValidatorBase(DTDSubset schema,
ValidationContext ctxt,
boolean hasNsDefaults,
java.util.Map elemSpecs,
java.util.Map genEntities) |
Modifier and Type | Method and Description |
---|---|
void |
checkNsDefaults(InputElementStack nsStack)
Method called by the input element stack to indicate that
it has just added local namespace declarations from the
current element, and is about to start resolving element
and attribute namespace bindings.
|
protected void |
doAddDefaultValue(DTDAttribute attr) |
protected void |
doReportValidationProblem(java.lang.String msg,
javax.xml.stream.Location loc) |
java.lang.String |
getAttributeType(int index)
Method for getting schema-specified type of an attribute, if
information is available.
|
int |
getIdAttrIndex()
Method for finding out the index of the attribute (collected using
the attribute collector; having DTD-derived info in same order)
that is of type ID.
|
protected abstract ElementIdMap |
getIdMap() |
int |
getNotationAttrIndex()
Method for finding out the index of the attribute (collected using
the attribute collector; having DTD-derived info in same order)
that is of type NOTATION.
|
XMLValidationSchema |
getSchema()
Returns the schema instance that created this validator
object, if known (and applicable).
|
boolean |
hasNsDefaults() |
boolean |
mayHaveNsDefaults(java.lang.String elemPrefix,
java.lang.String elemLN)
Calling this method before
checkNsDefaults(com.ctc.wstx.sr.InputElementStack) is necessary
to pass information regarding the current element; although
it will become available later on (via normal XMLValidator interface),
that's too late (after namespace binding and resolving). |
abstract boolean |
reallyValidating() |
void |
setAttrValueNormalization(boolean state)
Method that allows enabling/disabling attribute value normalization.
|
abstract java.lang.String |
validateAttribute(java.lang.String localName,
java.lang.String uri,
java.lang.String prefix,
char[] valueChars,
int valueStart,
int valueEnd)
Callback method called on validator to give it a chance to validate
the value of an attribute, as well as to normalize its value if
appropriate (remove leading/trailing/intervening white space for
certain token types etc.).
|
abstract java.lang.String |
validateAttribute(java.lang.String localName,
java.lang.String uri,
java.lang.String prefix,
java.lang.String value)
Callback method called on validator to give it a chance to validate
the value of an attribute, as well as to normalize its value if
appropriate (remove leading/trailing/intervening white space for
certain token types etc.).
|
abstract int |
validateElementAndAttributes()
Method called after calling
XMLValidator.validateAttribute(java.lang.String, java.lang.String, java.lang.String, java.lang.String) on all
attributes (if any), but before starting to handle element
content. |
abstract int |
validateElementEnd(java.lang.String localName,
java.lang.String uri,
java.lang.String prefix)
Method called right after encountering an element close tag.
|
abstract void |
validateElementStart(java.lang.String localName,
java.lang.String uri,
java.lang.String prefix)
Method called to update information about the newly encountered (start)
element.
|
void |
validateText(char[] cbuf,
int textStart,
int textEnd,
boolean lastTextSegment)
Method called to validate textual content.
|
void |
validateText(java.lang.String text,
boolean lastTextSegment)
Method called to validate textual content.
|
abstract void |
validationCompleted(boolean eod)
Method called when the validation is completed; either due to the
input stream ending, or due to an explicit 'stop validation' request
by the application (via context object).
|
getSchemaType
protected static final java.util.HashMap EMPTY_MAP
protected boolean mNormAttrs
protected DTDElement mCurrElem
validateElementStart
,
validateAttribute
,
validateElementAndAttributes
calls.protected DTDElement[] mElems
protected int mElemCount
mElems
.protected java.util.HashMap mCurrAttrDefs
protected DTDAttribute[] mAttrSpecs
protected int mAttrCount
mAttrSpecs
; needed to store in case type information
is requested later on.protected int mIdAttrIndex
protected final transient PrefixedName mTmpKey
public DTDValidatorBase(DTDSubset schema, ValidationContext ctxt, boolean hasNsDefaults, java.util.Map elemSpecs, java.util.Map genEntities)
public void setAttrValueNormalization(boolean state)
public abstract boolean reallyValidating()
public final XMLValidationSchema getSchema()
XMLValidator
ValidatorPair
will return null since it 'contains' multiple validators
and generally does not have just one parent or owner schema.getSchema
in class XMLValidator
public abstract void validateElementStart(java.lang.String localName, java.lang.String uri, java.lang.String prefix) throws javax.xml.stream.XMLStreamException
validateElementStart
in class XMLValidator
javax.xml.stream.XMLStreamException
public abstract java.lang.String validateAttribute(java.lang.String localName, java.lang.String uri, java.lang.String prefix, java.lang.String value) throws javax.xml.stream.XMLStreamException
XMLValidator
validateAttribute
in class XMLValidator
javax.xml.stream.XMLStreamException
public abstract java.lang.String validateAttribute(java.lang.String localName, java.lang.String uri, java.lang.String prefix, char[] valueChars, int valueStart, int valueEnd) throws javax.xml.stream.XMLStreamException
XMLValidator
validateAttribute
in class XMLValidator
valueChars
- Character array that contains value (possibly
along with some other text)valueStart
- Index of the first character of the value in
in valueChars
arrayvalueEnd
- Index of the character AFTER the last character;
so that the length of the value String is
valueEnd - valueStart
javax.xml.stream.XMLStreamException
public abstract int validateElementAndAttributes() throws javax.xml.stream.XMLStreamException
XMLValidator
XMLValidator.validateAttribute(java.lang.String, java.lang.String, java.lang.String, java.lang.String)
on all
attributes (if any), but before starting to handle element
content.validateElementAndAttributes
in class XMLValidator
CONTENT_ALLOW_
constants, to indicate
what kind of textual content is allowed at the scope returned
to after the element has closed.javax.xml.stream.XMLStreamException
public abstract int validateElementEnd(java.lang.String localName, java.lang.String uri, java.lang.String prefix) throws javax.xml.stream.XMLStreamException
XMLValidator
validateElementEnd
in class XMLValidator
javax.xml.stream.XMLStreamException
public void validateText(java.lang.String text, boolean lastTextSegment) throws javax.xml.stream.XMLStreamException
XMLValidator
Note: this method is only guaranteed to be called when
XMLValidator.validateElementAndAttributes()
for the currently open
element returned XMLValidator.CONTENT_ALLOW_VALIDATABLE_TEXT
(or,
in case of mixed content, XMLValidator.validateElementEnd(java.lang.String, java.lang.String, java.lang.String)
, for the
last enclosed element). Otherwise, validator context may choose
not to call the method as an optimization.
validateText
in class XMLValidator
text
- Text content to validatelastTextSegment
- Whether this text content is the last text
segment before a close element; true if it is, false if it is not,
or no determination can be made. Can be used for optimizing
validation -- if this is true, no text needs to be buffered since
no more will be sent before the current element closes.javax.xml.stream.XMLStreamException
public void validateText(char[] cbuf, int textStart, int textEnd, boolean lastTextSegment) throws javax.xml.stream.XMLStreamException
XMLValidator
Note: this method is only guaranteed to be called when
XMLValidator.validateElementAndAttributes()
for the currently open
element returned XMLValidator.CONTENT_ALLOW_VALIDATABLE_TEXT
(or,
in case of mixed content, XMLValidator.validateElementEnd(java.lang.String, java.lang.String, java.lang.String)
, for the
last enclosed element). Otherwise, validator context may choose
not to call the method as an optimization.
validateText
in class XMLValidator
cbuf
- Character array that contains text content to validatetextStart
- Index of the first character of the content to
validatetextEnd
- Character following the last character of the
content to validate (that is, length of content to validate is
textEnd - textStart
).lastTextSegment
- Whether this text content is the last text
segment before a close element; true if it is, false if it is not,
or no determination can be made. Can be used for optimizing
validation -- if this is true, no text needs to be buffered since
no more will be sent before the current element closes.javax.xml.stream.XMLStreamException
public abstract void validationCompleted(boolean eod) throws javax.xml.stream.XMLStreamException
XMLValidator
validationCompleted
in class XMLValidator
eod
- Flag that indicates whether this method was called by the
context due to the end of the stream (true); or by an application
requesting end of validation (false).javax.xml.stream.XMLStreamException
public java.lang.String getAttributeType(int index)
XMLValidator
getAttributeType
in class XMLValidator
public int getIdAttrIndex()
getIdAttrIndex
in class XMLValidator
public int getNotationAttrIndex()
getNotationAttrIndex
in class XMLValidator
public boolean mayHaveNsDefaults(java.lang.String elemPrefix, java.lang.String elemLN)
checkNsDefaults(com.ctc.wstx.sr.InputElementStack)
is necessary
to pass information regarding the current element; although
it will become available later on (via normal XMLValidator interface),
that's too late (after namespace binding and resolving).mayHaveNsDefaults
in interface NsDefaultProvider
public void checkNsDefaults(InputElementStack nsStack) throws javax.xml.stream.XMLStreamException
NsDefaultProvider
checkNsDefaults
in interface NsDefaultProvider
javax.xml.stream.XMLStreamException
protected abstract ElementIdMap getIdMap()
public boolean hasNsDefaults()
protected void doReportValidationProblem(java.lang.String msg, javax.xml.stream.Location loc) throws javax.xml.stream.XMLStreamException
javax.xml.stream.XMLStreamException
protected void doAddDefaultValue(DTDAttribute attr) throws javax.xml.stream.XMLStreamException
javax.xml.stream.XMLStreamException