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.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
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 void
characters(char[] ch, int start, int length)
void
comment(char[] ch, int start, int length)
void
endCDATA()
void
endDocument()
void
endDTD()
void
endElement(java.lang.String namespaceURI, java.lang.String localName, java.lang.String qName)
void
endEntity(java.lang.String name)
void
endPrefixMapping(java.lang.String prefix)
void
flush()
Ensures that any pending output has been written.void
ignorableWhitespace(char[] ch, int start, int length)
void
out(java.lang.String text)
Writes a string raw.void
processingInstruction(java.lang.String target, java.lang.String data)
void
setDocumentLocator(org.xml.sax.Locator locator)
void
setOutput(java.io.Writer out)
Sets the destination stream.void
skippedEntity(java.lang.String name)
void
startCDATA()
void
startDocument()
void
startDTD(java.lang.String name, java.lang.String publicId, java.lang.String systemId)
void
startElement(java.lang.String namespaceURI, java.lang.String localName, java.lang.String qName, org.xml.sax.Attributes atts)
void
startEntity(java.lang.String name)
void
startPrefixMapping(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:
startElement
in 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:
endElement
in 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:
characters
in 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:
ignorableWhitespace
in interfaceorg.xml.sax.ContentHandler
- Throws:
org.xml.sax.SAXException
-
skippedEntity
public void skippedEntity(java.lang.String name) throws org.xml.sax.SAXException
- Specified by:
skippedEntity
in 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:
processingInstruction
in 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:
comment
in interfaceorg.xml.sax.ext.LexicalHandler
- Throws:
org.xml.sax.SAXException
-
startCDATA
public void startCDATA() throws org.xml.sax.SAXException
- Specified by:
startCDATA
in interfaceorg.xml.sax.ext.LexicalHandler
- Throws:
org.xml.sax.SAXException
-
endCDATA
public void endCDATA() throws org.xml.sax.SAXException
- Specified by:
endCDATA
in 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:
setDocumentLocator
in interfaceorg.xml.sax.ContentHandler
-
startDocument
public void startDocument() throws org.xml.sax.SAXException
- Specified by:
startDocument
in interfaceorg.xml.sax.ContentHandler
- Throws:
org.xml.sax.SAXException
-
endDocument
public void endDocument() throws org.xml.sax.SAXException
- Specified by:
endDocument
in interfaceorg.xml.sax.ContentHandler
- Throws:
org.xml.sax.SAXException
-
startPrefixMapping
public void startPrefixMapping(java.lang.String prefix, java.lang.String uri)
- Specified by:
startPrefixMapping
in interfaceorg.xml.sax.ContentHandler
-
endPrefixMapping
public void endPrefixMapping(java.lang.String prefix)
- Specified by:
endPrefixMapping
in interfaceorg.xml.sax.ContentHandler
-
startDTD
public void startDTD(java.lang.String name, java.lang.String publicId, java.lang.String systemId)
- Specified by:
startDTD
in interfaceorg.xml.sax.ext.LexicalHandler
-
endDTD
public void endDTD()
- Specified by:
endDTD
in interfaceorg.xml.sax.ext.LexicalHandler
-
startEntity
public void startEntity(java.lang.String name)
- Specified by:
startEntity
in interfaceorg.xml.sax.ext.LexicalHandler
-
endEntity
public void endEntity(java.lang.String name)
- Specified by:
endEntity
in interfaceorg.xml.sax.ext.LexicalHandler
-
flush
public void flush() throws org.xml.sax.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:
org.xml.sax.SAXException
-
out
public void out(java.lang.String text) throws org.xml.sax.SAXException
Writes a string raw.- Parameters:
text
- string to write- Throws:
org.xml.sax.SAXException
-
-