Top Description Fields Constructors Methods
com.ctc.wstx.dtd

public abstract Class DTDValidatorBase

extends XMLValidator
implements NsDefaultProvider
Class Inheritance
All Implemented Interfaces
com.ctc.wstx.sr.NsDefaultProvider
Known Direct Subclasses
com.ctc.wstx.dtd.DTDTypingNonValidator, com.ctc.wstx.dtd.DTDValidator
Imports
java.text.MessageFormat, java.util.*, javax.xml.stream.Location, .XMLStreamException, org.codehaus.stax2.validation.*, com.ctc.wstx.api.WstxInputProperties, com.ctc.wstx.ent.EntityDecl, com.ctc.wstx.sr.NsDefaultProvider, .InputElementStack, com.ctc.wstx.util.DataUtil, .ElementIdMap, .ExceptionUtil, .PrefixedName

Shared abstract base class for Woodstox implementations of 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.

Field Summary

Modifier and TypeField and Description
pack-priv static final int
DEFAULT_STACK_SIZE

Estimated maximum depth of typical documents; used to allocate the array for element stack

protected static final HashMap<String, EntityDecl>
EMPTY_MAP

Let's actually just reuse a local Map...

pack-priv static final int
EXP_MAX_ATTRS

Estimated maximum number of attributes for a single element

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).

pack-priv final ValidationContext
mContext

Validation context (owner) for this validator.

protected HashMap<PrefixedName, DTDAttribute>
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.

pack-priv final Map<PrefixedName, DTDElement>
mElemSpecs

Map that contains element specifications from DTD; null if no DOCTYPE declaration found.

pack-priv final Map<String, EntityDecl>
mGeneralEntities

General entities defined in DTD subsets; needed for validating ENTITY/ENTITIES attributes.

pack-priv final boolean
mHasNsDefaults

Flag that indicates whether any of the elements declared has default attribute values for namespace declaration pseudo-attributes.

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)

pack-priv final DTDSubset
mSchema

DTD schema (DTDSubsetImpl) object that created this validator instance.

pack-priv char[]
mTmpAttrValueBuffer

Temporary buffer attribute instances can share for validation purposes

protected final transient PrefixedName
protected static final HashMap<PrefixedName, DTDAttribute>
Inherited from org.codehaus.stax2.validation.XMLValidator:
CONTENT_ALLOW_ANY_TEXTCONTENT_ALLOW_NONECONTENT_ALLOW_UNDEFINEDCONTENT_ALLOW_VALIDATABLE_TEXTCONTENT_ALLOW_WSCONTENT_ALLOW_WS_NONSTRICT

Constructor Summary

AccessConstructor and Description
public
DTDValidatorBase(DTDSubset schema, ValidationContext ctxt, boolean hasNsDefaults, Map<PrefixedName, DTDElement> elemSpecs, Map<String, EntityDecl> genEntities)

Method Summary

Modifier and TypeMethod and Description
public void
checkNsDefaults(InputElementStack nsStack)

Implements com.ctc.wstx.sr.NsDefaultProvider.checkNsDefaults.

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
protected void
public String
getAttributeType(int index)

Implements abstract org.codehaus.stax2.validation.XMLValidator.getAttributeType.

Method for getting schema-specified type of an attribute, if information is available.

pack-priv PrefixedName
getElemName()

Name of current element on the top of the element stack.

pack-priv Map<String, EntityDecl>
public int

Returns:

Index of the attribute with type ID, in the current element, if one exists: -1 otherwise
getIdAttrIndex
()

Implements abstract org.codehaus.stax2.validation.XMLValidator.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. DTD explicitly specifies that at most one attribute can have this type for any element.

protected abstract ElementIdMap
pack-priv Location
public int

Returns:

Index of the attribute with type NOTATION, in the current element, if one exists: -1 otherwise
getNotationAttrIndex
()

Implements abstract org.codehaus.stax2.validation.XMLValidator.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.

public final XMLValidationSchema
getSchema()

Implements abstract org.codehaus.stax2.validation.XMLValidator.getSchema.

Returns the schema instance that created this validator object, if known (and applicable).

pack-priv char[]
getTempAttrValueBuffer(int neededLength)

public boolean
public boolean
mayHaveNsDefaults(String elemPrefix, String elemLN)

Implements com.ctc.wstx.sr.NsDefaultProvider.mayHaveNsDefaults.

Calling this method before checkNsDefaults 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).

public abstract boolean

Returns:

True for validator object that actually do validate content; false for objects that only use DTD type information.
reallyValidating
()

pack-priv void
reportValidationProblem(String msg)

