org.wikimodel.wem.xhtml.filter
Class XHTMLWhitespaceXMLFilter

java.lang.Object
  extended by org.xml.sax.helpers.XMLFilterImpl
      extended by org.wikimodel.wem.xhtml.filter.DefaultXMLFilter
          extended by 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:

Author:
vmassol

Field Summary
 
Fields inherited from class org.wikimodel.wem.xhtml.filter.DefaultXMLFilter
SAX_LEXICAL_HANDLER_PROPERTY
 
Constructor Summary
XHTMLWhitespaceXMLFilter()
           
XHTMLWhitespaceXMLFilter(XMLReader reader)
           
 
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.wikimodel.wem.xhtml.filter.DefaultXMLFilter
endDTD, endEntity, getProperty, parse, setProperty, startDTD, startEntity
 
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
 

Constructor Detail

XHTMLWhitespaceXMLFilter

public XHTMLWhitespaceXMLFilter()

XHTMLWhitespaceXMLFilter

public XHTMLWhitespaceXMLFilter(XMLReader reader)
Method Detail

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.