Top Description Fields Constructors Methods
com.ctc.wstx.sr

public Class ValidatingStreamReader

extends TypedStreamReader
Class Inheritance
Imports
java.io.FileNotFoundException, .IOException, java.net.URI, .URISyntaxException, .URL, java.util.*, javax.xml.stream.XMLStreamException, javax.xml.stream.events.NotationDeclaration, org.codehaus.stax2.XMLInputFactory2, org.codehaus.stax2.validation.*, com.ctc.wstx.api.ReaderConfig, com.ctc.wstx.cfg.ErrorConsts, .XmlConsts, com.ctc.wstx.io.*, com.ctc.wstx.dtd.DTDId, .DTDSubset, .DTDValidatorBase, .FullDTDReader, com.ctc.wstx.ent.EntityDecl, com.ctc.wstx.util.URLUtil

Implementation of org.codehaus.stax2.XMLStreamReader2 that builds on TypedStreamReader and adds full DTD-handling including DTD validation
Authors
Tatu Saloranta, Benson Margulies

Field Summary

Modifier and TypeField and Description
pack-priv XMLValidator
mAutoDtdValidator

Validating reader keeps of automatically created DTD-based validator, since its handling may differ from that of application managed validators.

pack-priv DTDValidationSchema
mDTD

Combined DTD set, constructed from parsed internal and external entities (which may have been set via override DTD functionality).

pack-priv boolean
mDtdValidatorSet

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

protected ValidationProblemHandler
mVldProbHandler

Custom validation problem handler, if any.

pack-priv static final String
pack-priv static final String
Inherited from com.ctc.wstx.sr.TypedStreamReader:
_base64Decoder_decoderFactoryMASK_TYPED_ACCESS_ARRAYMASK_TYPED_ACCESS_BINARYMIN_BINARY_CHUNK

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
protected DTDId
protected DTDId
public static ValidatingStreamReader
createValidatingStreamReader(BranchingReaderSource
Input source used to read the XML document.
input
,
ReaderCreator
"Owner" of this reader, factory that created the reader; needed for returning updated symbol table information after parsing.
owner
,
ReaderConfig
Object that contains reader configuration info.
cfg
,
InputBootstrapper
Bootstrapper to use, for reading xml declaration etc.
bs
,
boolean
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)
forER
)

Factory method for constructing readers.

private DTDSubset
private DTDSubset
findDtdExtSubset(String pubId, String sysId, DTDSubset intSubset)

Method called by finishDTD, to locate the specified external DTD subset.

protected void
finishDTD(boolean
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.
copyContents
)

Overrides com.ctc.wstx.sr.BasicStreamReader.finishDTD.

This method gets called to handle remainder of DOCTYPE declaration, essentially the optional internal subset.

public Object
getProcessedDTD()

Overrides com.ctc.wstx.sr.BasicStreamReader.getProcessedDTD.

Implements org.codehaus.stax2.DTDInfo.getProcessedDTD.

Note

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

public DTDValidationSchema
public Object
getProperty(String
The name of the property, may not be null
name
)

Overrides com.ctc.wstx.sr.BasicStreamReader.getProperty.

Implements javax.xml.stream.XMLStreamReader.getProperty.

Get the value of a feature/property from the underlying implementation

protected void
initValidation()

Overrides com.ctc.wstx.sr.BasicStreamReader.initValidation.

Method called right before handling the root element, by the base class.

protected void
reportInvalidContent(int
Type of event that contained unexpected content
evtType
)

Overrides com.ctc.wstx.sr.BasicStreamReader.reportInvalidContent.

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.

public void
private URI
resolveExtSubsetPath(String systemId)

Method called to resolve path to external DTD subset, given system identifier.

public ValidationProblemHandler
setValidationProblemHandler(ValidationProblemHandler
Handler to install, if non null; if null, indicates that the default (implementation-specific) handling should be used
h
)

Overrides com.ctc.wstx.sr.BasicStreamReader.setValidationProblemHandler.

Implements org.codehaus.stax2.validation.Validatable.setValidationProblemHandler.

Method that application can call to define a custom handler for validation problems encountered during validation process.

public XMLValidator
stopValidatingAgainst(XMLValidationSchema schema)

Overrides com.ctc.wstx.sr.BasicStreamReader.stopValidatingAgainst.

Implements org.codehaus.stax2.validation.Validatable.stopValidatingAgainst.

Method that can be called by application to stop validating output against a schema, for which validateAgainst was called earlier.

