com.icl.saxon.tree
Class Stripper

java.lang.Object
  |
  +--com.icl.saxon.tree.Stripper
All Implemented Interfaces:
org.xml.sax.ContentHandler, org.xml.sax.ext.LexicalHandler

public class Stripper
extends java.lang.Object
implements org.xml.sax.ContentHandler, org.xml.sax.ext.LexicalHandler

The Stripper class maintains details of which elements need to be stripped. The code is written to act as a SAX filter to do the stripping. It also includes a free-standing method to strip an existing tree.


Constructor Summary
Stripper()
          create a Stripper and initialise variables
 
Method Summary
 void characters(char[] ch, int start, int length)
          Callback interface for SAX: not for application use
 void comment(char[] ch, int start, int length)
          Callback interface for SAX (part of LexicalHandler interface): not for application use
 void endCDATA()
           
 void endDocument()
          Callback interface for SAX: not for application use
 void endDTD()
           
 void endElement(java.lang.String uri, java.lang.String localname, java.lang.String rawname)
          Callback interface for SAX: not for application use
 void endEntity(java.lang.String name)
           
 void endPrefixMapping(java.lang.String prefix)
          Callback interface for SAX: not for application use
 void flush()
          Flush buffer for accumulated character data, suppressing white space if appropriate
 boolean getPreserveAll()
          Return true if all whitespace nodes are to be preserved
 void ignorableWhitespace(char[] ch, int start, int length)
          Callback interface for SAX: not for application use
 boolean isSpacePreserving(java.lang.String uri, java.lang.String localname)
          Decide whether an element is in the set of white-space preserving element types
 void processingInstruction(java.lang.String name, java.lang.String remainder)
          Callback interface for SAX: not for application use
 void setDocumentLocator(org.xml.sax.Locator locator)
          Callback interface for SAX: not for application use
 void setNextHandler(org.xml.sax.ContentHandler handler)
           
 void setPreserveSpace(AnyNameTest any, boolean preserve)
           
 void setPreserveSpace(Name name, boolean preserve)
          Add an element to the list of elements for which white space is preserved / stripped.
 void setPreserveSpace(PrefixTest test, boolean preserve)
           
 void skippedEntity(java.lang.String name)
           
 void startCDATA()
           
 void startDocument()
          Callback interface for SAX: not for application use
 void startDTD(java.lang.String name, java.lang.String publicId, java.lang.String systemId)
           
 void startElement(java.lang.String uri, java.lang.String localname, java.lang.String rawname, org.xml.sax.Attributes atts)
          Callback interface for SAX: not for application use
 void startEntity(java.lang.String name)
           
 void startPrefixMapping(java.lang.String prefix, java.lang.String uri)
          Callback interface for SAX: not for application use
 void strip(DocumentInfo doc)
          Prune the tree.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Stripper

public Stripper()
create a Stripper and initialise variables
Method Detail

setPreserveSpace

public void setPreserveSpace(Name name,
                             boolean preserve)
Add an element to the list of elements for which white space is preserved / stripped.
Parameters:
name - The element name
preserve - true: preserve space for this element;
false: strip space for this element

setPreserveSpace

public void setPreserveSpace(PrefixTest test,
                             boolean preserve)

setPreserveSpace

public void setPreserveSpace(AnyNameTest any,
                             boolean preserve)

isSpacePreserving

public boolean isSpacePreserving(java.lang.String uri,
                                 java.lang.String localname)
Decide whether an element is in the set of white-space preserving element types
Parameters:
uri - The namespace URI of the element name
localname - The local part of the element name
Returns:
true if the element is in the set of white-space preserving element types

getPreserveAll

public boolean getPreserveAll()
Return true if all whitespace nodes are to be preserved

setNextHandler

public void setNextHandler(org.xml.sax.ContentHandler handler)

startDocument

public void startDocument()
                   throws org.xml.sax.SAXException
Callback interface for SAX: not for application use
Specified by:
startDocument in interface org.xml.sax.ContentHandler

endDocument

public void endDocument()
                 throws org.xml.sax.SAXException
