Top Description Fields Constructors Methods
org.codehaus.stax2.validation

public abstract Class XMLValidator

extends Object
Class Inheritance
Known Direct Subclasses
org.codehaus.stax2.validation.ValidatorPair
Imports
javax.xml.stream.XMLStreamException

Class that defines interface that individual (possibly) stateful validator instances have to implement, and that both javax.xml.stream.XMLStreamReader and javax.xml.stream.XMLStreamWriter instances can call to validate xml documents.

Validator instances are created from and by non-stateful XMLValidationSchema instances. A new validator instance has to be created for each document read or written, ie. can not be shared or reused, unlike schema instances which can be.

Field Summary

Modifier and TypeField and Description
public static final int
CONTENT_ALLOW_ANY_TEXT

This value indicates that any textual content (plain PCTEXT) is allowed, and that validator is not going to do any validation for it.

public static final int
CONTENT_ALLOW_NONE

This value indicates that no content whatsoever is legal within current context, that is, where the only legal content to follow is the closing end tag -- not even comments or processing instructions are allowed.

public static final int
CONTENT_ALLOW_UNDEFINED

This value is a placeholder that should never be returned by validators, but that can be used internally as an uninitialized value.

public static final int
CONTENT_ALLOW_VALIDATABLE_TEXT

This value indicates that textual content is allowed, but that the validator needs to be called to let it do actual content-based validation.

public static final int
CONTENT_ALLOW_WS

This value indicates that only white space text content is allowed, not other kinds of text.

public static final int
CONTENT_ALLOW_WS_NONSTRICT

This value is similar to CONTENT_ALLOW_WS_NONSTRICT, but only used for content typing purposes, not for validation.

Constructor Summary

AccessConstructor and Description
protected

Method Summary

Modifier and TypeMethod and Description
public abstract String
getAttributeType(int index)

Method for getting schema-specified type of an attribute, if information is available.

public abstract int

Returns:

Index of the attribute with type ID, in the current element, if one exists: -1 otherwise
getIdAttrIndex
()

Method for finding out the index of the attribute that is of type ID; derived from DTD, W4C Schema, or some other validation source.

public abstract int

Returns:

Index of the attribute with type NOTATION, in the current element, if one exists: -1 otherwise
getNotationAttrIndex
()

Method for finding out the index of the attribute (collected using the attribute collector; having DTD/Schema-derived info in same order) that is of type NOTATION.

public abstract XMLValidationSchema
getSchema()

Returns the schema instance that created this validator object, if known (and applicable).

public String

Returns:

One of external schema identifier values (such as XMLValidationSchema#SCHEMA_ID_DTD).
getSchemaType
()

Returns type of schema that was used to construct this validator instance.

public abstract String

Returns:

Null, if the passed value is fine as is; or a String, if it needs to be replaced. In latter case, caller will replace the value before passing it to other validators. Also, if the attribute value is accessible via caller (as is the case for stream readers), caller should return this value, instead of the original one.
validateAttribute
(String localName, String uri, String prefix, String value)

Callback method called on validator to give it a chance to validate the value of an attribute, as well as to normalize its value if appropriate (remove leading/trailing/intervening white space for certain token types etc.).

public abstract String

Returns:

Null, if the passed value is fine as is; or a String, if it needs to be replaced. In latter case, caller will replace the value before passing it to other validators. Also, if the attribute value is accessible via caller (as is the case for stream readers), caller should return this value, instead of the original one.
validateAttribute
(String localName, String uri, String prefix, char[]
Character array that contains value (possibly along with some other text)
valueChars
,
int
Index of the first character of the value in in valueChars array
valueStart
,
int
Index of the character AFTER the last character; so that the length of the value String is valueEnd - valueStart
valueEnd
)

Callback method called on validator to give it a chance to validate the value of an attribute, as well as to normalize its value if appropriate (remove leading/trailing/intervening white space for certain token types etc.).

public abstract int

Returns:

One of CONTENT_ALLOW_ constants, to indicate what kind of textual content is allowed at the scope returned to after the element has closed.
validateElementAndAttributes
()

Method called after calling validateAttribute on all attributes (if any), but before starting to handle element content.

public abstract int

Returns:

One of CONTENT_ALLOW_ constants, to indicate what kind of textual content is allowed at the scope returned to after the element has closed.
validateElementEnd
(String localName, String uri, String prefix)

Method called right after encountering an element close tag.

public abstract void
validateElementStart(String localName, String uri, String prefix)

public abstract void
validateText(String
Text content to validate
text
,
boolean
Whether this text content is the last text segment before a close element; true if it is, false if it is not, or no determination can be made. Can be used for optimizing validation -- if this is true, no text needs to be buffered since no more will be sent before the current element closes.
lastTextSegment
)

Method called to validate textual content.

public abstract void
validateText(char[]
Character array that contains text content to validate
cbuf
,
int
Index of the first character of the content to validate
textStart
,
int
Character following the last character of the content to validate (that is, length of content to validate is textEnd - textStart).
textEnd
,
boolean
Whether this text content is the last text segment before a close element; true if it is, false if it is not, or no determination can be made. Can be used for optimizing validation -- if this is true, no text needs to be buffered since no more will be sent before the current element closes.
lastTextSegment
)

Method called to validate textual content.

public abstract void
validationCompleted(boolean
Flag that indicates whether this method was called by the context due to the end of the stream (true); or by an application requesting end of validation (false).
eod
)

Method called when the validation is completed; either due to the input stream ending, or due to an explicit 'stop validation' request by the application (via context object).

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

CONTENT_ALLOW_ANY_TEXTback to summary
public static final int CONTENT_ALLOW_ANY_TEXT

This value indicates that any textual content (plain PCTEXT) is allowed, and that validator is not going to do any validation for it. It will, however, need to be called with respect to element events.

CONTENT_ALLOW_NONEback to summary
public static final int CONTENT_ALLOW_NONE

This value indicates that no content whatsoever is legal within current context, that is, where the only legal content to follow is the closing end tag -- not even comments or processing instructions are allowed. This is the case for example for elements that DTD defines to have EMPTY content model.

CONTENT_ALLOW_UNDEFINEDback to summary
public static final int CONTENT_ALLOW_UNDEFINED

This value is a placeholder that should never be returned by validators, but that can be used internally as an uninitialized value.

CONTENT_ALLOW_VALIDATABLE_TEXTback to summary
public static final int CONTENT_ALLOW_VALIDATABLE_TEXT

This value indicates that textual content is allowed, but that the validator needs to be called to let it do actual content-based validation. Other event types are ok, and elements will need to be validated by the validator as well.

CONTENT_ALLOW_WSback to summary
public static final int CONTENT_ALLOW_WS

This value indicates that only white space text content is allowed, not other kinds of text. Other non-text events may be allowed; validator will deal with element validation. Value also indicates that if non-white space text content is encountered, a validation problem is reported

CONTENT_ALLOW_WS_NONSTRICTback to summary
public static final int CONTENT_ALLOW_WS_NONSTRICT

This value is similar to CONTENT_ALLOW_WS_NONSTRICT, but only used for content typing purposes, not for validation. This means that if non-white space text content is encountered, no problem is reported.

This value is currently only used with DTD processors, when in typing (non-validating) mode.

Since
3.0

Constructor Detail

XMLValidatorback to summary
protected XMLValidator()

Method Detail

getAttributeTypeback to summary
public abstract String getAttributeType(int index)

Method for getting schema-specified type of an attribute, if information is available. If not, validators can return null to explicitly indicate no information was available.

getIdAttrIndexback to summary
public abstract int getIdAttrIndex()

Method for finding out the index of the attribute that is of type ID; derived from DTD, W4C Schema, or some other validation source. Usually schemas explicitly specifies that at most one attribute can have this type for any element.

Returns:int

Index of the attribute with type ID, in the current element, if one exists: -1 otherwise

getNotationAttrIndexback to summary
public abstract int getNotationAttrIndex()

Method for finding out the index of the attribute (collected using the attribute collector; having DTD/Schema-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.

Returns:int

Index of the attribute with type NOTATION, in the current element, if one exists: -1 otherwise

getSchemaback to summary
public abstract XMLValidationSchema getSchema()

Returns the schema instance that created this validator object, if known (and applicable). May return null for some instances: specifically, ValidatorPair will return null since it 'contains' multiple validators and generally does not have just one parent or owner schema.

getSchemaTypeback to summary
public String getSchemaType()

Returns type of schema that was used to construct this validator instance.

Returns:String

One of external schema identifier values (such as XMLValidationSchema#SCHEMA_ID_DTD).

validateAttributeback to summary
public abstract String validateAttribute(String localName, String uri, String prefix, String value) throws XMLStreamException

Callback method called on validator to give it a chance to validate the value of an attribute, as well as to normalize its value if appropriate (remove leading/trailing/intervening white space for certain token types etc.).

Returns:String

Null, if the passed value is fine as is; or a String, if it needs to be replaced. In latter case, caller will replace the value before passing it to other validators. Also, if the attribute value is accessible via caller (as is the case for stream readers), caller should return this value, instead of the original one.

validateAttributeback to summary
public abstract String validateAttribute(String localName, String uri, String prefix, char[] valueChars, int valueStart, int valueEnd) throws XMLStreamException

Callback method called on validator to give it a chance to validate the value of an attribute, as well as to normalize its value if appropriate (remove leading/trailing/intervening white space for certain token types etc.).

Parameters
valueChars:char[]

Character array that contains value (possibly along with some other text)

valueStart:int

Index of the first character of the value in in valueChars array

valueEnd:int

Index of the character AFTER the last character; so that the length of the value String is valueEnd - valueStart

Returns:String

Null, if the passed value is fine as is; or a String, if it needs to be replaced. In latter case, caller will replace the value before passing it to other validators. Also, if the attribute value is accessible via caller (as is the case for stream readers), caller should return this value, instead of the original one.

validateElementAndAttributesback to summary
public abstract int validateElementAndAttributes() throws XMLStreamException

Method called after calling validateAttribute on all attributes (if any), but before starting to handle element content.

Returns:int

One of CONTENT_ALLOW_ constants, to indicate what kind of textual content is allowed at the scope returned to after the element has closed.

validateElementEndback to summary
public abstract int validateElementEnd(String localName, String uri, String prefix) throws XMLStreamException

Method called right after encountering an element close tag.

Returns:int

One of CONTENT_ALLOW_ constants, to indicate what kind of textual content is allowed at the scope returned to after the element has closed.

validateElementStartback to summary
public abstract void validateElementStart(String localName, String uri, String prefix) throws XMLStreamException
validateTextback to summary
public abstract void validateText(String text, boolean lastTextSegment) throws XMLStreamException

Method called to validate textual content.

Note

this method is only guaranteed to be called when validateElementAndAttributes() for the currently open element returned CONTENT_ALLOW_VALIDATABLE_TEXT (or, in case of mixed content, validateElementEnd, for the last enclosed element). Otherwise, validator context may choose not to call the method as an optimization.

Parameters
text:String

Text content to validate

lastTextSegment:boolean

Whether this text content is the last text segment before a close element; true if it is, false if it is not, or no determination can be made. Can be used for optimizing validation -- if this is true, no text needs to be buffered since no more will be sent before the current element closes.

validateTextback to summary
public abstract void validateText(char[] cbuf, int textStart, int textEnd, boolean lastTextSegment) throws XMLStreamException

Method called to validate textual content.

Note

this method is only guaranteed to be called when validateElementAndAttributes() for the currently open element returned CONTENT_ALLOW_VALIDATABLE_TEXT (or, in case of mixed content, validateElementEnd, for the last enclosed element). Otherwise, validator context may choose not to call the method as an optimization.

Parameters
cbuf:char[]

Character array that contains text content to validate

textStart:int

Index of the first character of the content to validate

textEnd:int

Character following the last character of the content to validate (that is, length of content to validate is textEnd - textStart).

lastTextSegment:boolean

Whether this text content is the last text segment before a close element; true if it is, false if it is not, or no determination can be made. Can be used for optimizing validation -- if this is true, no text needs to be buffered since no more will be sent before the current element closes.

validationCompletedback to summary
public abstract void validationCompleted(boolean eod) throws XMLStreamException

Method called when the validation is completed; either due to the input stream ending, or due to an explicit 'stop validation' request by the application (via context object).

Parameters
eod:boolean

Flag that indicates whether this method was called by the context due to the end of the stream (true); or by an application requesting end of validation (false).