public XMLValidator
stopValidatingAgainst(XMLValidator validator)

Overrides com.ctc.wstx.sr.BasicStreamReader.stopValidatingAgainst.

Implements org.codehaus.stax2.validation.Validatable.stopValidatingAgainst.

Method that can be called by application to stop validating output using specified validator.

public XMLValidator
validateAgainst(XMLValidationSchema schema)

Overrides com.ctc.wstx.sr.BasicStreamReader.validateAgainst.

Implements org.codehaus.stax2.validation.Validatable.validateAgainst.

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 stopValidatingAgainst.

Inherited from com.ctc.wstx.sr.TypedStreamReader:
_base64Decoder_constructTypeException_decoderFactory_verifyQNamecreateStreamReadergetAttributeAsgetAttributeAsArraygetAttributeAsBinarygetAttributeAsBinarygetAttributeAsBooleangetAttributeAsDecimalgetAttributeAsDoublegetAttributeAsDoubleArraygetAttributeAsFloatgetAttributeAsFloatArraygetAttributeAsIntgetAttributeAsIntArraygetAttributeAsIntegergetAttributeAsLonggetAttributeAsLongArraygetAttributeAsQNamegetAttributeIndexgetElementAsgetElementAsBinarygetElementAsBinarygetElementAsBooleangetElementAsDecimalgetElementAsDoublegetElementAsFloatgetElementAsIntgetElementAsIntegergetElementAsLonggetElementAsQNamereadElementAsArrayreadElementAsBinaryreadElementAsBinaryreadElementAsDoubleArrayreadElementAsFloatArrayreadElementAsIntArrayreadElementAsLongArray

Field Detail

mAutoDtdValidatorback to summary
pack-priv XMLValidator mAutoDtdValidator

Validating reader keeps of automatically created DTD-based validator, since its handling may differ from that of application managed validators.

mDTDback to summary
pack-priv DTDValidationSchema mDTD

Combined DTD set, constructed from parsed internal and external entities (which may have been set via override DTD functionality).

mDtdValidatorSetback to summary
pack-priv boolean mDtdValidatorSet

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

mVldProbHandlerback to summary
protected ValidationProblemHandler mVldProbHandler

Custom validation problem handler, if any.

STAX_PROP_ENTITIESback to summary
pack-priv static final String STAX_PROP_ENTITIES
STAX_PROP_NOTATIONSback to summary
pack-priv static final String STAX_PROP_NOTATIONS

Constructor Detail

ValidatingStreamReaderback to summary
private ValidatingStreamReader(InputBootstrapper bs, BranchingReaderSource input, ReaderCreator owner, ReaderConfig cfg, InputElementStack elemStack, boolean forER) throws XMLStreamException

Method Detail

constructDtdIdback to summary
protected DTDId constructDtdId(String pubId, String sysId) throws IOException
constructDtdIdback to summary
protected DTDId constructDtdId(URI sysId) throws IOException
createValidatingStreamReaderback to summary
public static ValidatingStreamReader createValidatingStreamReader(BranchingReaderSource input, ReaderCreator owner, ReaderConfig cfg, InputBootstrapper bs, boolean forER) throws XMLStreamException

Factory method for constructing readers.

Parameters
input:BranchingReaderSource

Input source used to read the XML document.

owner:ReaderCreator

"Owner" of this reader, factory that created the reader; needed for returning updated symbol table information after parsing.

cfg:ReaderConfig

Object that contains reader configuration info.

bs:InputBootstrapper

Bootstrapper to use, for reading xml declaration etc.

forER:boolean

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)

findCachedSubsetback to summary
private DTDSubset findCachedSubset(DTDId id, DTDSubset intSubset) throws XMLStreamException
findDtdExtSubsetback to summary
private DTDSubset findDtdExtSubset(String pubId, String sysId, DTDSubset intSubset) throws 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.

finishDTDback to summary
protected void finishDTD(boolean copyContents) throws XMLStreamException

Overrides com.ctc.wstx.sr.BasicStreamReader.finishDTD.

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.

Parameters
copyContents:boolean

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.

Annotations
@Override
getProcessedDTDback to summary
public Object getProcessedDTD()

Overrides com.ctc.wstx.sr.BasicStreamReader.getProcessedDTD.

Implements org.codehaus.stax2.DTDInfo.getProcessedDTD.

Doc from com.ctc.wstx.sr.BasicStreamReader.getProcessedDTD.

Note

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

Returns:Object

