com.simonstl.gorille
Class CharRulesFilter

java.lang.Object
  |
  +--org.xml.sax.helpers.XMLFilterImpl
        |
        +--com.simonstl.gorille.CharRulesFilter
All Implemented Interfaces:
org.xml.sax.ContentHandler, org.xml.sax.DTDHandler, org.xml.sax.EntityResolver, org.xml.sax.ErrorHandler, org.xml.sax.XMLFilter, org.xml.sax.XMLReader

public class CharRulesFilter
extends org.xml.sax.helpers.XMLFilterImpl

A SAX filter which tests information against the XML character rules. This code has not been well-tested, as SAX parsers perform such testing in advance of the information reaching this filter. This filter is intended as a demonstration of how such layering might work if parsers outsourced that work, and also as a tool for checking SAX events generated internally by programs before passing them to other processors.

Version:
0.01 5 January 2002
Author:
Simon St.Laurent

Field Summary
static int ERROR
           
protected  int errorHandling
           
static int FATAL_ERROR
           
protected  org.xml.sax.Locator locator
           
protected  CharRules rules
           
protected  boolean verbose
           
static int WARNING
           
 
Constructor Summary
CharRulesFilter()
          An empty constructor that requires the use of setParent before starting I don't think this works.
CharRulesFilter(org.xml.sax.XMLReader parent)
          A constructor that takes the parser which will feed it SAX events
 
Method Summary
 void characters(char[] ch, int start, int length)
          Filter a character data event.
 void endDocument()
          Filter an end document event.
 void endElement(java.lang.String uri, java.lang.String localName, java.lang.String qName)
          Filter an end element event.
 void endPrefixMapping(java.lang.String prefix)
          Filter an end Namespace prefix mapping event.
 boolean getFeature(java.lang.String name)
          Look up the value of a feature.
 java.lang.Object getProperty(java.lang.String name)
          Look up the value of a property.
 CharRules getRules()
          in case you ever need to get the rules out of the tester
 void ignorableWhitespace(char[] ch, int start, int length)
          Filter an ignorable whitespace event.
 void notationDecl(java.lang.String name, java.lang.String publicId, java.lang.String systemId)
          Filter a notation declaration event.
 void processingInstruction(java.lang.String target, java.lang.String data)
          Filter a processing instruction event.
protected  void reportError(org.xml.sax.SAXParseException e)
           
 void setDocumentLocator(org.xml.sax.Locator _locator)
          Filter a new document locator event.
 void setErrorType(int _errorHandling)
          sets up error-handling.
 void setFeature(java.lang.String name, boolean value)
          Set the value of a feature.
 void setProperty(java.lang.String name, java.lang.Object value)
          Set the value of a property.
 void setRules(CharRules newRules)
          sets up the rules, read in from a config file by CharRulesLoader or otherwise concocted in Java using the CharRules class.
 void setVerbose(boolean _verbose)
          Sets whether the filter should report errors to the command-line.
 void skippedEntity(java.lang.String name)
          Filter a skipped entity event.
 void startDocument()
          Filter a start document event.
 void startElement(java.lang.String uri, java.lang.String localName, java.lang.String qName, org.xml.sax.Attributes atts)
          Filter a start element event.
 void startPrefixMapping(java.lang.String prefix, java.lang.String uri)
          Filter a start Namespace prefix mapping event.
 void unparsedEntityDecl(java.lang.String name, java.lang.String publicId, java.lang.String systemId, java.lang.String notationName)
          Filter an unparsed entity declaration event.
 
Methods inherited from class org.xml.sax.helpers.XMLFilterImpl
error, fatalError, getContentHandler, getDTDHandler, getEntityResolver, getErrorHandler, getParent, parse, parse, resolveEntity, setContentHandler, setDTDHandler, setEntityResolver, setErrorHandler, setParent, warning
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

FATAL_ERROR

public static final int FATAL_ERROR

ERROR

public static final int ERROR

WARNING

public static final int WARNING

rules

protected CharRules rules

errorHandling

protected int errorHandling

locator

protected org.xml.sax.Locator locator

verbose

protected boolean verbose
Constructor Detail

CharRulesFilter

public CharRulesFilter()
An empty constructor that requires the use of setParent before starting I don't think this works.

CharRulesFilter

public CharRulesFilter(org.xml.sax.XMLReader parent)
A constructor that takes the parser which will feed it SAX events
Method Detail

