|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.xml.sax.helpers.XMLFilterImpl
edu.iastate.utils.log.XMLFilterBase
edu.iastate.utils.log.DataUnformatFilter
Filter for removing formatting from data- or field-oriented XML. Code and comments adapted from DataWriter-0.2, written by David Megginson and released into the public domain, without warranty.
This filter removes leading and trailing whitespace from field-oriented XML without mixed content. Note that this class will likely not yield appropriate results for document-oriented XML like XHTML pages, which mix character data and elements together.
DataFormatFilter| Field Summary | |
private static java.lang.Object |
SEEN_DATA
|
private static java.lang.Object |
SEEN_ELEMENT
|
private static java.lang.Object |
SEEN_NOTHING
|
private java.lang.Object |
state
|
private java.util.Stack |
stateStack
|
private java.lang.StringBuffer |
whitespace
|
| Fields inherited from class edu.iastate.utils.log.XMLFilterBase |
EMPTY_ATTS |
| Fields inherited from class org.xml.sax.helpers.XMLFilterImpl |
|
| Constructor Summary | |
DataUnformatFilter()
Create a new filter. |
|
DataUnformatFilter(org.xml.sax.XMLReader xmlreader)
Create a new filter. |
|
| Method Summary | |
void |
characters(char[] ch,
int start,
int length)
Filter a character data event. |
protected void |
clearWhitespace()
Discards saved whitespace. |
protected void |
emitWhitespace()
Passes saved whitespace down the filter chain. |
void |
endElement(java.lang.String uri,
java.lang.String localName,
java.lang.String qName)
Filter an end element event. |
void |
ignorableWhitespace(char[] ch,
int start,
int length)
Filter an ignorable whitespace event. |
private boolean |
isXMLWhitespace(char c)
Returns true if character is XML whitespace. |
void |
processingInstruction(java.lang.String target,
java.lang.String data)
Filter a processing instruction event. |
void |
reset()
Reset the filter so that it can be reused. |
protected void |
saveWhitespace(char[] ch,
int start,
int length)
Saves trailing whitespace. |
void |
startDocument()
Filter a start document event. |
void |
startElement(java.lang.String uri,
java.lang.String localName,
java.lang.String qName,
org.xml.sax.Attributes atts)
Filter a start element event. |
| Methods inherited from class edu.iastate.utils.log.XMLFilterBase |
characters, dataElement, dataElement, dataElement, emptyElement, emptyElement, emptyElement, endElement, endElement, startElement, startElement |
| Methods inherited from class org.xml.sax.helpers.XMLFilterImpl |
endDocument, endPrefixMapping, error, fatalError, getContentHandler, getDTDHandler, getEntityResolver, getErrorHandler, getFeature, getParent, getProperty, notationDecl, parse, parse, resolveEntity, setContentHandler, setDocumentLocator, setDTDHandler, setEntityResolver, setErrorHandler, setFeature, setParent, setProperty, skippedEntity, startPrefixMapping, unparsedEntityDecl, warning |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
private static final java.lang.Object SEEN_NOTHING
private static final java.lang.Object SEEN_ELEMENT
private static final java.lang.Object SEEN_DATA
private java.lang.Object state
private java.util.Stack stateStack
private java.lang.StringBuffer whitespace
| Constructor Detail |
public DataUnformatFilter()
public DataUnformatFilter(org.xml.sax.XMLReader xmlreader)
Use the XMLReader provided as the source of events.
xmlreader - The parent in the filter chain.| Method Detail |
public void reset()
This method is especially useful if the filter failed with an exception the last time through.
public void startDocument()
throws org.xml.sax.SAXException
Reset state and pass the event on for further processing.
com.jivesoftware.sax.SAXException - If a filter
further down the chain raises an exception.
org.xml.sax.SAXExceptioncom.jivesoftware.sax.ContentHandler#startDocument
public void startElement(java.lang.String uri,
java.lang.String localName,
java.lang.String qName,
org.xml.sax.Attributes atts)
throws org.xml.sax.SAXException
uri - The element's Namespace URI.localName - The element's local name.qName - The element's qualified (prefixed) name.atts - The element's attribute list.
com.jivesoftware.sax.SAXException - If a filter
further down the chain raises an exception.
org.xml.sax.SAXExceptioncom.jivesoftware.sax.ContentHandler#startElement
public void endElement(java.lang.String uri,
java.lang.String localName,
java.lang.String qName)
throws org.xml.sax.SAXException
uri - The element's Namespace URI.localName - The element's local name.qName - The element's qualified (prefixed) name.
com.jivesoftware.sax.SAXException - If a filter
further down the chain raises an exception.
org.xml.sax.SAXExceptioncom.jivesoftware.sax.ContentHandler#endElement
public void characters(char[] ch,
int start,
int length)
throws org.xml.sax.SAXException
ch - The characters to write.start - The starting position in the array.length - The number of characters to use.
com.jivesoftware.sax.SAXException - If a filter
further down the chain raises an exception.
org.xml.sax.SAXExceptioncom.jivesoftware.sax.ContentHandler#characters
public void ignorableWhitespace(char[] ch,
int start,
int length)
throws org.xml.sax.SAXException
ch - The array of characters to write.start - The starting position in the array.length - The number of characters to write.
com.jivesoftware.sax.SAXException - If a filter
further down the chain raises an exception.
org.xml.sax.SAXExceptioncom.jivesoftware.sax.ContentHandler#ignorableWhitespace
public void processingInstruction(java.lang.String target,
java.lang.String data)
throws org.xml.sax.SAXException
target - The PI target.data - The PI data.
com.jivesoftware.sax.SAXException - If a filter
further down the chain raises an exception.
org.xml.sax.SAXExceptioncom.jivesoftware.sax.ContentHandler#processingInstruction
protected void saveWhitespace(char[] ch,
int start,
int length)
protected void emitWhitespace()
throws org.xml.sax.SAXException
org.xml.sax.SAXExceptionprotected void clearWhitespace()
private boolean isXMLWhitespace(char c)
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||