Class 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

      Fields 
      Modifier and Type Field Description
      (package private) static int DEFAULT_STACK_SIZE
      Estimated maximum depth of typical documents; used to allocate the array for element stack
      protected static java.util.HashMap<java.lang.String,​EntityDecl> EMPTY_MAP
      Let's actually just reuse a local Map...
      (package private) static 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).
      (package private) org.codehaus.stax2.validation.ValidationContext mContext
      Validation context (owner) for this validator.
      protected java.util.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.
      (package private) java.util.Map<PrefixedName,​DTDElement> mElemSpecs
      Map that contains element specifications from DTD; null if no DOCTYPE declaration found.
      (package private) java.util.Map<java.lang.String,​EntityDecl> mGeneralEntities
      General entities defined in DTD subsets; needed for validating ENTITY/ENTITIES attributes.
      (package private) 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)
      (package private) DTDSubset mSchema
      DTD schema (DTDSubsetImpl) object that created this validator instance.
      (package private) char[] mTmpAttrValueBuffer
      Temporary buffer attribute instances can share for validation purposes
      protected PrefixedName mTmpKey  
      protected static java.util.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, org.codehaus.stax2.validation.ValidationContext ctxt, boolean hasNsDefaults, java.util.Map<PrefixedName,​DTDElement> elemSpecs, java.util.Map<java.lang.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​(java.lang.String msg, javax.xml.stream.Location loc)  
      java.lang.String getAttributeType​(int index)  
      (package private) PrefixedName getElemName()
      Name of current element on the top of the element stack.
      (package private) java.util.Map<java.lang.String,​EntityDecl> getEntityMap()  
      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()  
      (package private) javax.xml.stream.Location getLocation()  
      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()  
      (package private) char[] getTempAttrValueBuffer​(int neededLength)  
      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()  
      (package private) void reportValidationProblem​(java.lang.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.
      (package private) void reportValidationProblem​(java.lang.String format, java.lang.Object arg)  
      (package private) void reportValidationProblem​(java.lang.String format, java.lang.Object arg1, java.lang.Object arg2)  
      (package private) void reportValidationProblem​(java.lang.String msg, javax.xml.stream.Location loc)  
      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)  
      abstract java.lang.String validateAttribute​(java.lang.String localName, java.lang.String uri, java.lang.String prefix, java.lang.String value)  
      abstract int validateElementAndAttributes()  
      abstract int validateElementEnd​(java.lang.String localName, java.lang.String uri, java.lang.String prefix)  
      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)  
      void validateText​(java.lang.String text, boolean lastTextSegment)  
      abstract void validationCompleted​(boolean eod)  
      • Methods inherited from class org.codehaus.stax2.validation.XMLValidator

        getSchemaType
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • DEFAULT_STACK_SIZE

        static final int DEFAULT_STACK_SIZE
        Estimated maximum depth of typical documents; used to allocate the array for element stack
        See Also:
        Constant Field Values
      • EXP_MAX_ATTRS

        static final int EXP_MAX_ATTRS
        Estimated maximum number of attributes for a single element
        See Also:
        Constant Field Values
      • EMPTY_MAP

        protected static final java.util.HashMap<java.lang.String,​EntityDecl> EMPTY_MAP
        Let's actually just reuse a local Map...
      • mHasNsDefaults

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

        final org.codehaus.stax2.validation.ValidationContext mContext
        Validation context (owner) for this validator. Needed for adding default attribute values, for example.
      • mElemSpecs

        final java.util.Map<PrefixedName,​DTDElement> mElemSpecs
        Map that contains element specifications from DTD; null if no DOCTYPE declaration found.
      • mGeneralEntities

        final java.util.Map<java.lang.String,​EntityDecl> mGeneralEntities
        General entities defined in DTD subsets; needed for validating ENTITY/ENTITIES attributes.
      • 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 during validateElementStart, 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 in mElems.
      • mCurrAttrDefs

        protected java.util.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 in mAttrSpecs; 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.
      • mTmpAttrValueBuffer

        char[] mTmpAttrValueBuffer
        Temporary buffer attribute instances can share for validation purposes
    • Constructor Detail

      • DTDValidatorBase

        public DTDValidatorBase​(DTDSubset schema,
                                org.codehaus.stax2.validation.ValidationContext ctxt,
                                boolean hasNsDefaults,
                                java.util.Map<PrefixedName,​DTDElement> elemSpecs,
                                java.util.Map<java.lang.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 class org.codehaus.stax2.validation.XMLValidator
      • validateElementStart

        public abstract void validateElementStart​(java.lang.String localName,
                                                  java.lang.String uri,
                                                  java.lang.String prefix)
                                           throws javax.xml.stream.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 class org.codehaus.stax2.validation.XMLValidator
        Throws:
        javax.xml.stream.XMLStreamException
      • validateAttribute

        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
        Specified by:
        validateAttribute in class org.codehaus.stax2.validation.XMLValidator
        Throws:
        javax.xml.stream.XMLStreamException
      • validateAttribute

        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
        Specified by:
        validateAttribute in class org.codehaus.stax2.validation.XMLValidator
        Throws:
        javax.xml.stream.XMLStreamException
      • validateElementAndAttributes

        public abstract int validateElementAndAttributes()
                                                  throws javax.xml.stream.XMLStreamException
        Specified by:
        validateElementAndAttributes in class org.codehaus.stax2.validation.XMLValidator
        Throws:
        javax.xml.stream.XMLStreamException
      • validateElementEnd

        public abstract int validateElementEnd​(java.lang.String localName,
                                               java.lang.String uri,
                                               java.lang.String prefix)
                                        throws javax.xml.stream.XMLStreamException
        Specified by:
        validateElementEnd in class org.codehaus.stax2.validation.XMLValidator
        Returns:
        Validation state that should be effective for the parent element state
        Throws:
        javax.xml.stream.XMLStreamException
      • validateText

        public void validateText​(java.lang.String text,
                                 boolean lastTextSegment)
                          throws javax.xml.stream.XMLStreamException
        Specified by:
        validateText in class org.codehaus.stax2.validation.XMLValidator
        Throws:
        javax.xml.stream.XMLStreamException
      • validateText

        public void validateText​(char[] cbuf,
                                 int textStart,
                                 int textEnd,
                                 boolean lastTextSegment)
                          throws javax.xml.stream.XMLStreamException
        Specified by:
        validateText in class org.codehaus.stax2.validation.XMLValidator
        Throws:
        javax.xml.stream.XMLStreamException
      • validationCompleted

        public abstract void validationCompleted​(boolean eod)
                                          throws javax.xml.stream.XMLStreamException
        Specified by:
        validationCompleted in class org.codehaus.stax2.validation.XMLValidator
        Throws:
        javax.xml.stream.XMLStreamException
      • getAttributeType

        public java.lang.String getAttributeType​(int index)
        Specified by:
        getAttributeType in class org.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 class org.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 class org.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​(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).
        Specified by:
        mayHaveNsDefaults in interface NsDefaultProvider
      • checkNsDefaults

        public void checkNsDefaults​(InputElementStack nsStack)
                             throws javax.xml.stream.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 interface NsDefaultProvider
        Throws:
        javax.xml.stream.XMLStreamException
      • getElemName

        PrefixedName getElemName()
        Name of current element on the top of the element stack.
      • getLocation

        javax.xml.stream.Location getLocation()
      • getEntityMap

        java.util.Map<java.lang.String,​EntityDecl> getEntityMap()
      • getTempAttrValueBuffer

        char[] getTempAttrValueBuffer​(int neededLength)
      • hasNsDefaults

        public boolean hasNsDefaults()
      • reportValidationProblem

        void reportValidationProblem​(java.lang.String msg)
                              throws javax.xml.stream.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.
        Throws:
        javax.xml.stream.XMLStreamException
      • reportValidationProblem

        void reportValidationProblem​(java.lang.String msg,
                                     javax.xml.stream.Location loc)
                              throws javax.xml.stream.XMLStreamException
        Throws:
        javax.xml.stream.XMLStreamException
      • reportValidationProblem

        void reportValidationProblem​(java.lang.String format,
                                     java.lang.Object arg)
                              throws javax.xml.stream.XMLStreamException
        Throws:
        javax.xml.stream.XMLStreamException
      • reportValidationProblem

        void reportValidationProblem​(java.lang.String format,
                                     java.lang.Object arg1,
                                     java.lang.Object arg2)
                              throws javax.xml.stream.XMLStreamException
        Throws:
        javax.xml.stream.XMLStreamException
      • doReportValidationProblem

        protected void doReportValidationProblem​(java.lang.String msg,
                                                 javax.xml.stream.Location loc)
                                          throws javax.xml.stream.XMLStreamException
        Throws:
        javax.xml.stream.XMLStreamException
      • doAddDefaultValue

        protected void doAddDefaultValue​(DTDAttribute attr)
                                  throws javax.xml.stream.XMLStreamException
        Throws:
        javax.xml.stream.XMLStreamException