Package uk.ac.starlink.ttools.copy
Class SquashAttributeHandler
java.lang.Object
uk.ac.starlink.ttools.copy.SquashAttributeHandler
- All Implemented Interfaces:
ContentHandler
,LexicalHandler
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
ConstructorsConstructorDescriptionSquashAttributeHandler
(Writer out, String attName, boolean removeEmptyElement) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionvoid
characters
(char[] ch, int start, int length) void
comment
(char[] ch, int start, int length) void
endCDATA()
void
void
endDTD()
void
endElement
(String namespaceURI, String localName, String qName) void
void
endPrefixMapping
(String prefix) void
flush()
Ensures that any pending output has been written.void
ignorableWhitespace
(char[] ch, int start, int length) void
Writes a string raw.void
processingInstruction
(String target, String data) void
setDocumentLocator
(Locator locator) void
Sets the destination stream.void
skippedEntity
(String name) void
void
void
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
Methods inherited from interface org.xml.sax.ContentHandler
declaration
-
Constructor Details
-
SquashAttributeHandler
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 Details
-
startElement
public void startElement(String namespaceURI, String localName, String qName, Attributes atts) throws SAXException - Specified by:
startElement
in interfaceContentHandler
- Throws:
SAXException
-
endElement
- Specified by:
endElement
in interfaceContentHandler
- Throws:
SAXException
-
characters
- Specified by:
characters
in interfaceContentHandler
- Throws:
SAXException
-
ignorableWhitespace
- Specified by:
ignorableWhitespace
in interfaceContentHandler
- Throws:
SAXException
-
skippedEntity
- Specified by:
skippedEntity
in interfaceContentHandler
- Throws:
SAXException
-
processingInstruction
- Specified by:
processingInstruction
in interfaceContentHandler
- Throws:
SAXException
-
comment
- Specified by:
comment
in interfaceLexicalHandler
- Throws:
SAXException
-
startCDATA
- Specified by:
startCDATA
in interfaceLexicalHandler
- Throws:
SAXException
-
endCDATA
- Specified by:
endCDATA
in interfaceLexicalHandler
- Throws:
SAXException
-
setOutput
Sets the destination stream. This method must be called before the handler is used.- Parameters:
out
- output stream
-
setDocumentLocator
- Specified by:
setDocumentLocator
in interfaceContentHandler
-
startDocument
- Specified by:
startDocument
in interfaceContentHandler
- Throws:
SAXException
-
endDocument
- Specified by:
endDocument
in interfaceContentHandler
- Throws:
SAXException
-
startPrefixMapping
- Specified by:
startPrefixMapping
in interfaceContentHandler
-
endPrefixMapping
- Specified by:
endPrefixMapping
in interfaceContentHandler
-
startDTD
- Specified by:
startDTD
in interfaceLexicalHandler
-
endDTD
public void endDTD()- Specified by:
endDTD
in interfaceLexicalHandler
-
startEntity
- Specified by:
startEntity
in interfaceLexicalHandler
-
endEntity
- Specified by:
endEntity
in interfaceLexicalHandler
-
flush
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
Writes a string raw.- Parameters:
text
- string to write- Throws:
SAXException
-