org.wikimodel.wem.xhtml.filter
Class XHTMLWhitespaceXMLFilter
java.lang.Object
org.xml.sax.helpers.XMLFilterImpl
org.wikimodel.wem.xhtml.filter.DefaultXMLFilter
org.wikimodel.wem.xhtml.filter.XHTMLWhitespaceXMLFilter
- All Implemented Interfaces:
- ContentHandler, DTDHandler, EntityResolver, ErrorHandler, LexicalHandler, XMLFilter, XMLReader
public class XHTMLWhitespaceXMLFilter
- extends DefaultXMLFilter
Removes non-semantic whitespaces in XML elements.
Possible use cases:
- UC1:
<tag1>(sp)(sp)one(sp)(sp)two(sp)(sp)</tag1> becomes <tag1>one(sp)two</tag1>
- UC2:
<tag1>(sp)(sp)one(sp)(sp)two(sp)(sp)<tag2>three</tag2></tag1> becomes <tag1>one(sp)two(sp)<tag2>three</tag2></tag1>
- UC3:
<tag1>(\n\r\t)one(\n\r\t)two(\n\r\t)</tag1> becomes <tag1>one(sp)two</tag1>
- UC4:
</tag1>(sp)(sp)(\n\r\t)<tag2> (where tag1 and tag2 are not both block elements) becomes </tag1> <tag2>. If tag1 and tag2 are block elements all spaces are removed
- UC5:
<![CDATA[(\n\r\t)(sp)(sp)one(sp)(sp)(\n\r\t)]]> is left untouched
- UC6:
<pre>(\n\r\t)(sp)(sp)one(sp)(sp)(\n\r\t)</pre> is left untouched
- UC7:
<tag1>(sp)(sp)one(sp)(sp)<!--comment-->(sp)(sp)two(sp)(sp)</tag1> becomes <tag1>one<!--comment-->two</tag1>
- UC8:
</tag1>(sp)(sp)one(sp)(sp)</tag2> becomes </tag1>(sp)one</tag2>
- UC9: Comments which have a meaning for the XHTML parser do not have spaces removed in the content preceding them
- Author:
- vmassol
| Methods inherited from class org.xml.sax.helpers.XMLFilterImpl |
endDocument, endPrefixMapping, error, fatalError, getContentHandler, getDTDHandler, getEntityResolver, getErrorHandler, getFeature, getParent, ignorableWhitespace, notationDecl, parse, processingInstruction, resolveEntity, setContentHandler, setDocumentLocator, setDTDHandler, setEntityResolver, setErrorHandler, setFeature, setParent, skippedEntity, startDocument, startPrefixMapping, unparsedEntityDecl, warning |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
XHTMLWhitespaceXMLFilter
public XHTMLWhitespaceXMLFilter()
XHTMLWhitespaceXMLFilter
public XHTMLWhitespaceXMLFilter(XMLReader reader)
characters
public void characters(char[] ch,
int start,
int length)
throws SAXException
- Specified by:
characters in interface ContentHandler- Overrides:
characters in class XMLFilterImpl
- Throws:
SAXException
startElement
public void startElement(String uri,
String localName,
String qName,
Attributes atts)
throws SAXException
- Specified by:
startElement in interface ContentHandler- Overrides:
startElement in class XMLFilterImpl
- Throws:
SAXException
endElement
public void endElement(String uri,
String localName,
String qName)
throws SAXException
- Specified by:
endElement in interface ContentHandler- Overrides:
endElement in class XMLFilterImpl
- Throws:
SAXException
startCDATA
public void startCDATA()
throws SAXException
- Specified by:
startCDATA in interface LexicalHandler- Overrides:
startCDATA in class DefaultXMLFilter
- Throws:
SAXException
endCDATA
public void endCDATA()
throws SAXException
- Specified by:
endCDATA in interface LexicalHandler- Overrides:
endCDATA in class DefaultXMLFilter
- Throws:
SAXException
comment
public void comment(char[] ch,
int start,
int length)
throws SAXException
- Specified by:
comment in interface LexicalHandler- Overrides:
comment in class DefaultXMLFilter
- Throws:
SAXException
shouldRemoveWhiteSpaces
protected boolean shouldRemoveWhiteSpaces()
sendCharacters
protected void sendCharacters()
throws SAXException
- Throws:
SAXException
cleanExtraWhiteSpaces
protected void cleanExtraWhiteSpaces()
trimLeadingWhiteSpaces
protected void trimLeadingWhiteSpaces()
trimTrailingWhiteSpaces
protected void trimTrailingWhiteSpaces()
getContent
protected StringBuffer getContent()
isSemanticComment
protected boolean isSemanticComment(String comment)
- We remove spaces around non semantic comments.
- Parameters:
comment - the comment to evaluate
- Returns:
- true if the comment is a semantic one
Copyright © 2005-2009. All Rights Reserved.