Doc from org.codehaus.stax2.DTDInfo.getProcessedDTD.

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.

Annotations
@Override
getProcessedDTDSchemaback to summary
public DTDValidationSchema getProcessedDTDSchema()

Overrides com.ctc.wstx.sr.BasicStreamReader.getProcessedDTDSchema.

Implements org.codehaus.stax2.DTDInfo.getProcessedDTDSchema.

Doc from com.ctc.wstx.sr.BasicStreamReader.getProcessedDTDSchema.

Sub-class will override this method

Annotations
@Override
getPropertyback to summary
public Object getProperty(String name)

Overrides com.ctc.wstx.sr.BasicStreamReader.getProperty.

Implements javax.xml.stream.XMLStreamReader.getProperty.

Doc from javax.xml.stream.XMLStreamReader.getProperty.

Get the value of a feature/property from the underlying implementation

Parameters
name:String

The name of the property, may not be null

Returns:Object

The value of the property

Annotations
@Override
initValidationback to summary
protected void initValidation() throws XMLStreamException

Overrides com.ctc.wstx.sr.BasicStreamReader.initValidation.

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)

Annotations
@Override
reportInvalidContentback to summary
protected void reportInvalidContent(int evtType) throws XMLStreamException

Overrides com.ctc.wstx.sr.BasicStreamReader.reportInvalidContent.

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.

Parameters
evtType:int

Doc from com.ctc.wstx.sr.BasicStreamReader.reportInvalidContent.

Type of event that contained unexpected content

Annotations
@Override
reportValidationProblemback to summary
public void reportValidationProblem(XMLValidationProblem prob) throws XMLStreamException

Overrides com.ctc.wstx.sr.StreamScanner.reportValidationProblem.

Implements com.ctc.wstx.sr.InputProblemReporter.reportValidationProblem.

If there is an error handler established, call it.

Annotations
@Override
resolveExtSubsetPathback to summary
private URI resolveExtSubsetPath(String systemId) throws IOException

Method called to resolve path to external DTD subset, given system identifier.

setValidationProblemHandlerback to summary
public ValidationProblemHandler setValidationProblemHandler(ValidationProblemHandler h)

Overrides com.ctc.wstx.sr.BasicStreamReader.setValidationProblemHandler.

Implements org.codehaus.stax2.validation.Validatable.setValidationProblemHandler.

Doc from org.codehaus.stax2.validation.Validatable.setValidationProblemHandler.

Method that application can call to define a custom handler for validation problems encountered during validation process.

Parameters
h:ValidationProblemHandler

Handler to install, if non null; if null, indicates that the default (implementation-specific) handling should be used

Returns:ValidationProblemHandler

Previously set validation problem handler, if any; null if none was set

Annotations
@Override
stopValidatingAgainstback to summary
public XMLValidator stopValidatingAgainst(XMLValidationSchema schema) throws XMLStreamException

Overrides com.ctc.wstx.sr.BasicStreamReader.stopValidatingAgainst.

Implements org.codehaus.stax2.validation.Validatable.stopValidatingAgainst.

Doc from org.codehaus.stax2.validation.Validatable.stopValidatingAgainst.

Method that can be called by application to stop validating output against a schema, for which validateAgainst was called earlier.

Returns:XMLValidator

Validator instance created from the schema that was removed, if one was in use; null if no such schema in use.

Annotations
@Override
stopValidatingAgainstback to summary
public XMLValidator stopValidatingAgainst(XMLValidator validator) throws XMLStreamException

Overrides com.ctc.wstx.sr.BasicStreamReader.stopValidatingAgainst.

Implements org.codehaus.stax2.validation.Validatable.stopValidatingAgainst.

Doc from org.codehaus.stax2.validation.Validatable.stopValidatingAgainst.

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 validateAgainst.

Note

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

Returns:XMLValidator

Validator instance found (ie. argument validator) if it was being used for validating current document; null if not.

Annotations
@Override
validateAgainstback to summary
public XMLValidator validateAgainst(XMLValidationSchema schema) throws XMLStreamException

Overrides com.ctc.wstx.sr.BasicStreamReader.validateAgainst.

Implements org.codehaus.stax2.validation.Validatable.validateAgainst.

Doc from org.codehaus.stax2.validation.Validatable.validateAgainst.

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 stopValidatingAgainst.

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.

Returns:XMLValidator

Validator instance constructed, if validator was added, or null if a validator for the schema has already been constructed.

Annotations
@Override