Class DTDValidatorBase
- java.lang.Object
-
- org.codehaus.stax2.validation.XMLValidator
-
- com.ctc.wstx.dtd.DTDValidatorBase
-
- All Implemented Interfaces:
NsDefaultProvider
- Direct Known Subclasses:
DTDTypingNonValidator,DTDValidator
public abstract class DTDValidatorBase extends XMLValidator implements NsDefaultProvider
Shared abstract base class for Woodstox implementations ofXMLValidatorfor 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
Fields Modifier and Type Field Description protected static HashMap<String,EntityDecl>EMPTY_MAPLet's actually just reuse a local Map...protected intmAttrCountNumber of attribute specification Objects inmAttrSpecs; needed to store in case type information is requested later on.protected DTDAttribute[]mAttrSpecsList 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 HashMap<PrefixedName,DTDAttribute>mCurrAttrDefsAttribute definitions for attributes the current element may haveprotected DTDElementmCurrElemThis is the element that is currently being validated; valid duringvalidateElementStart,validateAttribute,validateElementAndAttributescalls.protected intmElemCountNumber of elements inmElems.protected DTDElement[]mElemsStack of element definitions matching the current active element stack.protected intmIdAttrIndexIndex of the attribute of type ID, within current element's attribute list.protected booleanmNormAttrsFlag 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 PrefixedNamemTmpKeyprotected static HashMap<PrefixedName,DTDAttribute>NO_ATTRS-
Fields inherited from class org.codehaus.stax2.validation.XMLValidator
CONTENT_ALLOW_ANY_TEXT, CONTENT_ALLOW_NONE, CONTENT_ALLOW_UNDEFINED, CONTENT_ALLOW_VALIDATABLE_TEXT, CONTENT_ALLOW_WS, CONTENT_ALLOW_WS_NONSTRICT
-
-
Constructor Summary
Constructors Constructor Description DTDValidatorBase(DTDSubset schema, ValidationContext ctxt, boolean hasNsDefaults, Map<PrefixedName,DTDElement> elemSpecs, Map<String,EntityDecl> genEntities)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description voidcheckNsDefaults(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 voiddoAddDefaultValue(DTDAttribute attr)protected voiddoReportValidationProblem(String msg, Location loc)StringgetAttributeType(int index)Method for getting schema-specified type of an attribute, if information is available.intgetIdAttrIndex()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 ElementIdMapgetIdMap()intgetNotationAttrIndex()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.XMLValidationSchemagetSchema()Returns the schema instance that created this validator object, if known (and applicable).booleanhasNsDefaults()booleanmayHaveNsDefaults(String elemPrefix, String elemLN)Calling this method beforecheckNsDefaults(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 booleanreallyValidating()voidsetAttrValueNormalization(boolean state)Method that allows enabling/disabling attribute value normalization.abstract StringvalidateAttribute(String localName, String uri, 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 StringvalidateAttribute(String localName, String uri, String prefix, 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 intvalidateElementAndAttributes()Method called after callingXMLValidator.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 intvalidateElementEnd(String localName, String uri, String prefix)Method called right after encountering an element close tag.abstract voidvalidateElementStart(String localName, String uri, String prefix)Method called to update information about the newly encountered (start) element.voidvalidateText(char[] cbuf, int textStart, int textEnd, boolean lastTextSegment)Method called to validate textual content.voidvalidateText(String text, boolean lastTextSegment)Method called to validate textual content.abstract voidvalidationCompleted(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).-
Methods inherited from class org.codehaus.stax2.validation.XMLValidator
getSchemaType
-
-
-
-
Field Detail
-
NO_ATTRS
protected static final HashMap<PrefixedName,DTDAttribute> NO_ATTRS
-
EMPTY_MAP
protected static final HashMap<String,EntityDecl> EMPTY_MAP
Let's actually just reuse a local Map...
-
mNormAttrs
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)
-
mCurrElem
protected DTDElement mCurrElem
This is the element that is currently being validated; valid duringvalidateElementStart,validateAttribute,validateElementAndAttributescalls.
-
mElems
protected DTDElement[] mElems
Stack of element definitions matching the current active element stack. Instances are elements definitions read from DTD.
-
mElemCount
protected int mElemCount
Number of elements inmElems.
-
mCurrAttrDefs
protected HashMap<PrefixedName,DTDAttribute> mCurrAttrDefs
Attribute definitions for attributes the current element may have
-
mAttrSpecs
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).
-
mAttrCount
protected int mAttrCount
Number of attribute specification Objects inmAttrSpecs; needed to store in case type information is requested later on.
-
mIdAttrIndex
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.
-
mTmpKey
protected final transient PrefixedName mTmpKey
-
-
Constructor Detail
-
DTDValidatorBase
public DTDValidatorBase(DTDSubset schema, ValidationContext ctxt, boolean hasNsDefaults, Map<PrefixedName,DTDElement> elemSpecs, Map<String,EntityDecl> genEntities)
-
-
Method Detail
-
setAttrValueNormalization
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)
-
reallyValidating
public abstract boolean reallyValidating()
- Returns:
- True for validator object that actually do validate content; false for objects that only use DTD type information.
-
getSchema
public final XMLValidationSchema getSchema()
Description copied from class:XMLValidatorReturns the schema instance that created this validator object, if known (and applicable). May return null for some instances: specifically,ValidatorPairwill return null since it 'contains' multiple validators and generally does not have just one parent or owner schema.- Specified by:
getSchemain classXMLValidator
-
validateElementStart
public abstract void validateElementStart(String localName, String uri, String prefix) throws XMLStreamException
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.- Specified by:
validateElementStartin classXMLValidator- Throws:
XMLStreamException
-
validateAttribute
public abstract String validateAttribute(String localName, String uri, String prefix, String value) throws XMLStreamException
Description copied from class:XMLValidatorCallback 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.).- Specified by:
validateAttributein classXMLValidator- Returns:
- 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.
- Throws:
XMLStreamException
-
validateAttribute
public abstract String validateAttribute(String localName, String uri, String prefix, char[] valueChars, int valueStart, int valueEnd) throws XMLStreamException
Description copied from class:XMLValidatorCallback 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.).- Specified by:
validateAttributein classXMLValidatorvalueChars- Character array that contains value (possibly along with some other text)valueStart- Index of the first character of the value in invalueCharsarrayvalueEnd- Index of the character AFTER the last character; so that the length of the value String isvalueEnd - valueStart- Returns:
- 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.
- Throws:
XMLStreamException
-
validateElementAndAttributes
public abstract int validateElementAndAttributes() throws XMLStreamExceptionDescription copied from class:XMLValidatorMethod called after callingXMLValidator.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.- Specified by:
validateElementAndAttributesin classXMLValidator- Returns:
- One of
CONTENT_ALLOW_constants, to indicate what kind of textual content is allowed at the scope returned to after the element has closed. - Throws:
XMLStreamException
-
validateElementEnd
public abstract int validateElementEnd(String localName, String uri, String prefix) throws XMLStreamException
Description copied from class:XMLValidatorMethod called right after encountering an element close tag.- Specified by:
validateElementEndin classXMLValidator- Returns:
- Validation state that should be effective for the parent element state
- Throws:
XMLStreamException
-
validateText
public void validateText(String text, boolean lastTextSegment) throws XMLStreamException
Description copied from class:XMLValidatorMethod called to validate textual content.Note: this method is only guaranteed to be called when
XMLValidator.validateElementAndAttributes()for the currently open element returnedXMLValidator.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.- Specified by:
validateTextin classXMLValidator- Parameters:
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.- Throws:
XMLStreamException
-
validateText
public void validateText(char[] cbuf, int textStart, int textEnd, boolean lastTextSegment) throws XMLStreamExceptionDescription copied from class:XMLValidatorMethod called to validate textual content.Note: this method is only guaranteed to be called when
XMLValidator.validateElementAndAttributes()for the currently open element returnedXMLValidator.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.- Specified by:
validateTextin classXMLValidator- Parameters:
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 istextEnd - 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.- Throws:
XMLStreamException
-
validationCompleted
public abstract void validationCompleted(boolean eod) throws XMLStreamExceptionDescription copied from class:XMLValidatorMethod 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).- Specified by:
validationCompletedin classXMLValidator- Parameters:
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).- Throws:
XMLStreamException
-
getAttributeType
public String getAttributeType(int index)
Description copied from class:XMLValidatorMethod 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.- Specified by:
getAttributeTypein classXMLValidator
-
getIdAttrIndex
public 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. DTD explicitly specifies that at most one attribute can have this type for any element.- Specified by:
getIdAttrIndexin classXMLValidator- Returns:
- Index of the attribute with type ID, in the current element, if one exists: -1 otherwise
-
getNotationAttrIndex
public 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. DTD explicitly specifies that at most one attribute can have this type for any element.- Specified by:
getNotationAttrIndexin classXMLValidator- Returns:
- Index of the attribute with type NOTATION, in the current element, if one exists: -1 otherwise
-
mayHaveNsDefaults
public boolean mayHaveNsDefaults(String elemPrefix, String elemLN)
Calling this method beforecheckNsDefaults(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).- Specified by:
mayHaveNsDefaultsin interfaceNsDefaultProvider
-
checkNsDefaults
public void checkNsDefaults(InputElementStack nsStack) throws XMLStreamException
Description copied from interface:NsDefaultProviderMethod 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.- Specified by:
checkNsDefaultsin interfaceNsDefaultProvider- Throws:
XMLStreamException
-
getIdMap
protected abstract ElementIdMap getIdMap()
-
hasNsDefaults
public boolean hasNsDefaults()
-
doReportValidationProblem
protected void doReportValidationProblem(String msg, Location loc) throws XMLStreamException
- Throws:
XMLStreamException
-
doAddDefaultValue
protected void doAddDefaultValue(DTDAttribute attr) throws XMLStreamException
- Throws:
XMLStreamException
-
-