setFeature

public void setFeature(java.lang.String name,
                       boolean value)
                throws org.xml.sax.SAXNotRecognizedException,
                       org.xml.sax.SAXNotSupportedException
Set the value of a feature.
Overrides:
setFeature in class org.xml.sax.helpers.XMLFilterImpl
Parameters:
name - The feature name.
value - The requested feature value.
Throws:
org.xml.sax.SAXNotRecognizedException - If the feature value can't be assigned or retrieved from the parent.
org.xml.sax.SAXNotSupportedException - When the parent recognizes the feature name but cannot set the requested value.
See Also:
XMLReader.setFeature(java.lang.String, boolean)

getFeature

public boolean getFeature(java.lang.String name)
                   throws org.xml.sax.SAXNotRecognizedException,
                          org.xml.sax.SAXNotSupportedException
Look up the value of a feature.
Overrides:
getFeature in class org.xml.sax.helpers.XMLFilterImpl
Parameters:
name - The feature name.
Returns:
The current value of the feature.
Throws:
org.xml.sax.SAXNotRecognizedException - If the feature value can't be assigned or retrieved from the parent.
org.xml.sax.SAXNotSupportedException - When the parent recognizes the feature name but cannot determine its value at this time.
See Also:
XMLReader.getFeature(java.lang.String)

setProperty

public void setProperty(java.lang.String name,
                        java.lang.Object value)
                 throws org.xml.sax.SAXNotRecognizedException,
                        org.xml.sax.SAXNotSupportedException
Set the value of a property.
Overrides:
setProperty in class org.xml.sax.helpers.XMLFilterImpl
Parameters:
name - The property name.
value - The requested property value.
Throws:
org.xml.sax.SAXNotRecognizedException - If the property value can't be assigned or retrieved from the parent.
org.xml.sax.SAXNotSupportedException - When the parent recognizes the property name but cannot set the requested value.
See Also:
XMLReader.setProperty(java.lang.String, java.lang.Object)

getProperty

public java.lang.Object getProperty(java.lang.String name)
                             throws org.xml.sax.SAXNotRecognizedException,
                                    org.xml.sax.SAXNotSupportedException
Look up the value of a property.
Overrides:
getProperty in class org.xml.sax.helpers.XMLFilterImpl
Parameters:
name - The property name.
Returns:
The current value of the property.
Throws:
org.xml.sax.SAXNotRecognizedException - If the property value can't be assigned or retrieved from the parent.
org.xml.sax.SAXNotSupportedException - When the parent recognizes the property name but cannot determine its value at this time.
See Also:
XMLReader.setFeature(java.lang.String, boolean)

setRules

public void setRules(CharRules newRules)
sets up the rules, read in from a config file by CharRulesLoader or otherwise concocted in Java using the CharRules class.
Parameters:
newRules - the set of rules the class will apply to content

setVerbose

public void setVerbose(boolean _verbose)
Sets whether the filter should report errors to the command-line. False by default.

setErrorType

public void setErrorType(int _errorHandling)
sets up error-handling. By default, character errors are fatal errors, but that may not always be appropriate.
Parameters:
_ErrorHandling - the set of rules the class will apply to content

getRules

public CharRules getRules()
in case you ever need to get the rules out of the tester

reportError

protected void reportError(org.xml.sax.SAXParseException e)

setDocumentLocator

public void setDocumentLocator(org.xml.sax.Locator _locator)
Filter a new document locator event. Using setDocumentLocator is necessary if you want to know where an illegal character was encountered.
Overrides:
setDocumentLocator in class org.xml.sax.helpers.XMLFilterImpl
Parameters:
locator - The document locator.

notationDecl

public void notationDecl(java.lang.String name,
                         java.lang.String publicId,
                         java.lang.String systemId)
                  throws org.xml.sax.SAXException
Filter a notation declaration event.
Overrides:
notationDecl in class org.xml.sax.helpers.XMLFilterImpl
Parameters:
name - The notation name.
publicId - The notation's public identifier, or null.
systemId - The notation's system identifier, or null.
Throws:
org.xml.sax.SAXException - The client may throw an exception during processing.

unparsedEntityDecl

public void unparsedEntityDecl(java.lang.String name,
                               java.lang.String publicId,
                               java.lang.String systemId,
                               java.lang.String notationName)
                        throws org.xml.sax.SAXException