Method called to report validity problems; depending on mode, will either throw an exception, or add a problem notification to the list of problems.

pack-priv void
pack-priv void
pack-priv void
public void
setAttrValueNormalization(boolean state)

Method that allows enabling/disabling attribute value normalization.

public abstract String
validateAttribute(String localName, String uri, String prefix, String value)

Implements abstract org.codehaus.stax2.validation.XMLValidator.validateAttribute.

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.).

public abstract String
validateAttribute(String localName, String uri, String prefix, char[]
Character array that contains value (possibly along with some other text)
valueChars
,
int
Index of the first character of the value in in valueChars array
valueStart
,
int
Index of the character AFTER the last character; so that the length of the value String is valueEnd - valueStart
valueEnd
)

Implements abstract org.codehaus.stax2.validation.XMLValidator.validateAttribute.

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.).

public abstract int
validateElementAndAttributes()

Implements abstract org.codehaus.stax2.validation.XMLValidator.validateElementAndAttributes.

Method called after calling validateAttribute on all attributes (if any), but before starting to handle element content.

public abstract int

Returns:

Validation state that should be effective for the parent element state
validateElementEnd
(String localName, String uri, String prefix)

Implements abstract org.codehaus.stax2.validation.XMLValidator.validateElementEnd.

Method called right after encountering an element close tag.

public abstract void
validateElementStart(String localName, String uri, String prefix)

Implements abstract org.codehaus.stax2.validation.XMLValidator.validateElementStart.

Method called to update information about the newly encountered (start) element.

public void
validateText(String
Text content to validate
text
,
boolean
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.
lastTextSegment
)

Implements abstract org.codehaus.stax2.validation.XMLValidator.validateText.

Method called to validate textual content.

public void
validateText(char[]
Character array that contains text content to validate
cbuf
,
int
Index of the first character of the content to validate
textStart
,
int
Character following the last character of the content to validate (that is, length of content to validate is textEnd - textStart).
textEnd
,
boolean
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.
lastTextSegment
)

Implements abstract org.codehaus.stax2.validation.XMLValidator.validateText.

Method called to validate textual content.

public abstract void
validationCompleted(boolean
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).
eod
)

Implements abstract org.codehaus.stax2.validation.XMLValidator.validationCompleted.

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).

Inherited from org.codehaus.stax2.validation.XMLValidator:
getSchemaType

Field Detail

DEFAULT_STACK_SIZEback to summary
pack-priv static final int DEFAULT_STACK_SIZE

Estimated maximum depth of typical documents; used to allocate the array for element stack

EMPTY_MAPback to summary
protected static final HashMap<String, EntityDecl> EMPTY_MAP

Let's actually just reuse a local Map...

EXP_MAX_ATTRSback to summary
pack-priv static final int EXP_MAX_ATTRS

Estimated maximum number of attributes for a single element

mAttrCountback to summary
protected int mAttrCount

Number of attribute specification Objects in mAttrSpecs; needed to store in case type information is requested later on.

mAttrSpecsback to summary
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).

mContextback to summary
pack-priv final ValidationContext mContext

Validation context (owner) for this validator. Needed for adding default attribute values, for example.

mCurrAttrDefsback to summary
protected HashMap<PrefixedName, DTDAttribute> mCurrAttrDefs

Attribute definitions for attributes the current element may have

mCurrElemback to summary
protected DTDElement mCurrElem

This is the element that is currently being validated; valid during validateElementStart, validateAttribute, validateElementAndAttributes calls.

mElemCountback to summary
protected int mElemCount

Number of elements in mElems.

mElemsback to summary
protected DTDElement[] mElems

Stack of element definitions matching the current active element stack. Instances are elements definitions read from DTD.

mElemSpecsback to summary
pack-priv final Map<PrefixedName, DTDElement> mElemSpecs

Map that contains element specifications from DTD; null if no DOCTYPE declaration found.

mGeneralEntitiesback to summary
pack-priv final Map<String, EntityDecl> mGeneralEntities

General entities defined in DTD subsets; needed for validating ENTITY/ENTITIES attributes.

mHasNsDefaultsback to summary
pack-priv final boolean mHasNsDefaults

Flag that indicates whether any of the elements declared has default attribute values for namespace declaration pseudo-attributes.

mIdAttrIndexback to summary
protected int mIdAttrIndex

Index of the attribute of type ID, within current element's attribute list. Track of this is kept separate from other attribute since id attributes often need to be used for resolving cross-references.

mNormAttrsback to summary
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)

mSchemaback to summary
pack-priv final DTDSubset mSchema

DTD schema (DTDSubsetImpl) object that created this validator instance.

