org.dspace.app.xmlui.objectmanager
Class SAXFilter

java.lang.Object
  extended by org.dspace.app.xmlui.objectmanager.SAXFilter
All Implemented Interfaces:
ContentHandler, LexicalHandler

public class SAXFilter
extends Object
implements ContentHandler, LexicalHandler

This is a Swiss army like SAX Filter, its purpose is to filter out undesirable SAX events from the stream. The primary application of this is for inserting SAX fragment into an existing SAX pipeline, under this scenario you would not want new startDocument or endDocument events interfering with the existing pipeline thus this class can filter those out. The Swiss army part comes in because it's configurable. Instead of defining a static set of events that are filled out by default all events are filled out and must be turned on to allow each type Individually. Primarily you can filter events based upon their type, i.e. start/end elements or start/end documents. However there is one special control, and that is to only allow elements below a minimum level. .

Author:
Scott Phillips

Constructor Summary
SAXFilter(ContentHandler contentHandler, LexicalHandler lexicalHandler, NamespaceSupport namespaces)
          Construct a new SAXFilter such that the allowed events will be routed to the corresponding content and lexical handlers.
 
Method Summary
 SAXFilter allowCDATA()
          Allow CDATA events
 SAXFilter allowCharacters()
          Allow character events
 SAXFilter allowComments()
          Allow comment events
 SAXFilter allowDocumentLocators()
          Allow document locator events
 SAXFilter allowDocuments()
          Allow start/end document events
 SAXFilter allowDTDs()
          Allow DTD events
 SAXFilter allowElements()
          allow start/end element events
 SAXFilter allowElements(int minimumElementLevel)
          Allow start/end element events.
 SAXFilter allowEntities()
          Allow XML entities events
 SAXFilter allowIgnorableWhitespace()
          Allow ignorable whitespace events
 SAXFilter allowPrefixMappings()
          allow start/end prefix mapping events
 SAXFilter allowProcessingInstructions()
          Allow processing instruction events
 SAXFilter allowSkippedEntities()
          Allow start / end events for skipped entities
 void characters(char[] ch, int start, int length)
           
 void comment(char[] ch, int start, int length)
           
 void endCDATA()
           
 void endDocument()
           
 void endDTD()
           
 void endElement(String uri, String localName, String qName)
           
 void endEntity(String name)
           
 void endPrefixMapping(String prefix)
           
 void ignorableWhitespace(char[] ch, int start, int length)
           
 void processingInstruction(String target, String data)
           
 SAXFilter setDefaultNamespace(String uri)
          Add a default namespace is none is provided.
 void setDocumentLocator(Locator locator)
           
 void skippedEntity(String name)
           
 void startCDATA()
           
 void startDocument()
          SAX Content events
 void startDTD(String name, String publicId, String systemId)
          SAX Lexical events
 void startElement(String uri, String localName, String qName, Attributes atts)
           
 void startEntity(String name)
           
 void startPrefixMapping(String prefix, String uri)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SAXFilter

public SAXFilter(ContentHandler contentHandler,
                 LexicalHandler lexicalHandler,
                 NamespaceSupport namespaces)
Construct a new SAXFilter such that the allowed events will be routed to the corresponding content and lexical handlers.

Parameters:
contentHandler - The SAX content handler.
lexicalHandler - The SAX lexical handler.
namespaces - Namespace support which records what prefixes have been defined.
Method Detail

allowDocuments

public SAXFilter allowDocuments()
Allow start/end document events


allowDocumentLocators

public SAXFilter allowDocumentLocators()
Allow document locator events


allowProcessingInstructions

public SAXFilter allowProcessingInstructions()
Allow processing instruction events


allowPrefixMappings

public SAXFilter allowPrefixMappings()
allow start/end prefix mapping events


allowElements

public SAXFilter allowElements()
allow start/end element events


allowElements

