Package com.ctc.wstx.dtd
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 org.codehaus.stax2.validation.XMLValidator implements NsDefaultProvider
Shared abstract base class for Woodstox implementations ofXMLValidator
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
Fields Modifier and Type Field Description protected static HashMap<String,EntityDecl>
EMPTY_MAP
Let's actually just reuse a local Map...protected int
mAttrCount
Number of attribute specification Objects inmAttrSpecs
; 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 HashMap<PrefixedName,DTDAttribute>
mCurrAttrDefs
Attribute definitions for attributes the current element may haveprotected DTDElement
mCurrElem
This is the element that is currently being validated; valid duringvalidateElementStart
,validateAttribute
,validateElementAndAttributes
calls.protected int
mElemCount
Number of elements inmElems
.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
protected static HashMap<PrefixedName,DTDAttribute>
NO_ATTRS
-
Constructor Summary
Constructors Constructor Description DTDValidatorBase(DTDSubset schema, org.codehaus.stax2.validation.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 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(String msg, Location loc)
String
getAttributeType(int index)
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.org.codehaus.stax2.validation.XMLValidationSchema
getSchema()
boolean
hasNsDefaults()
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).abstract boolean
reallyValidating()
void
setAttrValueNormalization(boolean state)
Method that allows enabling/disabling attribute value normalization.abstract String
validateAttribute(String localName, String uri, String prefix, char[] valueChars, int valueStart, int valueEnd)
abstract String
validateAttribute(String localName, String uri, String prefix, String value)
abstract int
validateElementAndAttributes()
abstract int
validateElementEnd(String localName, String uri, String prefix)
abstract void
validateElementStart(String localName, String uri, String prefix)
Method called to update information about the newly encountered (start) element.void
validateText(char[] cbuf, int textStart, int textEnd, boolean lastTextSegment)
void
validateText(String text, boolean lastTextSegment)
abstract void
validationCompleted(boolean eod)
-
-
-
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
,validateElementAndAttributes
calls.
-
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, org.codehaus.stax2.validation.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 org.codehaus.stax2.validation.XMLValidationSchema getSchema()
- Specified by:
getSchema
in classorg.codehaus.stax2.validation.XMLValidator
-
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:
validateElementStart
in classorg.codehaus.stax2.validation.XMLValidator
- Throws:
XMLStreamException
-
validateAttribute
public abstract String validateAttribute(String localName, String uri, String prefix, String value) throws XMLStreamException
- Specified by:
validateAttribute
in classorg.codehaus.stax2.validation.XMLValidator
- Throws:
XMLStreamException
-
validateAttribute
public abstract String validateAttribute(String localName, String uri, String prefix, char[] valueChars, int valueStart, int valueEnd) throws XMLStreamException
- Specified by:
validateAttribute
in classorg.codehaus.stax2.validation.XMLValidator
- Throws:
XMLStreamException
-
validateElementAndAttributes
public abstract int validateElementAndAttributes() throws XMLStreamException
- Specified by:
validateElementAndAttributes
in classorg.codehaus.stax2.validation.XMLValidator
- Throws:
XMLStreamException
-
validateElementEnd
public abstract int validateElementEnd(String localName, String uri, String prefix) throws XMLStreamException
- Specified by:
validateElementEnd
in classorg.codehaus.stax2.validation.XMLValidator
- Returns:
- Validation state that should be effective for the parent element state
- Throws:
XMLStreamException
-
validateText
public void validateText(String text, boolean lastTextSegment) throws XMLStreamException
- Specified by:
validateText
in classorg.codehaus.stax2.validation.XMLValidator
- Throws:
XMLStreamException
-
validateText
public void validateText(char[] cbuf, int textStart, int textEnd, boolean lastTextSegment) throws XMLStreamException
- Specified by:
validateText
in classorg.codehaus.stax2.validation.XMLValidator
- Throws:
XMLStreamException
-
validationCompleted
public abstract void validationCompleted(boolean eod) throws XMLStreamException
- Specified by:
validationCompleted
in classorg.codehaus.stax2.validation.XMLValidator
- Throws:
XMLStreamException
-
getAttributeType
public String getAttributeType(int index)
- Specified by:
getAttributeType
in classorg.codehaus.stax2.validation.XMLValidator
-
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:
getIdAttrIndex
in classorg.codehaus.stax2.validation.XMLValidator
- 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:
getNotationAttrIndex
in classorg.codehaus.stax2.validation.XMLValidator
- 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:
mayHaveNsDefaults
in interfaceNsDefaultProvider
-
checkNsDefaults
public void checkNsDefaults(InputElementStack nsStack) throws XMLStreamException
Description copied from interface:NsDefaultProvider
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.- Specified by:
checkNsDefaults
in 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
-
-