com.ctc.wstx.sr
Class ValidatingStreamReader

java.lang.Object
  extended by com.ctc.wstx.io.WstxInputData
      extended by com.ctc.wstx.sr.StreamScanner
          extended by com.ctc.wstx.sr.BasicStreamReader
              extended by com.ctc.wstx.sr.ValidatingStreamReader
All Implemented Interfaces:
InputConfigFlags, ParsingErrorMsgs, InputProblemReporter, StreamReaderImpl, javax.xml.stream.XMLStreamConstants, javax.xml.stream.XMLStreamReader, DTDInfo, LocationInfo, Validatable, XMLStreamReader2

public class ValidatingStreamReader
extends BasicStreamReader

Implementation of XMLStreamReader that builds on BasicStreamReader, but adds full DTD-handling, including DTD validation


Field Summary
protected  ValidationProblemHandler mVldProbHandler
          Custom validation problem handler, if any.
 
Fields inherited from class com.ctc.wstx.sr.BasicStreamReader
DEFAULT_NS_PREFIX, mAttrCollector, mCfgCoalesceText, mCfgLazyParsing, mCfgNormalizeAttrs, mCfgReportTextAsChars, mCheckIndentation, mConfigFlags, mCurrEntity, mCurrToken, mDocStandalone, mDtdPublicId, mDtdSystemId, mElementStack, mGeneralEntities, mOwner, mPendingException, mSecondaryToken, mShortestTextSegment, mStDoctypeFound, mStEmptyElem, mStTextThreshold, mTextBuffer, mTokenState, mValidateText, mVldContent, mWsStatus, sPrefixXml, sPrefixXmlns
 
Fields inherited from class com.ctc.wstx.sr.StreamScanner
CHAR_CR_LF_OR_NULL, CHAR_FIRST_PURE_TEXT, CHAR_LOWEST_LEGAL_LOCALNAME_CHAR, INT_CR_LF_OR_NULL, mCfgNormalizeLFs, mCfgNsEnabled, mCfgReplaceEntities, mConfig, mCurrDepth, mCurrName, mDocXmlVersion, mInput, mInputTopDepth, mNameBuffer, mRootInput, mTokenInputCol, mTokenInputRow, mTokenInputTotal, SAX_COMPAT_MODE
 
Fields inherited from class com.ctc.wstx.io.WstxInputData
CHAR_NULL, CHAR_SPACE, INT_NULL, INT_SPACE, MAX_UNICODE_CHAR, mCurrInputProcessed, mCurrInputRow, mCurrInputRowStart, mInputBuffer, mInputLen, mInputPtr, mXml11
 
Fields inherited from interface org.codehaus.stax2.XMLStreamReader2
FEATURE_DTD_OVERRIDE
 
Fields inherited from interface javax.xml.stream.XMLStreamConstants
ATTRIBUTE, CDATA, CHARACTERS, COMMENT, DTD, END_DOCUMENT, END_ELEMENT, ENTITY_DECLARATION, ENTITY_REFERENCE, NAMESPACE, NOTATION_DECLARATION, PROCESSING_INSTRUCTION, SPACE, START_DOCUMENT, START_ELEMENT
 
Fields inherited from interface com.ctc.wstx.cfg.InputConfigFlags
CFG_AUTO_CLOSE_INPUT, CFG_CACHE_DTDS, CFG_CACHE_DTDS_BY_PUBLIC_ID, CFG_COALESCE_TEXT, CFG_INTERN_NS_URIS, CFG_LAZY_PARSING, CFG_NAMESPACE_AWARE, CFG_NORMALIZE_ATTR_VALUES, CFG_NORMALIZE_LFS, CFG_PRESERVE_LOCATION, CFG_REPLACE_ENTITY_REFS, CFG_REPORT_CDATA, CFG_REPORT_PROLOG_WS, CFG_SUPPORT_DTD, CFG_SUPPORT_DTDPP, CFG_SUPPORT_EXTERNAL_ENTITIES, CFG_VALIDATE_AGAINST_DTD, CFG_VALIDATE_TEXT_CHARS, CFG_XMLID_TYPING, CFG_XMLID_UNIQ_CHECKS
 
Fields inherited from interface com.ctc.wstx.cfg.ParsingErrorMsgs
SUFFIX_EOF_EXP_NAME, SUFFIX_IN_ATTR_VALUE, SUFFIX_IN_CDATA, SUFFIX_IN_CLOSE_ELEMENT, SUFFIX_IN_COMMENT, SUFFIX_IN_DEF_ATTR_VALUE, SUFFIX_IN_DOC, SUFFIX_IN_DTD, SUFFIX_IN_DTD_EXTERNAL, SUFFIX_IN_DTD_INTERNAL, SUFFIX_IN_ELEMENT, SUFFIX_IN_ENTITY_REF, SUFFIX_IN_EPILOG, SUFFIX_IN_NAME, SUFFIX_IN_PROC_INSTR, SUFFIX_IN_PROLOG, SUFFIX_IN_TEXT, SUFFIX_IN_XML_DECL
 
