Class VerifierFilter
- java.lang.Object
-
- org.xml.sax.helpers.XMLFilterImpl
-
- com.sun.msv.verifier.VerifierFilter
-
- All Implemented Interfaces:
IVerifier,org.iso_relax.verifier.VerifierHandler,ContentHandler,DTDHandler,EntityResolver,ErrorHandler,XMLFilter,XMLReader
public class VerifierFilter extends XMLFilterImpl implements IVerifier
SAX XMLFilter 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.- Author:
- Kohsuke KAWAGUCHI
-
-
Constructor Summary
Constructors Constructor Description VerifierFilter(DocumentDeclaration documentDecl, ErrorHandler errorHandler)VerifierFilter(IVerifier verifier)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidcharacters(char[] ch, int start, int length)voidendDocument()voidendElement(String namespaceURI, String localName, String qName)voidendPrefixMapping(String prefix)ObjectgetCurrentElementType()returns current element type.ErrorHandlergetErrorHandler()org.relaxng.datatype.Datatype[]getLastCharacterType()gets DataType that validated the last characters.LocatorgetLocator()IVerifiergetVerifier()voidignorableWhitespace(char[] ch, int start, int length)booleanisValid()checks if the document was valid.voidprocessingInstruction(String target, String data)voidsetDocumentLocator(Locator locator)voidsetErrorHandler(ErrorHandler handler)voidsetPanicMode(boolean usePanicMode)Turns on/off the panic mode.voidskippedEntity(String name)voidstartDocument()voidstartElement(String namespaceURI, String localName, String qName, Attributes atts)voidstartPrefixMapping(String prefix, String uri)-
Methods inherited from class org.xml.sax.helpers.XMLFilterImpl
error, fatalError, getContentHandler, getDTDHandler, getEntityResolver, getFeature, getParent, getProperty, notationDecl, parse, parse, resolveEntity, setContentHandler, setDTDHandler, setEntityResolver, setFeature, setParent, setProperty, unparsedEntityDecl, warning
-
-
-
-
Constructor Detail
-
VerifierFilter
public VerifierFilter(IVerifier verifier)
- Parameters:
verifier- Verifier object that performs actual validation.
-
VerifierFilter
public VerifierFilter(DocumentDeclaration documentDecl, ErrorHandler errorHandler)
-
-
Method Detail
-
isValid
public boolean isValid()
Description copied from interface:IVerifierchecks if the document was valid. This method may not be called before verification was completed.
-
getCurrentElementType
public Object getCurrentElementType()
Description copied from interface:IVerifierreturns current element type. Actual java type depends on the implementation. This method works correctly only when called immediately after handling startElement event.- Specified by:
getCurrentElementTypein 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).
-
getLastCharacterType
public org.relaxng.datatype.Datatype[] getLastCharacterType()
Description copied from interface:IVerifiergets 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:
getLastCharacterTypein interfaceIVerifier- Returns:
- null if type-assignment was not possible.
-
getLocator
public final Locator getLocator()
- Specified by:
getLocatorin interfaceIVerifier
-
getErrorHandler
public final ErrorHandler getErrorHandler()
- Specified by:
getErrorHandlerin interfaceIVerifier- Specified by:
getErrorHandlerin interfaceXMLReader- Overrides:
getErrorHandlerin classXMLFilterImpl
-
setErrorHandler
public final void setErrorHandler(ErrorHandler handler)
- Specified by:
setErrorHandlerin interfaceIVerifier- Specified by:
setErrorHandlerin interfaceXMLReader- Overrides:
setErrorHandlerin classXMLFilterImpl
-
setPanicMode
public final void setPanicMode(boolean usePanicMode)
Description copied from interface:IVerifierTurns 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:
setPanicModein interfaceIVerifier
-
getVerifier
public IVerifier getVerifier()
-
setDocumentLocator
public void setDocumentLocator(Locator locator)
- Specified by:
setDocumentLocatorin interfaceContentHandler- Overrides:
setDocumentLocatorin classXMLFilterImpl
-
startDocument
public void startDocument() throws SAXException- Specified by:
startDocumentin interfaceContentHandler- Overrides:
startDocumentin classXMLFilterImpl- Throws:
SAXException
-
endDocument
public void endDocument() throws SAXException- Specified by:
endDocumentin interfaceContentHandler- Overrides:
endDocumentin classXMLFilterImpl- Throws:
SAXException
-
startPrefixMapping
public void startPrefixMapping(String prefix, String uri) throws SAXException
- Specified by:
startPrefixMappingin interfaceContentHandler- Overrides:
startPrefixMappingin classXMLFilterImpl- Throws:
SAXException
-
endPrefixMapping
public void endPrefixMapping(String prefix) throws SAXException
- Specified by:
endPrefixMappingin interfaceContentHandler- Overrides:
endPrefixMappingin classXMLFilterImpl- Throws:
SAXException
-
startElement
public void startElement(String namespaceURI, String localName, String qName, Attributes atts) throws SAXException
- Specified by:
startElementin interfaceContentHandler- Overrides:
startElementin classXMLFilterImpl- Throws:
SAXException
-
endElement
public void endElement(String namespaceURI, String localName, String qName) throws SAXException
- Specified by:
endElementin interfaceContentHandler- Overrides:
endElementin classXMLFilterImpl- Throws:
SAXException
-
characters
public void characters(char[] ch, int start, int length) throws SAXException- Specified by:
charactersin interfaceContentHandler- Overrides:
charactersin classXMLFilterImpl- Throws:
SAXException
-
ignorableWhitespace
public void ignorableWhitespace(char[] ch, int start, int length) throws SAXException- Specified by:
ignorableWhitespacein interfaceContentHandler- Overrides:
ignorableWhitespacein classXMLFilterImpl- Throws:
SAXException
-
processingInstruction
public void processingInstruction(String target, String data) throws SAXException
- Specified by:
processingInstructionin interfaceContentHandler- Overrides:
processingInstructionin classXMLFilterImpl- Throws:
SAXException
-
skippedEntity
public void skippedEntity(String name) throws SAXException
- Specified by:
skippedEntityin interfaceContentHandler- Overrides:
skippedEntityin classXMLFilterImpl- Throws:
SAXException
-
-