Class ValidatingStreamReader

  • All Implemented Interfaces:
    InputConfigFlags, ParsingErrorMsgs, InputProblemReporter, StreamReaderImpl, javax.xml.stream.XMLStreamConstants, javax.xml.stream.XMLStreamReader, org.codehaus.stax2.DTDInfo, org.codehaus.stax2.LocationInfo, org.codehaus.stax2.typed.TypedXMLStreamReader, org.codehaus.stax2.validation.Validatable, org.codehaus.stax2.XMLStreamReader2

    public class ValidatingStreamReader
    extends TypedStreamReader
    Implementation of XMLStreamReader2 that builds on TypedStreamReader and adds full DTD-handling including DTD validation
    • Field Detail

      • mDTD

        org.codehaus.stax2.validation.DTDValidationSchema mDTD
        Combined DTD set, constructed from parsed internal and external entities (which may have been set via override DTD functionality).
      • mAutoDtdValidator

        org.codehaus.stax2.validation.XMLValidator mAutoDtdValidator
        Validating reader keeps of automatically created DTD-based validator, since its handling may differ from that of application managed validators.
      • mDtdValidatorSet

        boolean mDtdValidatorSet
        Flag that indicates whether a DTD validator has been automatically set (as per DOCTYPE declaration or override)
      • mVldProbHandler

        protected org.codehaus.stax2.validation.ValidationProblemHandler mVldProbHandler
        Custom validation problem handler, if any.
    • Method Detail

      • createValidatingStreamReader

        public static ValidatingStreamReader createValidatingStreamReader​(BranchingReaderSource input,
                                                                          ReaderCreator owner,
                                                                          ReaderConfig cfg,
                                                                          InputBootstrapper bs,
                                                                          boolean forER)
                                                                   throws javax.xml.stream.XMLStreamException
        Factory method for constructing readers.
        Parameters:
        owner - "Owner" of this reader, factory that created the reader; needed for returning updated symbol table information after parsing.
        input - Input source used to read the XML document.
        cfg - Object that contains reader configuration info.
        bs - Bootstrapper to use, for reading xml declaration etc.
        forER - True if this reader is to be (configured to be) used by an event reader. Will cause some changes to default settings, as required by contracts Woodstox XMLEventReader implementation has (with respect to lazy parsing, short text segments etc)
        Throws:
        javax.xml.stream.XMLStreamException
      • getProperty

        public java.lang.Object getProperty​(java.lang.String name)
        Specified by:
        getProperty in interface javax.xml.stream.XMLStreamReader
        Overrides:
        getProperty in class BasicStreamReader
      • getProcessedDTD

        public java.lang.Object getProcessedDTD()
        Description copied from class: BasicStreamReader

        Note: DTD-handling sub-classes need to override this method.

        Specified by:
        getProcessedDTD in interface org.codehaus.stax2.DTDInfo
        Overrides:
        getProcessedDTD in class BasicStreamReader
      • getProcessedDTDSchema

        public org.codehaus.stax2.validation.DTDValidationSchema getProcessedDTDSchema()
        Description copied from class: BasicStreamReader
        Sub-class will override this method
        Specified by:
        getProcessedDTDSchema in interface org.codehaus.stax2.DTDInfo
        Overrides:
        getProcessedDTDSchema in class BasicStreamReader
      • validateAgainst

        public org.codehaus.stax2.validation.XMLValidator validateAgainst​(org.codehaus.stax2.validation.XMLValidationSchema schema)
                                                                   throws javax.xml.stream.XMLStreamException
        Specified by:
        validateAgainst in interface org.codehaus.stax2.validation.Validatable
        Overrides:
        validateAgainst in class BasicStreamReader
        Throws:
        javax.xml.stream.XMLStreamException
      • stopValidatingAgainst

        public org.codehaus.stax2.validation.XMLValidator stopValidatingAgainst​(org.codehaus.stax2.validation.XMLValidationSchema schema)
                                                                         throws javax.xml.stream.XMLStreamException
        Specified by:
        stopValidatingAgainst in interface org.codehaus.stax2.validation.Validatable
        Overrides:
        stopValidatingAgainst in class BasicStreamReader
        Throws:
        javax.xml.stream.XMLStreamException
      • stopValidatingAgainst

        public org.codehaus.stax2.validation.XMLValidator stopValidatingAgainst​(org.codehaus.stax2.validation.XMLValidator validator)
                                                                         throws javax.xml.stream.XMLStreamException
        Specified by:
        stopValidatingAgainst in interface org.codehaus.stax2.validation.Validatable
        Overrides:
        stopValidatingAgainst in class BasicStreamReader
        Throws:
        javax.xml.stream.XMLStreamException
      • setValidationProblemHandler

        public org.codehaus.stax2.validation.ValidationProblemHandler setValidationProblemHandler​(org.codehaus.stax2.validation.ValidationProblemHandler h)
        Specified by:
        setValidationProblemHandler in interface org.codehaus.stax2.validation.Validatable
        Overrides:
        setValidationProblemHandler in class BasicStreamReader
      • finishDTD

        protected void finishDTD​(boolean copyContents)
                          throws javax.xml.stream.XMLStreamException
        This method gets called to handle remainder of DOCTYPE declaration, essentially the optional internal subset. Internal subset, if such exists, is always read, but whether its contents are added to the read buffer depend on passed-in argument.

        NOTE: Since this method overrides the default implementation, make sure you do NOT change the method signature.

        Overrides:
        finishDTD in class BasicStreamReader
        Parameters:
        copyContents - If true, will copy contents of the internal subset of DOCTYPE declaration in the text buffer (in addition to parsing it for actual use); if false, will only do parsing.
        Throws:
        javax.xml.stream.XMLStreamException
      • reportValidationProblem

        public void reportValidationProblem​(org.codehaus.stax2.validation.XMLValidationProblem prob)
                                     throws javax.xml.stream.XMLStreamException
        If there is an error handler established, call it.
        Specified by:
        reportValidationProblem in interface InputProblemReporter
        Overrides:
        reportValidationProblem in class StreamScanner
        Throws:
        javax.xml.stream.XMLStreamException
      • initValidation

        protected void initValidation()
                               throws javax.xml.stream.XMLStreamException
        Method called right before handling the root element, by the base class. This allows for some initialization and checks to be done (not including ones that need access to actual element name)
        Overrides:
        initValidation in class BasicStreamReader
        Throws:
        javax.xml.stream.XMLStreamException
      • findDtdExtSubset

        private DTDSubset findDtdExtSubset​(java.lang.String pubId,
                                           java.lang.String sysId,
                                           DTDSubset intSubset)
                                    throws javax.xml.stream.XMLStreamException
        Method called by finishDTD, to locate the specified external DTD subset. Subset may be obtained from a cache, if cached copy exists and is compatible; if not, it will be read from the source identified by the public and/or system identifier passed.
        Throws:
        javax.xml.stream.XMLStreamException
      • findCachedSubset

        private DTDSubset findCachedSubset​(DTDId id,
                                           DTDSubset intSubset)
                                    throws javax.xml.stream.XMLStreamException
        Throws:
        javax.xml.stream.XMLStreamException
      • resolveExtSubsetPath

        private java.net.URI resolveExtSubsetPath​(java.lang.String systemId)
                                           throws java.io.IOException
        Method called to resolve path to external DTD subset, given system identifier.
        Throws:
        java.io.IOException
      • constructDtdId

        protected DTDId constructDtdId​(java.lang.String pubId,
                                       java.lang.String sysId)
                                throws java.io.IOException
        Throws:
        java.io.IOException
      • constructDtdId

        protected DTDId constructDtdId​(java.net.URI sysId)
                                throws java.io.IOException
        Throws:
        java.io.IOException
      • reportInvalidContent

        protected void reportInvalidContent​(int evtType)
                                     throws javax.xml.stream.XMLStreamException
        Method called by lower-level parsing code when invalid content (anything inside element with 'empty' content spec; text inside non-mixed element etc) is found during basic scanning. Note that actual DTD element structure problems are not reported through this method.
        Overrides:
        reportInvalidContent in class BasicStreamReader
        Parameters:
        evtType - Type of event that contained unexpected content
        Throws:
        javax.xml.stream.XMLStreamException