Method Summary
protected  DTDId constructDtdId(java.lang.String pubId, java.lang.String sysId)
           
protected  DTDId constructDtdId(java.net.URL sysId)
           
static ValidatingStreamReader createValidatingStreamReader(BranchingReaderSource input, ReaderCreator owner, ReaderConfig cfg, InputBootstrapper bs, boolean forER)
          Factory method for constructing readers.
protected  void finishDTD(boolean copyContents)
          This method gets called to handle remainder of DOCTYPE declaration, essentially the optional internal subset.
 java.lang.Object getProcessedDTD()
           Note: DTD-handling sub-classes need to override this method.
 DTDValidationSchema getProcessedDTDSchema()
          Sub-class will override this method
 java.lang.Object getProperty(java.lang.String name)
           
protected  void initValidation()
          Method called right before handling the root element, by the base class.
protected  void reportInvalidContent(int evtType)
          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.
 void setFeature(java.lang.String name, java.lang.Object value)
          Method that can be used to set per-reader features such as configuration settings; both generic ones (names for which are defined as constants in this class), and implementation dependant ones.
 ValidationProblemHandler setValidationProblemHandler(ValidationProblemHandler h)
          Method that application can call to define a custom handler for validation problems encountered during validation process.
 XMLValidator stopValidatingAgainst(XMLValidationSchema schema)
          Method that can be called by application to stop validating output against a schema, for which Validatable.validateAgainst(org.codehaus.stax2.validation.XMLValidationSchema) was called earlier.
 XMLValidator stopValidatingAgainst(XMLValidator validator)
          Method that can be called by application to stop validating output using specified validator.
 XMLValidator validateAgainst(XMLValidationSchema schema)
          Method that will construct a XMLValidator instance from the given schema (unless a validator for that schema has already been added), initialize it if necessary, and make validatable object (reader, writer) call appropriate validation methods from this point on until the end of the document (that is, it's not scoped with sub-trees), or until validator is removed by an explicit call to Validatable.stopValidatingAgainst(org.codehaus.stax2.validation.XMLValidationSchema).
 
Methods inherited from class com.ctc.wstx.sr.BasicStreamReader
checkCData, checkKeyword, close, closeCompletely, createBasicStreamReader, createElementStack, ensureFinishToken, findEntity, finishToken, fireSaxCharacterEvents, fireSaxCommentEvent, fireSaxEndElement, fireSaxPIEvent, fireSaxSpaceEvents, fireSaxStartElement, getAttributeCollector, getAttributeCount, getAttributeInfo, getAttributeLocalName, getAttributeName, getAttributeNamespace, getAttributePrefix, getAttributeType, getAttributeValue, getAttributeValue, getCharacterEncodingScheme, getCurrentEntityDecl, getDepth, getDTDInfo, getDTDInternalSubset, getDTDPublicId, getDTDRootName, getDTDSystemId, getElementText, getEncoding, getEndingByteOffset, getEndingCharOffset, getEndLocation, getEventType, getFeature, getInputElementStack, getLocalName, getLocation, getLocationInfo, getName, getNamespaceContext, getNamespaceCount, getNamespacePrefix, getNamespaceURI, getNamespaceURI, getNamespaceURI, getNonTransientNamespaceContext, getPIData, getPITarget, getPrefix, getPrefixedName, getStartingByteOffset, getStartingCharOffset, getText, getText, getTextCharacters, getTextCharacters, getTextLength, getTextStart, getVersion, handleEOF, handleExpandedSurrogate, handleGreedyEntityProblem, handleIncompleteEntityProblem, handleMultiDocStart, handleMultiDocXmlDecl, handleRootElem, handleUndeclaredEntity, hasConfigFlags, hasName, hasNext, hasText, isAttributeSpecified, isCharacters, isEmptyElement, isEndElement, isNamespaceAware, isPropertySupported, isStandalone, isStartElement, isWhiteSpace, next, nextTag, parseQuoted, require, safeEnsureFinishToken, safeFinishToken, setProperty, skipElement, skipEquals, skipWS, standaloneSet, withStartElement, wrappedFinishToken
 
Methods inherited from class com.ctc.wstx.sr.StreamScanner
closeAllInput, constructFromIoe, constructNullCharException, constructWfcException, doReportProblem, ensureInput, expandBy50Pct, expandEntity, fullyResolveEntity, getCurrentInput, getCurrentLocation, getLastCharLocation, getNameBuffer, getNext, getNextAfterWS, getNextChar, getNextCharAfterWS, getNextCharFromCurrent, getNextInCurrAfterWS, getNextInCurrAfterWS, getSource, getStartLocation, getSystemId, initInputSource, inputInBuffer, loadMore, loadMore, loadMoreFromCurrent, loadMoreFromCurrent, markLF, markLF, parseEntityName, parseFNameForError, parseFullName, parseFullName, parseFullName2, parseLocalName, parseLocalName2, parsePublicId, parseSystemId, parseUntil, peekNext, pushback, reportProblem, reportProblem, reportProblem, reportProblem, reportValidationProblem, reportValidationProblem, reportValidationProblem, reportValidationProblem, reportValidationProblem, reportValidationProblem, reportValidationProblem, resolveCharOnlyEntity, resolveNonCharEntity, resolveSimpleEntity, skipCRLF, skipFullName, throwFromIOE, throwFromStrE, throwIllegalCall, throwInvalidSpace, throwInvalidSpace, throwLazyError, throwNullChar, throwNullParent, throwParseError, throwParseError, throwParseError, throwUnexpectedChar, throwUnexpectedEOB, throwUnexpectedEOF, throwWfcException, tokenTypeDesc
 
Methods inherited from class com.ctc.wstx.io.WstxInputData
copyBufferStateFrom, findIllegalNameChar, findIllegalNmtokenChar, getCharDesc, isNameChar, isNameChar, isNameStartChar, isNameStartChar, isSpaceChar
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.codehaus.stax2.LocationInfo
getCurrentLocation, getStartLocation
 

Field Detail

mVldProbHandler

protected 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 java.io.IOException,
                                                                  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:
java.io.IOException
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

setFeature

public void setFeature(java.lang.String name,
                       java.lang.Object value)
Description copied from interface: XMLStreamReader2
Method that can be used to set per-reader features such as configuration settings; both generic ones (names for which are defined as constants in this class), and implementation dependant ones.

Note: although some feature names are shared with XMLStreamReader2.getFeature(java.lang.String), not all are: some features are read-only, some write-only

Specified by:
setFeature in interface XMLStreamReader2
Overrides:
setFeature in class BasicStreamReader
Parameters:
name - Name of the feature to set
value - Value to set feature to.

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 DTDInfo
Overrides:
getProcessedDTD in class BasicStreamReader
Returns:
If current event is DTD, DTD support is enabled, and reader supports DTD processing, returns an internal Object implementation uses for storing/processing DTD; otherwise returns null.

getProcessedDTDSchema

public DTDValidationSchema getProcessedDTDSchema()
Description copied from class: BasicStreamReader
Sub-class will override this method

Specified by:
getProcessedDTDSchema in interface DTDInfo
Overrides:
getProcessedDTDSchema in class BasicStreamReader

validateAgainst

public XMLValidator validateAgainst(XMLValidationSchema schema)
                             throws javax.xml.stream.XMLStreamException
Description copied from interface: Validatable
Method that will construct a XMLValidator instance from the given schema (unless a validator for that schema has already been added), initialize it if necessary, and make validatable object (reader, writer) call appropriate validation methods from this point on until the end of the document (that is, it's not scoped with sub-trees), or until validator is removed by an explicit call to Validatable.stopValidatingAgainst(org.codehaus.stax2.validation.XMLValidationSchema).

Note that while this method can be called at any point in output processing, validator instances are not required to be able to handle addition at other points than right before outputting the root element.

Specified by:
validateAgainst in interface Validatable
Overrides:
validateAgainst in class BasicStreamReader
Returns:
Validator instance constructed, if validator was added, or null if a validator for the schema has already been constructed.
Throws:
javax.xml.stream.XMLStreamException

stopValidatingAgainst

public XMLValidator stopValidatingAgainst(XMLValidationSchema schema)
                                   throws javax.xml.stream.XMLStreamException
Description copied from interface: Validatable
Method that can be called by application to stop validating output against a schema, for which Validatable.validateAgainst(org.codehaus.stax2.validation.XMLValidationSchema) was called earlier.

Specified by:
stopValidatingAgainst in interface Validatable
Overrides:
stopValidatingAgainst in class BasicStreamReader
Returns:
Validator instance created from the schema that was removed, if one was in use; null if no such schema in use.
Throws:
javax.xml.stream.XMLStreamException

stopValidatingAgainst

public XMLValidator stopValidatingAgainst(XMLValidator validator)
                                   throws javax.xml.stream.XMLStreamException
Description copied from interface: Validatable
Method that can be called by application to stop validating output using specified validator. The validator passed should be an earlier return value for a call to Validatable.validateAgainst(org.codehaus.stax2.validation.XMLValidationSchema).

Note: the specified validator is compared for identity with validators in use, not for equality.

Specified by:
stopValidatingAgainst in interface Validatable
Overrides:
stopValidatingAgainst in class BasicStreamReader
Returns:
Validator instance found (ie. argument validator) if it was being used for validating current document; null if not.
Throws:
javax.xml.stream.XMLStreamException

setValidationProblemHandler

public ValidationProblemHandler setValidationProblemHandler(ValidationProblemHandler h)
Description copied from interface: Validatable
Method that application can call to define a custom handler for validation problems encountered during validation process.

Specified by:
setValidationProblemHandler in interface Validatable
Overrides:
setValidationProblemHandler in class BasicStreamReader
Parameters:
h - Handler to install, if non null; if null, indicates that the default (implementation-specific) handling should be used
Returns:
Previously set validation problem handler, if any; null if none was set

finishDTD

protected void finishDTD(boolean copyContents)
                  throws java.io.IOException,
                         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:
java.io.IOException
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

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.URL 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
Throws:
javax.xml.stream.XMLStreamException