uk.ac.starlink.ttools.copy
Class SquashAttributeHandler

java.lang.Object
  extended by uk.ac.starlink.ttools.copy.SquashAttributeHandler
All Implemented Interfaces:
ContentHandler, LexicalHandler

public class SquashAttributeHandler
extends Object

SAX content handler which mostly copies events to text, but eliminates a given attribute from the root element.

Since:
19 Nov 2012
Author:
Mark Taylor

Constructor Summary
SquashAttributeHandler(Writer out, String attName, boolean removeEmptyElement)
          Constructor.
 
Method Summary
 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 namespaceURI, String localName, String qName)
           
 void endEntity(String name)
           
 void endPrefixMapping(String prefix)
           
 void flush()
          Ensures that any pending output has been written.
 void ignorableWhitespace(char[] ch, int start, int length)
           
 void out(String text)
          Writes a string raw.
 void processingInstruction(String target, String data)
           
 void setDocumentLocator(Locator locator)
           
 void setOutput(Writer out)
          Sets the destination stream.
 void skippedEntity(String name)
           
 void startCDATA()
           
 void startDocument()
           
 void startDTD(String name, String publicId, String systemId)
           
 void startElement(String namespaceURI, 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

SquashAttributeHandler

public SquashAttributeHandler(Writer out,
                              String attName,
                              boolean removeEmptyElement)
Constructor.

Parameters:
out - output stream; SAX events are copied as XML text to here
attName - name of attribute on level-0 element to remove
removeEmptyElement - if true, then if removing the named attribute from the level-0 element results in an element with no interesting content and no other attributes, the element itself is removed from the output
Method Detail

startElement

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

endElement

public void endElement(String namespaceURI,
                       String localName,
                       String qName)
                throws SAXException
Specified by:
endElement 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

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

processingInstruction

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

comment

public void comment(char[] ch,
                    int start,
                    int length)
             throws SAXException
Specified by:
comment 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

setOutput

public void setOutput(Writer out)
Sets the destination stream. This method must be called before the handler is used.

Parameters:
out - output stream

setDocumentLocator

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

startDocument

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

endDocument

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

startPrefixMapping

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

endPrefixMapping

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

startDTD

public void startDTD(String name,
                     String publicId,
                     String systemId)
Specified by:
startDTD in interface LexicalHandler

endDTD

public void endDTD()
Specified by:
endDTD in interface LexicalHandler

startEntity

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

endEntity

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

flush

public void flush()
           throws SAXException
Ensures that any pending output has been written. If other classes wish to write directly to this writer's destination stream, they must call this method first.

Throws:
SAXException

out

public void out(String text)
         throws SAXException
Writes a string raw.

Parameters:
text - string to write
Throws:
SAXException


Copyright © 2015 Central Laboratory of the Research Councils. All Rights Reserved.