mTmpAttrValueBufferback to summary
pack-priv char[] mTmpAttrValueBuffer

Temporary buffer attribute instances can share for validation purposes

mTmpKeyback to summary
protected final transient PrefixedName mTmpKey
NO_ATTRSback to summary
protected static final HashMap<PrefixedName, DTDAttribute> NO_ATTRS

Constructor Detail

DTDValidatorBaseback to summary
public DTDValidatorBase(DTDSubset schema, ValidationContext ctxt, boolean hasNsDefaults, Map<PrefixedName, DTDElement> elemSpecs, Map<String, EntityDecl> genEntities)

Method Detail

checkNsDefaultsback to summary
public void checkNsDefaults(InputElementStack nsStack) throws XMLStreamException

Implements com.ctc.wstx.sr.NsDefaultProvider.checkNsDefaults.

Doc from com.ctc.wstx.sr.NsDefaultProvider.checkNsDefaults.

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. This provider instance is to add namespace declarations from attribute defaults, if any, using callbacks to the input element stack.

Annotations
@Override
doAddDefaultValueback to summary
protected void doAddDefaultValue(DTDAttribute attr) throws XMLStreamException
doReportValidationProblemback to summary
protected void doReportValidationProblem(String msg, Location loc) throws XMLStreamException
getAttributeTypeback to summary
public String getAttributeType(int index)

Implements abstract org.codehaus.stax2.validation.XMLValidator.getAttributeType.

Doc from org.codehaus.stax2.validation.XMLValidator.getAttributeType.

Method for getting schema-specified type of an attribute, if information is available. If not, validators can return null to explicitly indicate no information was available.

Annotations
@Override
getElemNameback to summary
pack-priv PrefixedName getElemName()

Name of current element on the top of the element stack.

getEntityMapback to summary
pack-priv Map<String, EntityDecl> getEntityMap()
getIdAttrIndexback to summary
public int getIdAttrIndex()

Implements abstract org.codehaus.stax2.validation.XMLValidator.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. DTD explicitly specifies that at most one attribute can have this type for any element.

Returns:int

Index of the attribute with type ID, in the current element, if one exists: -1 otherwise

Annotations
@Override
getIdMapback to summary
protected abstract ElementIdMap getIdMap()
getLocationback to summary
pack-priv Location getLocation()
getNotationAttrIndexback to summary
public int getNotationAttrIndex()

Implements abstract org.codehaus.stax2.validation.XMLValidator.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. DTD explicitly specifies that at most one attribute can have this type for any element.

Returns:int

Index of the attribute with type NOTATION, in the current element, if one exists: -1 otherwise

Annotations
@Override
getSchemaback to summary
public final XMLValidationSchema getSchema()

Implements abstract org.codehaus.stax2.validation.XMLValidator.getSchema.

Doc from org.codehaus.stax2.validation.XMLValidator.getSchema.

Returns the schema instance that created this validator object, if known (and applicable). May return null for some instances: specifically, ValidatorPair will return null since it 'contains' multiple validators and generally does not have just one parent or owner schema.

Annotations
@Override
getTempAttrValueBufferback to summary
pack-priv char[] getTempAttrValueBuffer(int neededLength)
hasNsDefaultsback to summary
public boolean hasNsDefaults()
mayHaveNsDefaultsback to summary
public boolean mayHaveNsDefaults(String elemPrefix, String elemLN)

Implements com.ctc.wstx.sr.NsDefaultProvider.mayHaveNsDefaults.

Calling this method before checkNsDefaults 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).

Annotations
@Override
reallyValidatingback to summary
public abstract boolean reallyValidating()
Returns:boolean

True for validator object that actually do validate content; false for objects that only use DTD type information.

reportValidationProblemback to summary
pack-priv void reportValidationProblem(String msg) throws XMLStreamException

Method called to report validity problems; depending on mode, will either throw an exception, or add a problem notification to the list of problems.

reportValidationProblemback to summary
pack-priv void reportValidationProblem(String msg, Location loc) throws XMLStreamException
reportValidationProblemback to summary
pack-priv void reportValidationProblem(String format, Object arg) throws XMLStreamException
reportValidationProblemback to summary
pack-priv void reportValidationProblem(String format, Object arg1, Object arg2) throws XMLStreamException
setAttrValueNormalizationback to summary
public void setAttrValueNormalization(boolean state)

Method that allows enabling/disabling attribute value normalization. In general, readers by default enable normalization (to be fully xml compliant), whereas writers do not (since there is usually little to gain, if anything -- it is even possible value may be written before validation is called in some cases)

