com.ctc.wstx.msv
Class RelaxNGValidator

java.lang.Object
  extended by org.codehaus.stax2.validation.XMLValidator
      extended by com.ctc.wstx.msv.RelaxNGValidator

public class RelaxNGValidator
extends XMLValidator

Actual non-shareable validator instance, that is bound to an XML document, or document subset.

Some notes about implementation: (a) Some properties of RelaxNG model are used for optimization: for example, since text content in mixed-content models is not really validated for content, we only combine text segments between start and end tags (in any combination) -- full textual content between matching start and end tags is not necessarily collected (or rather, if there are child elements, is NEVER collected).


Field Summary
 
Fields inherited from class org.codehaus.stax2.validation.XMLValidator
CONTENT_ALLOW_ANY_TEXT, CONTENT_ALLOW_NONE, CONTENT_ALLOW_UNDEFINED, CONTENT_ALLOW_VALIDATABLE_TEXT, CONTENT_ALLOW_WS
 
Constructor Summary
RelaxNGValidator(XMLValidationSchema parent, ValidationContext ctxt, com.sun.msv.verifier.regexp.REDocumentDeclaration vgm)
           
 
Method Summary
 java.lang.String getAttributeType(int index)
          Method for getting schema-specified type of an attribute, if information is available.
 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.
 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.
 XMLValidationSchema getSchema()
          Returns the schema instance that created this validator object, if known (and applicable).
 java.lang.String validateAttribute(java.lang.String localName, java.lang.String uri, java.lang.String prefix, char[] valueChars, int valueStart, int 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.).
 java.lang.String validateAttribute(java.lang.String localName, java.lang.String uri, java.lang.String prefix, java.lang.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.).
 int validateElementAndAttributes()
          Method called after calling XMLValidator.validateAttribute(java.lang.String, java.lang.String, java.lang.String, java.lang.String) on all attributes (if any), but before starting to handle element content.
 int validateElementEnd(java.lang.String localName, java.lang.String uri, java.lang.String prefix)
          Method called right after encountering an element close tag.
 void validateElementStart(java.lang.String localName, java.lang.String uri, java.lang.String prefix)
          Method called to update information about the newly encountered (start) element.
 void validateText(char[] cbuf, int textStart, int textEnd, boolean lastTextSegment)
          Method called to validate textual content.
 void validateText(java.lang.String text, boolean lastTextSegment)
          Method called to validate textual content.
 void validationCompleted(boolean 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).
 
Methods inherited from class org.codehaus.stax2.validation.XMLValidator
getSchemaType
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

RelaxNGValidator

public RelaxNGValidator(XMLValidationSchema parent,
                        ValidationContext ctxt,
                        com.sun.msv.verifier.regexp.REDocumentDeclaration vgm)
Method Detail

getSchema

public XMLValidationSchema getSchema()
Description copied from class: XMLValidator
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.

Specified by:
getSchema in class XMLValidator

validateElementStart

public void validateElementStart(java.lang.String localName,
                                 java.lang.String uri,
                                 java.lang.String prefix)
                          throws XMLValidationException
Method called to update information about the newly encountered (start) element. At this point namespace information has been resolved, but no DTD validation has been done. Validator is to do these validations, including checking for attribute value (and existence) compatibility.

Specified by:
validateElementStart in class XMLValidator
Throws:
XMLValidationException

validateAttribute

public java.lang.String validateAttribute(java.lang.String localName,
                                          java.lang.String uri,
                                          java.lang.String prefix,
                                          java.lang.String value)
                                   throws XMLValidationException
Description copied from class: XMLValidator
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.).

Specified by:
validateAttribute in class XMLValidator
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.
Throws:
XMLValidationException

validateAttribute

public java.lang.String validateAttribute(java.lang.String localName,
                                          java.lang.String uri,
                                          java.lang.String prefix,
                                          char[] valueChars,
                                          int valueStart,
                                          int valueEnd)
                                   throws XMLValidationException
Description copied from class: XMLValidator
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.).

Specified by:
validateAttribute in class XMLValidator
valueChars - Character array that contains value (possibly along with some other text)
valueStart - Index of the first character of the value in in valueChars array
valueEnd - Index of the character AFTER the last character; so that the length of the value String is valueEnd - valueStart
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.
Throws:
XMLValidationException

validateElementAndAttributes

public int validateElementAndAttributes()
                                 throws XMLValidationException
Description copied from class: XMLValidator
Method called after calling XMLValidator.validateAttribute(java.lang.String, java.lang.String, java.lang.String, java.lang.String) on all attributes (if any), but before starting to handle element content.

Specified by:
validateElementAndAttributes in class XMLValidator
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.
Throws:
XMLValidationException

validateElementEnd

public int validateElementEnd(java.lang.String localName,
                              java.lang.String uri,
                              java.lang.String prefix)
                       throws XMLValidationException
Description copied from class: XMLValidator
Method called right after encountering an element close tag.

Specified by:
validateElementEnd in class XMLValidator
Returns:
Validation state that should be effective for the parent element state
Throws:
XMLValidationException

validateText

public void validateText(java.lang.String text,
                         boolean lastTextSegment)
                  throws XMLValidationException
Description copied from class: XMLValidator
Method called to validate textual content.

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

Specified by:
validateText in class XMLValidator
Parameters:
text - Text content to validate
lastTextSegment - 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.
Throws:
XMLValidationException

validateText

public void validateText(char[] cbuf,
                         int textStart,
                         int textEnd,
                         boolean lastTextSegment)
                  throws XMLValidationException
Description copied from class: XMLValidator
Method called to validate textual content.

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

Specified by:
validateText in class XMLValidator
Parameters:
cbuf - Character array that contains text content to validate
textStart - Index of the first character of the content to validate
textEnd - Character following the last character of the content to validate (that is, length of content to validate is textEnd - textStart).
lastTextSegment - 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.
Throws:
XMLValidationException

validationCompleted

public void validationCompleted(boolean eod)
                         throws XMLValidationException
Description copied from class: XMLValidator
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).

Specified by:
validationCompleted in class XMLValidator
Parameters:
eod - 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).
Throws:
XMLValidationException

getAttributeType

public java.lang.String getAttributeType(int index)
Description copied from class: XMLValidator
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.

Specified by:
getAttributeType in class XMLValidator

getIdAttrIndex

public int getIdAttrIndex()
Description copied from class: XMLValidator
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.

Specified by:
getIdAttrIndex in class XMLValidator
Returns:
Index of the attribute with type ID, in the current element, if one exists: -1 otherwise

getNotationAttrIndex

public int getNotationAttrIndex()
Description copied from class: XMLValidator
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.

Specified by:
getNotationAttrIndex in class XMLValidator
Returns:
Index of the attribute with type NOTATION, in the current element, if one exists: -1 otherwise