Package uk.ac.starlink.ttools.copy
Class SquashAttributeHandler
- java.lang.Object
-
- uk.ac.starlink.ttools.copy.SquashAttributeHandler
-
- All Implemented Interfaces:
org.xml.sax.ContentHandler,org.xml.sax.ext.LexicalHandler
public class SquashAttributeHandler extends java.lang.ObjectSAX 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
Constructors Constructor Description SquashAttributeHandler(java.io.Writer out, java.lang.String attName, boolean removeEmptyElement)Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidcharacters(char[] ch, int start, int length)voidcomment(char[] ch, int start, int length)voidendCDATA()voidendDocument()voidendDTD()voidendElement(java.lang.String namespaceURI, java.lang.String localName, java.lang.String qName)voidendEntity(java.lang.String name)voidendPrefixMapping(java.lang.String prefix)voidflush()Ensures that any pending output has been written.voidignorableWhitespace(char[] ch, int start, int length)voidout(java.lang.String text)Writes a string raw.voidprocessingInstruction(java.lang.String target, java.lang.String data)voidsetDocumentLocator(org.xml.sax.Locator locator)voidsetOutput(java.io.Writer out)Sets the destination stream.voidskippedEntity(java.lang.String name)voidstartCDATA()voidstartDocument()voidstartDTD(java.lang.String name, java.lang.String publicId, java.lang.String systemId)voidstartElement(java.lang.String namespaceURI, java.lang.String localName, java.lang.String qName, org.xml.sax.Attributes atts)voidstartEntity(java.lang.String name)voidstartPrefixMapping(java.lang.String prefix, java.lang.String uri)
-
-
-
Constructor Detail
-
SquashAttributeHandler
public SquashAttributeHandler(java.io.Writer out, java.lang.String attName, boolean removeEmptyElement)Constructor.- Parameters:
out- output stream; SAX events are copied as XML text to hereattName- name of attribute on level-0 element to removeremoveEmptyElement- 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(java.lang.String namespaceURI, java.lang.String localName, java.lang.String qName, org.xml.sax.Attributes atts) throws org.xml.sax.SAXException- Specified by:
startElementin interfaceorg.xml.sax.ContentHandler- Throws:
org.xml.sax.SAXException
-
endElement
public void endElement(java.lang.String namespaceURI, java.lang.String localName, java.lang.String qName) throws org.xml.sax.SAXException- Specified by:
endElementin interfaceorg.xml.sax.ContentHandler- Throws:
org.xml.sax.SAXException
-
characters
public void characters(char[] ch, int start, int length) throws org.xml.sax.SAXException- Specified by:
charactersin interfaceorg.xml.sax.ContentHandler- Throws:
org.xml.sax.SAXException
-
ignorableWhitespace
public void ignorableWhitespace(char[] ch, int start, int length) throws org.xml.sax.SAXException- Specified by:
ignorableWhitespacein interfaceorg.xml.sax.ContentHandler- Throws:
org.xml.sax.SAXException
-
skippedEntity
public void skippedEntity(java.lang.String name) throws org.xml.sax.SAXException- Specified by:
skippedEntityin interfaceorg.xml.sax.ContentHandler- Throws:
org.xml.sax.SAXException
-
processingInstruction
public void processingInstruction(java.lang.String target, java.lang.String data) throws org.xml.sax.SAXException- Specified by:
processingInstructionin interfaceorg.xml.sax.ContentHandler- Throws:
org.xml.sax.SAXException
-
comment
public void comment(char[] ch, int start, int length) throws org.xml.sax.SAXException- Specified by:
commentin interfaceorg.xml.sax.ext.LexicalHandler- Throws:
org.xml.sax.SAXException
-
startCDATA
public void startCDATA() throws org.xml.sax.SAXException- Specified by:
startCDATAin interfaceorg.xml.sax.ext.LexicalHandler- Throws:
org.xml.sax.SAXException
-
endCDATA
public void endCDATA() throws org.xml.sax.SAXException- Specified by:
endCDATAin interfaceorg.xml.sax.ext.LexicalHandler- Throws:
org.xml.sax.SAXException
-
setOutput
public void setOutput(java.io.Writer out)
Sets the destination stream. This method must be called before the handler is used.- Parameters:
out- output stream
-
setDocumentLocator
public void setDocumentLocator(org.xml.sax.Locator locator)
- Specified by:
setDocumentLocatorin interfaceorg.xml.sax.ContentHandler
-
startDocument
public void startDocument() throws org.xml.sax.SAXException- Specified by:
startDocumentin interfaceorg.xml.sax.ContentHandler- Throws:
org.xml.sax.SAXException
-
endDocument
public void endDocument() throws org.xml.sax.SAXException- Specified by:
endDocumentin interfaceorg.xml.sax.ContentHandler- Throws:
org.xml.sax.SAXException
-
startPrefixMapping
public void startPrefixMapping(java.lang.String prefix, java.lang.String uri)- Specified by:
startPrefixMappingin interfaceorg.xml.sax.ContentHandler
-
endPrefixMapping
public void endPrefixMapping(java.lang.String prefix)
- Specified by:
endPrefixMappingin interfaceorg.xml.sax.ContentHandler
-
startDTD
public void startDTD(java.lang.String name, java.lang.String publicId, java.lang.String systemId)- Specified by:
startDTDin interfaceorg.xml.sax.ext.LexicalHandler
-
endDTD
public void endDTD()
- Specified by:
endDTDin interfaceorg.xml.sax.ext.LexicalHandler
-
startEntity
public void startEntity(java.lang.String name)
- Specified by:
startEntityin interfaceorg.xml.sax.ext.LexicalHandler
-
endEntity
public void endEntity(java.lang.String name)
- Specified by:
endEntityin interfaceorg.xml.sax.ext.LexicalHandler
-
flush
public void flush() throws org.xml.sax.SAXExceptionEnsures 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:
org.xml.sax.SAXException
-
out
public void out(java.lang.String text) throws org.xml.sax.SAXExceptionWrites a string raw.- Parameters:
text- string to write- Throws:
org.xml.sax.SAXException
-
-