validateAttributeback to summary
public abstract String validateAttribute(String localName, String uri, String prefix, String value) throws XMLStreamException

Implements abstract org.codehaus.stax2.validation.XMLValidator.validateAttribute.

Doc from org.codehaus.stax2.validation.XMLValidator.validateAttribute.

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.).

Returns:String

Null, if the passed value is fine as is; or a String, if it needs to be replaced. In latter case, caller will replace the value before passing it to other validators. Also, if the attribute value is accessible via caller (as is the case for stream readers), caller should return this value, instead of the original one.

Annotations
@Override
validateAttributeback to summary
public abstract String validateAttribute(String localName, String uri, String prefix, char[] valueChars, int valueStart, int valueEnd) throws XMLStreamException

Implements abstract org.codehaus.stax2.validation.XMLValidator.validateAttribute.

Doc from org.codehaus.stax2.validation.XMLValidator.validateAttribute.

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.).

Parameters
valueChars:char[]

Character array that contains value (possibly along with some other text)

valueStart:int

Index of the first character of the value in in valueChars array

valueEnd:int

Index of the character AFTER the last character; so that the length of the value String is valueEnd - valueStart

Returns:String

Null, if the passed value is fine as is; or a String, if it needs to be replaced. In latter case, caller will replace the value before passing it to other validators. Also, if the attribute value is accessible via caller (as is the case for stream readers), caller should return this value, instead of the original one.

Annotations
@Override
validateElementAndAttributesback to summary
public abstract int validateElementAndAttributes() throws XMLStreamException

Implements abstract org.codehaus.stax2.validation.XMLValidator.validateElementAndAttributes.

Doc from org.codehaus.stax2.validation.XMLValidator.validateElementAndAttributes.

Method called after calling validateAttribute on all attributes (if any), but before starting to handle element content.

Returns:int

One of CONTENT_ALLOW_ constants, to indicate what kind of textual content is allowed at the scope returned to after the element has closed.

Annotations
@Override
validateElementEndback to summary
public abstract int validateElementEnd(String localName, String uri, String prefix) throws XMLStreamException

Implements abstract org.codehaus.stax2.validation.XMLValidator.validateElementEnd.

Doc from org.codehaus.stax2.validation.XMLValidator.validateElementEnd.

Method called right after encountering an element close tag.

Returns:int

Validation state that should be effective for the parent element state

Annotations
@Override
validateElementStartback to summary
public abstract void validateElementStart(String localName, String uri, String prefix) throws XMLStreamException

Implements abstract org.codehaus.stax2.validation.XMLValidator.validateElementStart.

Method called to update information about the newly encountered (start) element. At this point namespace information has been resolved, but no DTD validation has been done. Validator is to do these validations, including checking for attribute value (and existence) compatibility.

Annotations
@Override
validateTextback to summary
public void validateText(String text, boolean lastTextSegment) throws XMLStreamException

Implements abstract org.codehaus.stax2.validation.XMLValidator.validateText.

Doc from org.codehaus.stax2.validation.XMLValidator.validateText.

Method called to validate textual content.

Note

this method is only guaranteed to be called when validateElementAndAttributes() for the currently open element returned CONTENT_ALLOW_VALIDATABLE_TEXT (or, in case of mixed content, validateElementEnd, for the last enclosed element). Otherwise, validator context may choose not to call the method as an optimization.

Parameters
text:String

Text content to validate

lastTextSegment:boolean

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.

Annotations
@Override
validateTextback to summary
public void validateText(char[] cbuf, int textStart, int textEnd, boolean lastTextSegment) throws XMLStreamException

Implements abstract org.codehaus.stax2.validation.XMLValidator.validateText.

Doc from org.codehaus.stax2.validation.XMLValidator.validateText.

Method called to validate textual content.

Note

this method is only guaranteed to be called when validateElementAndAttributes() for the currently open element returned CONTENT_ALLOW_VALIDATABLE_TEXT (or, in case of mixed content, validateElementEnd, for the last enclosed element). Otherwise, validator context may choose not to call the method as an optimization.

Parameters
cbuf:char[]

Character array that contains text content to validate

textStart:int

Index of the first character of the content to validate

textEnd:int

Character following the last character of the content to validate (that is, length of content to validate is textEnd - textStart).

lastTextSegment:boolean

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.

Annotations
@Override
validationCompletedback to summary
public abstract void validationCompleted(boolean eod) throws XMLStreamException

Implements abstract org.codehaus.stax2.validation.XMLValidator.validationCompleted.

Doc from org.codehaus.stax2.validation.XMLValidator.validationCompleted.

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).

Parameters
eod:boolean

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).

Annotations
@Override