Callback interface for SAX: not for application use
Specified by:
endDocument in interface org.xml.sax.ContentHandler

setDocumentLocator

public void setDocumentLocator(org.xml.sax.Locator locator)
Callback interface for SAX: not for application use
Specified by:
setDocumentLocator in interface org.xml.sax.ContentHandler

startPrefixMapping

public void startPrefixMapping(java.lang.String prefix,
                               java.lang.String uri)
                        throws org.xml.sax.SAXException
Callback interface for SAX: not for application use
Specified by:
startPrefixMapping in interface org.xml.sax.ContentHandler

endPrefixMapping

public void endPrefixMapping(java.lang.String prefix)
                      throws org.xml.sax.SAXException
Callback interface for SAX: not for application use
Specified by:
endPrefixMapping in interface org.xml.sax.ContentHandler

startElement

public void startElement(java.lang.String uri,
                         java.lang.String localname,
                         java.lang.String rawname,
                         org.xml.sax.Attributes atts)
                  throws org.xml.sax.SAXException
Callback interface for SAX: not for application use
Specified by:
startElement in interface org.xml.sax.ContentHandler

endElement

public void endElement(java.lang.String uri,
                       java.lang.String localname,
                       java.lang.String rawname)
                throws org.xml.sax.SAXException
Callback interface for SAX: not for application use
Specified by:
endElement in interface org.xml.sax.ContentHandler

characters

public void characters(char[] ch,
                       int start,
                       int length)
                throws org.xml.sax.SAXException
Callback interface for SAX: not for application use
Specified by:
characters in interface org.xml.sax.ContentHandler

ignorableWhitespace

public void ignorableWhitespace(char[] ch,
                                int start,
                                int length)
                         throws org.xml.sax.SAXException
Callback interface for SAX: not for application use
Specified by:
ignorableWhitespace in interface org.xml.sax.ContentHandler

processingInstruction

public void processingInstruction(java.lang.String name,
                                  java.lang.String remainder)
                           throws org.xml.sax.SAXException
Callback interface for SAX: not for application use
Specified by:
processingInstruction in interface org.xml.sax.ContentHandler

comment

public void comment(char[] ch,
                    int start,
                    int length)
             throws org.xml.sax.SAXException
Callback interface for SAX (part of LexicalHandler interface): not for application use
Specified by:
comment in interface org.xml.sax.ext.LexicalHandler

flush

public void flush()
           throws org.xml.sax.SAXException
Flush buffer for accumulated character data, suppressing white space if appropriate

skippedEntity

public void skippedEntity(java.lang.String name)
                   throws org.xml.sax.SAXException
Specified by:
skippedEntity in interface org.xml.sax.ContentHandler

startDTD

public void startDTD(java.lang.String name,
                     java.lang.String publicId,
                     java.lang.String systemId)
              throws org.xml.sax.SAXException
Specified by:
startDTD in interface org.xml.sax.ext.LexicalHandler

endDTD

public void endDTD()
            throws org.xml.sax.SAXException
Specified by:
endDTD in interface org.xml.sax.ext.LexicalHandler

startEntity

public void startEntity(java.lang.String name)
                 throws org.xml.sax.SAXException
Specified by:
startEntity in interface org.xml.sax.ext.LexicalHandler

endEntity

public void endEntity(java.lang.String name)
               throws org.xml.sax.SAXException
Specified by:
endEntity in interface org.xml.sax.ext.LexicalHandler

startCDATA

public void startCDATA()
                throws org.xml.sax.SAXException
Specified by:
startCDATA in interface org.xml.sax.ext.LexicalHandler

endCDATA

public void endCDATA()
              throws org.xml.sax.SAXException
Specified by:
endCDATA in interface org.xml.sax.ext.LexicalHandler

strip

public void strip(DocumentInfo doc)
           throws org.xml.sax.SAXException
Prune the tree. This process strips all whitespace text nodes that need to be stripped. NOTE: normally, when receiving input from a SAX event stream, whitespace nodes are stripped from the event stream before they are added to the tree. There are some circumstances (e.g. embedded stylesheets) where the document must be built before the stripping rules are known, and this method is there to handle this situation.