public SAXFilter allowElements(int minimumElementLevel)
Allow start/end element events. However only allow those start / end events if they are below the given XML level. I.e. each nested element is a new level.

Parameters:
minimumElementLevel - the minimum level required.
Returns:

allowIgnorableWhitespace

public SAXFilter allowIgnorableWhitespace()
Allow ignorable whitespace events


allowSkippedEntities

public SAXFilter allowSkippedEntities()
Allow start / end events for skipped entities


allowCharacters

public SAXFilter allowCharacters()
Allow character events


allowDTDs

public SAXFilter allowDTDs()
Allow DTD events


allowEntities

public SAXFilter allowEntities()
Allow XML entities events


allowCDATA

public SAXFilter allowCDATA()
Allow CDATA events


allowComments

public SAXFilter allowComments()
Allow comment events


setDefaultNamespace

public SAXFilter setDefaultNamespace(String uri)
Add a default namespace is none is provided. The namespace should have allready been declared (add added to the namespace support object

Parameters:
uri - the default namespace uri.

startDocument

public void startDocument()
                   throws SAXException
SAX Content events

Specified by:
startDocument in interface ContentHandler
Throws:
SAXException

endDocument

public void endDocument()
                 throws SAXException
Specified by:
endDocument in interface ContentHandler
Throws:
SAXException

setDocumentLocator

public void setDocumentLocator(Locator locator)
Specified by:
setDocumentLocator in interface ContentHandler

processingInstruction

public void processingInstruction(String target,
                                  String data)
                           throws SAXException
Specified by:
processingInstruction in interface ContentHandler
Throws:
SAXException

startPrefixMapping

public void startPrefixMapping(String prefix,
                               String uri)
                        throws SAXException
Specified by:
startPrefixMapping in interface ContentHandler
Throws:
SAXException

endPrefixMapping

public void endPrefixMapping(String prefix)
                      throws SAXException
Specified by:
endPrefixMapping in interface ContentHandler
Throws:
SAXException

startElement

public void startElement(String uri,
                         String localName,
                         String qName,
                         Attributes atts)
                  throws SAXException
Specified by:
startElement in interface ContentHandler
Throws:
SAXException

endElement

public void endElement(String uri,
                       String localName,
                       String qName)
                throws SAXException
Specified by:
endElement in interface ContentHandler
Throws:
SAXException

ignorableWhitespace

public void ignorableWhitespace(char[] ch,
                                int start,
                                int length)
                         throws SAXException
Specified by:
ignorableWhitespace in interface ContentHandler
Throws:
SAXException

skippedEntity

public void skippedEntity(String name)
                   throws SAXException
Specified by:
skippedEntity in interface ContentHandler
Throws:
SAXException

characters

public void characters(char[] ch,
                       int start,
                       int length)
                throws SAXException
Specified by:
characters in interface ContentHandler
Throws:
SAXException

startDTD

public void startDTD(String name,
                     String publicId,
                     String systemId)
              throws SAXException
SAX Lexical events

Specified by:
startDTD in interface LexicalHandler
Throws:
SAXException

endDTD

public void endDTD()
            throws SAXException
Specified by:
endDTD in interface LexicalHandler
Throws:
SAXException

startEntity

public void startEntity(String name)
                 throws SAXException
Specified by:
startEntity in interface LexicalHandler
Throws:
SAXException

endEntity

public void endEntity(String name)
               throws SAXException
Specified by:
endEntity in interface LexicalHandler
Throws:
SAXException

startCDATA

public void startCDATA()
                throws SAXException
Specified by:
startCDATA in interface LexicalHandler
Throws:
SAXException

endCDATA

public void endCDATA()
              throws SAXException
Specified by:
endCDATA in interface LexicalHandler
Throws:
SAXException

comment

public void comment(char[] ch,
                    int start,
                    int length)
             throws SAXException
Specified by:
comment in interface LexicalHandler
Throws:
SAXException


Copyright © 2011 DuraSpace. All Rights Reserved.