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. 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()
           
protected  boolean isSemanticComment(String comment)
          We remove spaces around non semantic comments.
protected  void sendCharacters()
           
protected  boolean shouldRemoveWhiteSpaces()
           
 void startCDATA()
           
 void startElement(String uri, String localName, String qName, Attributes atts)
           
protected  void trimLeadingWhiteSpaces()
           
protected  void trimTrailingWhiteSpaces()
           
 
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, 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
 

Constructor Detail

XHTMLWhitespaceXMLFilter

public XHTMLWhitespaceXMLFilter()

XHTMLWhitespaceXMLFilter

public XHTMLWhitespaceXMLFilter(XMLReader reader)
Method Detail

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.