Class Verifier
- java.lang.Object
-
- com.sun.msv.verifier.AbstractVerifier
-
- com.sun.msv.verifier.Verifier
-
- All Implemented Interfaces:
IDContextProvider2
,IVerifier
,org.iso_relax.verifier.VerifierHandler
,org.relaxng.datatype.ValidationContext
,org.xml.sax.ContentHandler
,org.xml.sax.DTDHandler
- Direct Known Subclasses:
IDConstraintChecker
,TREXIslandVerifier
,TypeDetector
public class Verifier extends AbstractVerifier implements IVerifier
SAX ContentHandler that verifies incoming SAX event stream. This object can be reused to validate multiple documents. Just be careful NOT to use the same object to validate more than one documents at the same time.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static class
Verifier.Context
-
Field Summary
Fields Modifier and Type Field Description private DatatypeRef
attributeType
the same instance is reused by the feedAttribute method to reduce the number of the object creation.private DatatypeRef
characterType
this field is used to receive type information of character literals.protected Acceptor
current
private static int
DEFAULT_PANIC_LEVEL
protected DocumentDeclaration
docDecl
Schema object against which the validation will be doneprivate java.util.Set
duplicateIds
Stores all duplicate id values.static java.lang.String
ERR_DUPLICATE_ID
static java.lang.String
ERR_MISSING_ATTRIBUTE
static java.lang.String
ERR_UNCOMPLETED_CONTENT
static java.lang.String
ERR_UNEXPECTED_ATTRIBUTE
static java.lang.String
ERR_UNEXPECTED_ELEMENT
static java.lang.String
ERR_UNEXPECTED_STARTTAG
static java.lang.String
ERR_UNEXPECTED_TEXT
static java.lang.String
ERR_UNSOLD_IDREF
protected org.xml.sax.ErrorHandler
errorHandler
Error handlerprotected boolean
hadError
This flag will be set to true if an error is foundprivate int
initialPanicLevel
Initial panic level when an error is found.private boolean
isFinished
This flag will be set to true after endDocument method is called.protected int
panicLevel
Panic level.(package private) Verifier.Context
stack
context stackprivate StartTagInfo
sti
An object used to store start tag information.private int
stringCareLevel
current string care level.private java.lang.StringBuffer
text
characters that were read (but not processed)-
Fields inherited from class com.sun.msv.verifier.AbstractVerifier
dummyLocator, idrefs, ids, locator, namespaceSupport, performIDcheck
-
-
Constructor Summary
Constructors Constructor Description Verifier(DocumentDeclaration documentDecl, org.xml.sax.ErrorHandler errorHandler)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
characters(char[] buf, int start, int len)
void
endDocument()
void
endElement(java.lang.String namespaceUri, java.lang.String localName, java.lang.String qName)
protected org.relaxng.datatype.Datatype[]
feedAttribute(Acceptor child, java.lang.String uri, java.lang.String localName, java.lang.String qName, java.lang.String value)
java.lang.Object
getCurrentElementType()
returns current element type.org.xml.sax.ErrorHandler
getErrorHandler()
org.relaxng.datatype.Datatype[]
getLastCharacterType()
gets DataType that validated the last characters.void
ignorableWhitespace(char[] buf, int start, int len)
protected void
init()
boolean
isValid()
checks if the document was valid.static java.lang.String
localizeMessage(java.lang.String propertyName, java.lang.Object[] args)
void
onDuplicateId(java.lang.String id)
this method is called when a duplicate id value is found.protected ValidityViolation
onError(StringRef ref, java.lang.String defaultMsg, ErrorInfo ei)
signals an error.protected ValidityViolation
onError(java.lang.String msg, ErrorInfo ei)
protected void
onNextAcceptorReady(StartTagInfo sti, Acceptor nextAcceptor)
this method is called from the startElement method after the tag name is processed and the child acceptor is created.void
setErrorHandler(org.xml.sax.ErrorHandler handler)
void
setPanicMode(boolean usePanicMode)
Turns on/off the panic mode.void
startDocument()
void
startElement(java.lang.String namespaceUri, java.lang.String localName, java.lang.String qName, org.xml.sax.Attributes atts)
protected void
verifyText()
-
Methods inherited from class com.sun.msv.verifier.AbstractVerifier
endPrefixMapping, getBaseUri, getLocator, isNotation, isUnparsedEntity, notationDecl, onID, processingInstruction, resolveNamespacePrefix, setDocumentLocator, skippedEntity, startPrefixMapping, unparsedEntityDecl
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.xml.sax.ContentHandler
endPrefixMapping, processingInstruction, setDocumentLocator, skippedEntity, startPrefixMapping
-
Methods inherited from interface com.sun.msv.verifier.IVerifier
getLocator
-
-
-
-
Field Detail
-
current
protected Acceptor current
-
stack
Verifier.Context stack
context stack
-
stringCareLevel
private int stringCareLevel
current string care level. See Acceptor.getStringCareLevel
-
text
private java.lang.StringBuffer text
characters that were read (but not processed)
-
errorHandler
protected org.xml.sax.ErrorHandler errorHandler
Error handler
-
hadError
protected boolean hadError
This flag will be set to true if an error is found
-
isFinished
private boolean isFinished
This flag will be set to true after endDocument method is called.
-
sti
private final StartTagInfo sti
An object used to store start tag information. the same object is reused.
-
docDecl
protected final DocumentDeclaration docDecl
Schema object against which the validation will be done
-
panicLevel
protected int panicLevel
Panic level. If the level is non-zero, createChildAcceptors will silently recover from error. This effectively suppresses spurious error messages. This value is set to INITIAL_PANIC_LEVEL when first an error is encountered, and is decreased by successful stepForward and createChildAcceptor. This value is also propagated to child acceptors.
-
initialPanicLevel
private int initialPanicLevel
Initial panic level when an error is found. If this value is bigger, MSV will take more time to recover from errors, Setting this value to 0 means turning the panic mode off entirely.
-
DEFAULT_PANIC_LEVEL
private static final int DEFAULT_PANIC_LEVEL
- See Also:
- Constant Field Values
-
characterType
private final DatatypeRef characterType
this field is used to receive type information of character literals.
-
attributeType
private final DatatypeRef attributeType
the same instance is reused by the feedAttribute method to reduce the number of the object creation.
-
duplicateIds
private java.util.Set duplicateIds
Stores all duplicate id values. Errors are reported at the endDocument method because the onDuplicateId method cannot throw an exception.
-
ERR_UNEXPECTED_TEXT
public static final java.lang.String ERR_UNEXPECTED_TEXT
- See Also:
- Constant Field Values
-
ERR_UNEXPECTED_ATTRIBUTE
public static final java.lang.String ERR_UNEXPECTED_ATTRIBUTE
- See Also:
- Constant Field Values
-
ERR_MISSING_ATTRIBUTE
public static final java.lang.String ERR_MISSING_ATTRIBUTE
- See Also:
- Constant Field Values
-
ERR_UNEXPECTED_STARTTAG
public static final java.lang.String ERR_UNEXPECTED_STARTTAG
- See Also:
- Constant Field Values
-
ERR_UNCOMPLETED_CONTENT
public static final java.lang.String ERR_UNCOMPLETED_CONTENT
- See Also:
- Constant Field Values
-
ERR_UNEXPECTED_ELEMENT
public static final java.lang.String ERR_UNEXPECTED_ELEMENT
- See Also:
- Constant Field Values
-
ERR_UNSOLD_IDREF
public static final java.lang.String ERR_UNSOLD_IDREF
- See Also:
- Constant Field Values
-
ERR_DUPLICATE_ID
public static final java.lang.String ERR_DUPLICATE_ID
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
Verifier
public Verifier(DocumentDeclaration documentDecl, org.xml.sax.ErrorHandler errorHandler)
-
-
Method Detail
-
getErrorHandler
public final org.xml.sax.ErrorHandler getErrorHandler()
- Specified by:
getErrorHandler
in interfaceIVerifier
-
setErrorHandler
public final void setErrorHandler(org.xml.sax.ErrorHandler handler)
- Specified by:
setErrorHandler
in interfaceIVerifier
-
isValid
public final boolean isValid()
Description copied from interface:IVerifier
checks if the document was valid. This method may not be called before verification was completed.
-
setPanicMode
public final void setPanicMode(boolean usePanicMode)
Description copied from interface:IVerifier
Turns on/off the panic mode. Panic mode is on by default. Turning it on is good for general use. It prevents false error messages to appear.However, turning it off is sometimes useful, when you are sure that the structure of the document is almost valid (e.g., validating a document generated by an application or when you are sure about the validity of the structure and only interested in validating datatypes,)
- Specified by:
setPanicMode
in interfaceIVerifier
-
getLastCharacterType
public org.relaxng.datatype.Datatype[] getLastCharacterType()
Description copied from interface:IVerifier
gets DataType that validated the last characters.This method works correctly only when called immediately after startElement and endElement method. When called, this method returns DataType object that validated the last character literals.
For RELAX NG grammar, this method can return an array of length 2 or more. This happens when the last character matches <list> pattern. In that case, each type corresponds to each token (where tokens are the white-space separation of the last characters).
For any other grammar, this method always returns an array of length 1 (or null, if the type assignment failed).
So when you are using VerifierFilter, you can call this method only in your startElement and endElement method.
- Specified by:
getLastCharacterType
in interfaceIVerifier
- Returns:
- null if type-assignment was not possible.
-
verifyText
protected void verifyText() throws org.xml.sax.SAXException
- Throws:
org.xml.sax.SAXException
-
startElement
public void startElement(java.lang.String namespaceUri, java.lang.String localName, java.lang.String qName, org.xml.sax.Attributes atts) throws org.xml.sax.SAXException
- Specified by:
startElement
in interfaceorg.xml.sax.ContentHandler
- Overrides:
startElement
in classAbstractVerifier
- Throws:
org.xml.sax.SAXException
-
onNextAcceptorReady
protected void onNextAcceptorReady(StartTagInfo sti, Acceptor nextAcceptor) throws org.xml.sax.SAXException
this method is called from the startElement method after the tag name is processed and the child acceptor is created.This method is called before the attributes are consumed.
derived class can use this method to do something useful.
- Throws:
org.xml.sax.SAXException
-
feedAttribute
protected org.relaxng.datatype.Datatype[] feedAttribute(Acceptor child, java.lang.String uri, java.lang.String localName, java.lang.String qName, java.lang.String value) throws org.xml.sax.SAXException
- Throws:
org.xml.sax.SAXException
-
endElement
public void endElement(java.lang.String namespaceUri, java.lang.String localName, java.lang.String qName) throws org.xml.sax.SAXException
- Specified by:
endElement
in interfaceorg.xml.sax.ContentHandler
- Overrides:
endElement
in classAbstractVerifier
- Throws:
org.xml.sax.SAXException
-
onError
protected ValidityViolation onError(StringRef ref, java.lang.String defaultMsg, ErrorInfo ei) throws org.xml.sax.SAXException
signals an error. This method can be overrided by the derived class to provide different behavior.- Throws:
org.xml.sax.SAXException
-
onError
protected ValidityViolation onError(java.lang.String msg, ErrorInfo ei) throws org.xml.sax.SAXException
- Throws:
org.xml.sax.SAXException
-
getCurrentElementType
public java.lang.Object getCurrentElementType()
Description copied from interface:IVerifier
returns current element type. Actual java type depends on the implementation. This method works correctly only when called immediately after handling startElement event.- Specified by:
getCurrentElementType
in interfaceIVerifier
- Returns:
- null this method returns null when it doesn't support type-assignment feature, or type-assignment is impossible for the current element (for example due to the ambiguous grammar).
-
characters
public void characters(char[] buf, int start, int len) throws org.xml.sax.SAXException
- Specified by:
characters
in interfaceorg.xml.sax.ContentHandler
- Throws:
org.xml.sax.SAXException
-
ignorableWhitespace
public void ignorableWhitespace(char[] buf, int start, int len) throws org.xml.sax.SAXException
- Specified by:
ignorableWhitespace
in interfaceorg.xml.sax.ContentHandler
- Throws:
org.xml.sax.SAXException
-
init
protected void init()
- Overrides:
init
in classAbstractVerifier
-
startDocument
public void startDocument() throws org.xml.sax.SAXException
- Specified by:
startDocument
in interfaceorg.xml.sax.ContentHandler
- Throws:
org.xml.sax.SAXException
-
endDocument
public void endDocument() throws org.xml.sax.SAXException
- Specified by:
endDocument
in interfaceorg.xml.sax.ContentHandler
- Throws:
org.xml.sax.SAXException
-
onDuplicateId
public void onDuplicateId(java.lang.String id)
Description copied from class:AbstractVerifier
this method is called when a duplicate id value is found.- Specified by:
onDuplicateId
in classAbstractVerifier
-
localizeMessage
public static java.lang.String localizeMessage(java.lang.String propertyName, java.lang.Object[] args)
-
-