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. See
http://www.w3.org/TR/html4/struct/text.html#h-9.1 for more details.
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
|
Method Summary |
void |
characters(char[] ch,
int start,
int length)
|
protected void |
cleanExtraWhiteSpaces()
|
void |
comment(char[] ch,
int start,
int length)
|
void |
endCDATA()
|
void |
endElement(String uri,
String localName,
String qName)
|
protected StringBuffer |
getContent()
|
void |
ignorableWhitespace(char[] ch,
int start,
int length)
|
protected boolean |
isSemanticComment(String comment)
We remove spaces around non semantic comments. |
protected void |
sendCharacters(String content)
|
protected void |
sendContent()
|
protected void |
sendPreviousContent(boolean trimTrailing)
|
protected boolean |
shouldRemoveWhiteSpaces()
|
void |
startCDATA()
|
void |
startElement(String uri,
String localName,
String qName,
Attributes atts)
|
protected void |
trimLeadingWhiteSpaces()
|
protected String |
trimLeadingWhiteSpaces(CharSequence content)
|
protected void |
trimTrailingWhiteSpaces()
|
protected String |
trimTrailingWhiteSpaces(CharSequence content)
|
| Methods inherited from class org.xml.sax.helpers.XMLFilterImpl |
endDocument, endPrefixMapping, error, fatalError, getContentHandler, getDTDHandler, getEntityResolver, getErrorHandler, getFeature, getParent, 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)
ignorableWhitespace
public void ignorableWhitespace(char[] ch,
int start,
int length)
throws SAXException
- Specified by:
ignorableWhitespace in interface ContentHandler- Overrides:
ignorableWhitespace in class XMLFilterImpl
- Throws:
SAXException
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()
sendPreviousContent
protected void sendPreviousContent(boolean trimTrailing)
throws SAXException
- Throws:
SAXException
sendContent
protected void sendContent()
throws SAXException
- Throws:
SAXException
sendCharacters
protected void sendCharacters(String content)
throws SAXException
- Throws:
SAXException
cleanExtraWhiteSpaces
protected void cleanExtraWhiteSpaces()
trimLeadingWhiteSpaces
protected void trimLeadingWhiteSpaces()
trimLeadingWhiteSpaces
protected String trimLeadingWhiteSpaces(CharSequence content)
trimTrailingWhiteSpaces
protected void trimTrailingWhiteSpaces()
trimTrailingWhiteSpaces
protected String trimTrailingWhiteSpaces(CharSequence content)
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.