Filter an unparsed entity declaration event.
Overrides:
unparsedEntityDecl in class org.xml.sax.helpers.XMLFilterImpl
Parameters:
name - The entity name.
publicId - The entity's public identifier, or null.
systemId - The entity's system identifier, or null.
notationName - The name of the associated notation.
Throws:
org.xml.sax.SAXException - The client may throw an exception during processing.

startDocument

public void startDocument()
                   throws org.xml.sax.SAXException
Filter a start document event.
Overrides:
startDocument in class org.xml.sax.helpers.XMLFilterImpl
Throws:
org.xml.sax.SAXException - The client may throw an exception during processing.

endDocument

public void endDocument()
                 throws org.xml.sax.SAXException
Filter an end document event.
Overrides:
endDocument in class org.xml.sax.helpers.XMLFilterImpl
Throws:
org.xml.sax.SAXException - The client may throw an exception during processing.

startPrefixMapping

public void startPrefixMapping(java.lang.String prefix,
                               java.lang.String uri)
                        throws org.xml.sax.SAXException
Filter a start Namespace prefix mapping event.
Overrides:
startPrefixMapping in class org.xml.sax.helpers.XMLFilterImpl
Parameters:
prefix - The Namespace prefix.
uri - The Namespace URI.
Throws:
org.xml.sax.SAXException - The client may throw an exception during processing.

endPrefixMapping

public void endPrefixMapping(java.lang.String prefix)
                      throws org.xml.sax.SAXException
Filter an end Namespace prefix mapping event.
Overrides:
endPrefixMapping in class org.xml.sax.helpers.XMLFilterImpl
Parameters:
prefix - The Namespace prefix.
Throws:
org.xml.sax.SAXException - The client may throw an exception during processing.

startElement

public void startElement(java.lang.String uri,
                         java.lang.String localName,
                         java.lang.String qName,
                         org.xml.sax.Attributes atts)
                  throws org.xml.sax.SAXException
Filter a start element event.
Overrides:
startElement in class org.xml.sax.helpers.XMLFilterImpl
Parameters:
uri - The element's Namespace URI, or the empty string.
localName - The element's local name, or the empty string.
qName - The element's qualified (prefixed) name, or the empty string.
atts - The element's attributes.
Throws:
org.xml.sax.SAXException - The client may throw an exception during processing.

endElement

public void endElement(java.lang.String uri,
                       java.lang.String localName,
                       java.lang.String qName)
                throws org.xml.sax.SAXException
Filter an end element event.
Overrides:
endElement in class org.xml.sax.helpers.XMLFilterImpl
Parameters:
uri - The element's Namespace URI, or the empty string.
localName - The element's local name, or the empty string.
qName - The element's qualified (prefixed) name, or the empty string.
Throws:
org.xml.sax.SAXException - The client may throw an exception during processing.

characters

public void characters(char[] ch,
                       int start,
                       int length)
                throws org.xml.sax.SAXException
Filter a character data event.
Overrides:
characters in class org.xml.sax.helpers.XMLFilterImpl
Parameters:
ch - An array of characters.
start - The starting position in the array.
length - The number of characters to use from the array.
Throws:
org.xml.sax.SAXException - The client may throw an exception during processing.

ignorableWhitespace

public void ignorableWhitespace(char[] ch,
                                int start,
                                int length)
                         throws org.xml.sax.SAXException
Filter an ignorable whitespace event.
Overrides:
ignorableWhitespace in class org.xml.sax.helpers.XMLFilterImpl
Parameters:
ch - An array of characters.
start - The starting position in the array.
length - The number of characters to use from the array.
Throws:
org.xml.sax.SAXException - The client may throw an exception during processing.

processingInstruction

public void processingInstruction(java.lang.String target,
                                  java.lang.String data)
                           throws org.xml.sax.SAXException
Filter a processing instruction event.
Overrides:
processingInstruction in class org.xml.sax.helpers.XMLFilterImpl
Parameters:
target - The processing instruction target.
data - The text following the target.
Throws:
org.xml.sax.SAXException - The client may throw an exception during processing.

skippedEntity

public void skippedEntity(java.lang.String name)
                   throws org.xml.sax.SAXException
Filter a skipped entity event.
Overrides:
skippedEntity in class org.xml.sax.helpers.XMLFilterImpl
Parameters:
name - The name of the skipped entity.
Throws:
org.xml.sax.SAXException - The client may throw an exception during processing.