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
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
FieldsModifier and TypeFieldDescription(package private) static final int
Estimated maximum depth of typical documents; used to allocate the array for element stackprotected static final HashMap
<String, EntityDecl> Let's actually just reuse a local Map...(package private) static final int
Estimated maximum number of attributes for a single elementprotected int
Number of attribute specification Objects inmAttrSpecs
; needed to store in case type information is requested later on.protected DTDAttribute[]
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).(package private) final org.codehaus.stax2.validation.ValidationContext
Validation context (owner) for this validator.protected HashMap
<PrefixedName, DTDAttribute> Attribute definitions for attributes the current element may haveprotected DTDElement
This is the element that is currently being validated; valid duringvalidateElementStart
,validateAttribute
,validateElementAndAttributes
calls.protected int
Number of elements inmElems
.protected DTDElement[]
Stack of element definitions matching the current active element stack.(package private) final Map
<PrefixedName, DTDElement> Map that contains element specifications from DTD; null if no DOCTYPE declaration found.(package private) final Map
<String, EntityDecl> General entities defined in DTD subsets; needed for validating ENTITY/ENTITIES attributes.(package private) final boolean
Flag that indicates whether any of the elements declared has default attribute values for namespace declaration pseudo-attributes.protected int
Index of the attribute of type ID, within current element's attribute list.protected boolean
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)(package private) final DTDSubset
DTD schema (DTDSubsetImpl
) object that created this validator instance.(package private) char[]
Temporary buffer attribute instances can share for validation purposesprotected final PrefixedName
protected static final HashMap
<PrefixedName, DTDAttribute> 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
ConstructorsConstructorDescriptionDTDValidatorBase
(DTDSubset schema, org.codehaus.stax2.validation.ValidationContext ctxt, boolean hasNsDefaults, Map<PrefixedName, DTDElement> elemSpecs, Map<String, EntityDecl> genEntities) -
Method Summary
Modifier and TypeMethodDescriptionvoid
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
protected void
doReportValidationProblem
(String msg, Location loc) getAttributeType
(int index) (package private) PrefixedName
Name of current element on the top of the element stack.(package private) Map
<String, EntityDecl> int
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()
(package private) Location
int
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.final org.codehaus.stax2.validation.XMLValidationSchema
(package private) char[]
getTempAttrValueBuffer
(int neededLength) boolean
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
(package private) void
Method called to report validity problems; depending on mode, will either throw an exception, or add a problem notification to the list of problems.(package private) void
reportValidationProblem
(String format, Object arg) (package private) void
reportValidationProblem
(String format, Object arg1, Object arg2) (package private) void
reportValidationProblem
(String msg, Location loc) 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
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) Methods inherited from class org.codehaus.stax2.validation.XMLValidator
getSchemaType
-
Field Details
-
NO_ATTRS
-
DEFAULT_STACK_SIZE
static final int DEFAULT_STACK_SIZEEstimated maximum depth of typical documents; used to allocate the array for element stack- See Also:
-
EXP_MAX_ATTRS
static final int EXP_MAX_ATTRSEstimated maximum number of attributes for a single element- See Also:
-
EMPTY_MAP
Let's actually just reuse a local Map... -
mHasNsDefaults
final boolean mHasNsDefaultsFlag that indicates whether any of the elements declared has default attribute values for namespace declaration pseudo-attributes. -
mSchema
DTD schema (DTDSubsetImpl
) object that created this validator instance. -
mContext
final org.codehaus.stax2.validation.ValidationContext mContextValidation context (owner) for this validator. Needed for adding default attribute values, for example. -
mElemSpecs
Map that contains element specifications from DTD; null if no DOCTYPE declaration found. -
mGeneralEntities
General entities defined in DTD subsets; needed for validating ENTITY/ENTITIES attributes. -
mNormAttrs
protected boolean mNormAttrsFlag 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
This is the element that is currently being validated; valid duringvalidateElementStart
,validateAttribute
,validateElementAndAttributes
calls. -
mElems
Stack of element definitions matching the current active element stack. Instances are elements definitions read from DTD. -
mElemCount
protected int mElemCountNumber of elements inmElems
. -
mCurrAttrDefs
Attribute definitions for attributes the current element may have -
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 mAttrCountNumber of attribute specification Objects inmAttrSpecs
; needed to store in case type information is requested later on. -
mIdAttrIndex
protected int mIdAttrIndexIndex 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
-
mTmpAttrValueBuffer
char[] mTmpAttrValueBufferTemporary buffer attribute instances can share for validation purposes
-
-
Constructor Details
-
DTDValidatorBase
public DTDValidatorBase(DTDSubset schema, org.codehaus.stax2.validation.ValidationContext ctxt, boolean hasNsDefaults, Map<PrefixedName, DTDElement> elemSpecs, Map<String, EntityDecl> genEntities)
-
-
Method Details
-
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
- 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
- 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
- Specified by:
validationCompleted
in classorg.codehaus.stax2.validation.XMLValidator
- Throws:
XMLStreamException
-
getAttributeType
- 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
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
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
-
getElemName
PrefixedName getElemName()Name of current element on the top of the element stack. -
getLocation
Location getLocation() -
getIdMap
-
getEntityMap
Map<String,EntityDecl> getEntityMap() -
getTempAttrValueBuffer
char[] getTempAttrValueBuffer(int neededLength) -
hasNsDefaults
public boolean hasNsDefaults() -
reportValidationProblem
Method called to report validity problems; depending on mode, will either throw an exception, or add a problem notification to the list of problems.- Throws:
XMLStreamException
-
reportValidationProblem
- Throws:
XMLStreamException
-
reportValidationProblem
- Throws:
XMLStreamException
-
reportValidationProblem
- Throws:
XMLStreamException
-
doReportValidationProblem
- Throws:
XMLStreamException
-
doAddDefaultValue
- Throws:
XMLStreamException
-