Package com.ctc.wstx.sr
Class ValidatingStreamReader
- java.lang.Object
-
- com.ctc.wstx.io.WstxInputData
-
- com.ctc.wstx.sr.StreamScanner
-
- com.ctc.wstx.sr.BasicStreamReader
-
- com.ctc.wstx.sr.TypedStreamReader
-
- com.ctc.wstx.sr.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 ofXMLStreamReader2that builds onTypedStreamReaderand adds full DTD-handling including DTD validation- Author:
- Tatu Saloranta, Benson Margulies
-
-
Field Summary
Fields Modifier and Type Field Description (package private) org.codehaus.stax2.validation.XMLValidatormAutoDtdValidatorValidating reader keeps of automatically created DTD-based validator, since its handling may differ from that of application managed validators.(package private) org.codehaus.stax2.validation.DTDValidationSchemamDTDCombined DTD set, constructed from parsed internal and external entities (which may have been set via override DTD functionality).(package private) booleanmDtdValidatorSetFlag that indicates whether a DTD validator has been automatically set (as per DOCTYPE declaration or override)protected org.codehaus.stax2.validation.ValidationProblemHandlermVldProbHandlerCustom validation problem handler, if any.(package private) static java.lang.StringSTAX_PROP_ENTITIES(package private) static java.lang.StringSTAX_PROP_NOTATIONS-
Fields inherited from class com.ctc.wstx.sr.TypedStreamReader
_base64Decoder, _decoderFactory, MASK_TYPED_ACCESS_ARRAY, MASK_TYPED_ACCESS_BINARY, MIN_BINARY_CHUNK
-
Fields inherited from class com.ctc.wstx.sr.BasicStreamReader
ALL_WS_NO, ALL_WS_UNKNOWN, ALL_WS_YES, DOC_STANDALONE_NO, DOC_STANDALONE_UNKNOWN, DOC_STANDALONE_YES, MASK_GET_ELEMENT_TEXT, MASK_GET_TEXT, MASK_GET_TEXT_WITH_WRITER, MASK_GET_TEXT_XXX, mAttrCollector, mCfgCoalesceText, mCfgLazyParsing, mCfgReportTextAsChars, mCheckIndentation, mConfigFlags, mCurrTextLength, mCurrToken, mDocStandalone, mDtdPublicId, mDtdSystemId, mElementStack, mGeneralEntities, mOwner, mParseState, mPendingException, mReturnNullForDefaultNamespace, mRootLName, mRootPrefix, mSecondaryToken, mShortestTextSegment, mStDoctypeFound, mStEmptyElem, mStTextThreshold, mTextBuffer, mTokenState, mValidateText, mVldContent, mWsStatus, sPrefixXml, sPrefixXmlns, STATE_CLOSED, STATE_EPILOG, STATE_MULTIDOC_HACK, STATE_PROLOG, STATE_TREE, TOKEN_FULL_COALESCED, TOKEN_FULL_SINGLE, TOKEN_NOT_STARTED, TOKEN_PARTIAL_SINGLE, TOKEN_STARTED
-
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, mAllowXml11EscapedCharsInXml10, mCachedEntities, mCfgNsEnabled, mCfgReplaceEntities, mCfgTreatCharRefsAsEntities, mConfig, mCurrDepth, mCurrEntity, mCurrName, mDocInputEncoding, mDocXmlEncoding, mDocXmlVersion, mEntityExpansionCount, mEntityResolver, mInput, mInputTopDepth, mNameBuffer, mNormalizeLFs, mRootInput, mSymbols, mTokenInputCol, mTokenInputRow, mTokenInputTotal
-
Fields inherited from class com.ctc.wstx.io.WstxInputData
CHAR_NULL, CHAR_SPACE, INT_NULL, INT_SPACE, MAX_UNICODE_CHAR, mCurrInputProcessed, mCurrInputRow, mCurrInputRowStart, mInputBuffer, mInputEnd, mInputPtr, mXml11
-
Fields inherited from interface com.ctc.wstx.cfg.InputConfigFlags
CFG_ALLOW_XML11_ESCAPED_CHARS_IN_XML10, CFG_AUTO_CLOSE_INPUT, CFG_CACHE_DTDS, CFG_CACHE_DTDS_BY_PUBLIC_ID, CFG_COALESCE_TEXT, CFG_INTERN_NAMES, CFG_INTERN_NS_URIS, CFG_JAXP_FEATURE_SECURE_PROCESSING, CFG_LAZY_PARSING, CFG_NAMESPACE_AWARE, 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_TREAT_CHAR_REFS_AS_ENTS, CFG_VALIDATE_AGAINST_DTD, 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
-
-
Constructor Summary
Constructors Modifier Constructor Description privateValidatingStreamReader(InputBootstrapper bs, BranchingReaderSource input, ReaderCreator owner, ReaderConfig cfg, InputElementStack elemStack, boolean forER)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected DTDIdconstructDtdId(java.lang.String pubId, java.lang.String sysId)protected DTDIdconstructDtdId(java.net.URI sysId)static ValidatingStreamReadercreateValidatingStreamReader(BranchingReaderSource input, ReaderCreator owner, ReaderConfig cfg, InputBootstrapper bs, boolean forER)Factory method for constructing readers.private DTDSubsetfindCachedSubset(DTDId id, DTDSubset intSubset)private DTDSubsetfindDtdExtSubset(java.lang.String pubId, java.lang.String sysId, DTDSubset intSubset)Method called byfinishDTD, to locate the specified external DTD subset.protected voidfinishDTD(boolean copyContents)This method gets called to handle remainder of DOCTYPE declaration, essentially the optional internal subset.java.lang.ObjectgetProcessedDTD()Note: DTD-handling sub-classes need to override this method.org.codehaus.stax2.validation.DTDValidationSchemagetProcessedDTDSchema()Sub-class will override this methodjava.lang.ObjectgetProperty(java.lang.String name)protected voidinitValidation()Method called right before handling the root element, by the base class.protected voidreportInvalidContent(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.voidreportValidationProblem(org.codehaus.stax2.validation.XMLValidationProblem prob)If there is an error handler established, call it.private java.net.URIresolveExtSubsetPath(java.lang.String systemId)Method called to resolve path to external DTD subset, given system identifier.org.codehaus.stax2.validation.ValidationProblemHandlersetValidationProblemHandler(org.codehaus.stax2.validation.ValidationProblemHandler h)org.codehaus.stax2.validation.XMLValidatorstopValidatingAgainst(org.codehaus.stax2.validation.XMLValidationSchema schema)org.codehaus.stax2.validation.XMLValidatorstopValidatingAgainst(org.codehaus.stax2.validation.XMLValidator validator)org.codehaus.stax2.validation.XMLValidatorvalidateAgainst(org.codehaus.stax2.validation.XMLValidationSchema schema)-
Methods inherited from class com.ctc.wstx.sr.TypedStreamReader
_base64Decoder, _constructTypeException, _decoderFactory, _verifyQName, createStreamReader, getAttributeAs, getAttributeAsArray, getAttributeAsBinary, getAttributeAsBinary, getAttributeAsBoolean, getAttributeAsDecimal, getAttributeAsDouble, getAttributeAsDoubleArray, getAttributeAsFloat, getAttributeAsFloatArray, getAttributeAsInt, getAttributeAsIntArray, getAttributeAsInteger, getAttributeAsLong, getAttributeAsLongArray, getAttributeAsQName, getAttributeIndex, getElementAs, getElementAsBinary, getElementAsBinary, getElementAsBoolean, getElementAsDecimal, getElementAsDouble, getElementAsFloat, getElementAsInt, getElementAsInteger, getElementAsLong, getElementAsQName, readElementAsArray, readElementAsBinary, readElementAsBinary, readElementAsDoubleArray, readElementAsFloatArray, readElementAsIntArray, readElementAsLongArray
-
Methods inherited from class com.ctc.wstx.sr.BasicStreamReader
_constructTypeException, _constructUnexpectedInTyped, checkCData, checkKeyword, close, closeCompletely, 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, handleGreedyEntityProblem, handleIncompleteEntityProblem, handleMultiDocStart, handleMultiDocXmlDecl, handleRootElem, handleUndeclaredEntity, hasConfigFlags, hasName, hasNext, hasText, isAttributeSpecified, isCharacters, isEmptyElement, isEndElement, isNamespaceAware, isPropertySupported, isStandalone, isStartElement, isWhiteSpace, next, nextTag, parseQuoted, readCDataSecondary, readCoalescedText, readEndElem, readTextSecondary, require, safeEnsureFinishToken, safeFinishToken, setFeature, setProperty, skipElement, skipEquals, skipWS, standaloneSet, throwNotTextualOrElem, throwUnexpectedEOF, withStartElement
-
Methods inherited from class com.ctc.wstx.sr.StreamScanner
_reportProblem, _reportProblem, closeAllInput, constructFromIOE, constructLimitViolation, constructNullCharException, constructWfcException, ensureInput, expandBy50Pct, expandEntity, fullyResolveEntity, getConfig, getCurrentInput, getCurrentLocation, getIntEntity, 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, reportValidationProblem, reportValidationProblem, reportValidationProblem, reportValidationProblem, resolveCharOnlyEntity, resolveNonCharEntity, resolveSimpleEntity, skipCRLF, skipFullName, throwFromIOE, throwFromStrE, throwInvalidSpace, throwInvalidSpace, throwLazyError, throwNullChar, throwNullParent, throwParseError, throwParseError, throwUnexpectedChar, throwUnexpectedEOB, throwUnexpectedEOF, throwWfcException, tokenTypeDesc, verifyLimit
-
Methods inherited from class com.ctc.wstx.io.WstxInputData
copyBufferStateFrom, findIllegalNameChar, findIllegalNmtokenChar, getCharDesc, isNameChar, isNameChar, isNameStartChar, isNameStartChar, isSpaceChar
-
-
-
-
Field Detail
-
STAX_PROP_ENTITIES
static final java.lang.String STAX_PROP_ENTITIES
- See Also:
- Constant Field Values
-
STAX_PROP_NOTATIONS
static final java.lang.String STAX_PROP_NOTATIONS
- See Also:
- Constant Field Values
-
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.
-
-
Constructor Detail
-
ValidatingStreamReader
private ValidatingStreamReader(InputBootstrapper bs, BranchingReaderSource input, ReaderCreator owner, ReaderConfig cfg, InputElementStack elemStack, boolean forER) throws javax.xml.stream.XMLStreamException
- Throws:
javax.xml.stream.XMLStreamException
-
-
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:
getPropertyin interfacejavax.xml.stream.XMLStreamReader- Overrides:
getPropertyin classBasicStreamReader
-
getProcessedDTD
public java.lang.Object getProcessedDTD()
Description copied from class:BasicStreamReaderNote: DTD-handling sub-classes need to override this method.
- Specified by:
getProcessedDTDin interfaceorg.codehaus.stax2.DTDInfo- Overrides:
getProcessedDTDin classBasicStreamReader
-
getProcessedDTDSchema
public org.codehaus.stax2.validation.DTDValidationSchema getProcessedDTDSchema()
Description copied from class:BasicStreamReaderSub-class will override this method- Specified by:
getProcessedDTDSchemain interfaceorg.codehaus.stax2.DTDInfo- Overrides:
getProcessedDTDSchemain classBasicStreamReader
-
validateAgainst
public org.codehaus.stax2.validation.XMLValidator validateAgainst(org.codehaus.stax2.validation.XMLValidationSchema schema) throws javax.xml.stream.XMLStreamException- Specified by:
validateAgainstin interfaceorg.codehaus.stax2.validation.Validatable- Overrides:
validateAgainstin classBasicStreamReader- 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:
stopValidatingAgainstin interfaceorg.codehaus.stax2.validation.Validatable- Overrides:
stopValidatingAgainstin classBasicStreamReader- 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:
stopValidatingAgainstin interfaceorg.codehaus.stax2.validation.Validatable- Overrides:
stopValidatingAgainstin classBasicStreamReader- Throws:
javax.xml.stream.XMLStreamException
-
setValidationProblemHandler
public org.codehaus.stax2.validation.ValidationProblemHandler setValidationProblemHandler(org.codehaus.stax2.validation.ValidationProblemHandler h)
- Specified by:
setValidationProblemHandlerin interfaceorg.codehaus.stax2.validation.Validatable- Overrides:
setValidationProblemHandlerin classBasicStreamReader
-
finishDTD
protected void finishDTD(boolean copyContents) throws javax.xml.stream.XMLStreamExceptionThis 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:
finishDTDin classBasicStreamReader- 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.XMLStreamExceptionIf there is an error handler established, call it.- Specified by:
reportValidationProblemin interfaceInputProblemReporter- Overrides:
reportValidationProblemin classStreamScanner- Throws:
javax.xml.stream.XMLStreamException
-
initValidation
protected void initValidation() throws javax.xml.stream.XMLStreamExceptionMethod 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:
initValidationin classBasicStreamReader- 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 byfinishDTD, 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.IOExceptionMethod 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.XMLStreamExceptionMethod 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:
reportInvalidContentin classBasicStreamReader- Parameters:
evtType- Type of event that contained unexpected content- Throws:
javax.xml.stream.XMLStreamException
-
-