|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.xml.sax.helpers.XMLFilterImpl
org.randomcoder.content.XHTMLReader
public class XHTMLReader
XMLFilter implementation which filters out dangerous and/or
unwanted markup from the input XML.
This class implements a large subset of XHTML (minus dangerous, deprecated, or otherwise undesirable content). Tag and attribute names are canonicalized, non-semantic markup is converted to semantic, and disallowed elements, their children, and attributes are removed.
Copyright (c) 2006, Craig Condit. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
| Constructor Summary | |
|---|---|
XHTMLReader(XMLReader parent,
Set<String> allowedClasses,
URL baseUrl)
Creates a new XHTMLReader. |
|
| Method Summary | |
|---|---|
void |
characters(char[] ch,
int start,
int length)
Parses character data. |
void |
endDocument()
Marks the end of the current document. |
void |
endElement(String uri,
String localName,
String qName)
Marks the end of the current element. |
void |
endPrefixMapping(String prefix)
Ends the current prefix mapping. |
void |
ignorableWhitespace(char[] ch,
int start,
int length)
Processes ignorable whitespace. |
void |
notationDecl(String name,
String publicId,
String systemId)
Processes a notation declaration. |
void |
processingInstruction(String target,
String data)
Handles processing instructions. |
InputSource |
resolveEntity(String publicId,
String systemId)
Resolves an entity. |
void |
skippedEntity(String name)
Skips an entity. |
void |
startDocument()
Marks the beginning of the current document. |
void |
startElement(String uri,
String localName,
String qName,
Attributes atts)
Marks the start of an element. |
void |
startPrefixMapping(String prefix,
String uri)
Starts mapping a prefix. |
void |
unparsedEntityDecl(String name,
String publicId,
String systemId,
String notationName)
Handles unparsed entity declaractions. |
| Methods inherited from class org.xml.sax.helpers.XMLFilterImpl |
|---|
error, fatalError, getContentHandler, getDTDHandler, getEntityResolver, getErrorHandler, getFeature, getParent, getProperty, parse, parse, setContentHandler, setDocumentLocator, setDTDHandler, setEntityResolver, setErrorHandler, setFeature, setParent, setProperty, warning |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public XHTMLReader(XMLReader parent,
Set<String> allowedClasses,
URL baseUrl)
parent - parent reader to wrapallowedClasses - set of allowed css classesbaseUrl - base URL for links| Method Detail |
|---|
public void startDocument()
throws SAXException
startDocument in interface ContentHandlerstartDocument in class XMLFilterImplSAXException - if an error occurs
public void endDocument()
throws SAXException
endDocument in interface ContentHandlerendDocument in class XMLFilterImplSAXException - if an error occurs
public void startElement(String uri,
String localName,
String qName,
Attributes atts)
throws SAXException
startElement in interface ContentHandlerstartElement in class XMLFilterImpluri - URI of elementlocalName - local partqName - qualified nameatts - list of attributes
SAXException - if an error occurs
public void endElement(String uri,
String localName,
String qName)
throws SAXException
endElement in interface ContentHandlerendElement in class XMLFilterImpluri - URI of the current elementlocalName - local partqName - fully qualified name
SAXException - if an error occurs
public void characters(char[] ch,
int start,
int length)
throws SAXException
characters in interface ContentHandlercharacters in class XMLFilterImplch - character bufferstart - starting offset in bufferlength - number of characters to process
SAXException - if an error occurs
public void ignorableWhitespace(char[] ch,
int start,
int length)
throws SAXException
ignorableWhitespace in interface ContentHandlerignorableWhitespace in class XMLFilterImplch - character buffer to readstart - starting offset in bufferlength - number of characters to read
SAXException - if an error occurs
public void processingInstruction(String target,
String data)
throws SAXException
processingInstruction in interface ContentHandlerprocessingInstruction in class XMLFilterImpltarget - target of processing instructiondata - associated data
SAXException - if an error occurs
public void unparsedEntityDecl(String name,
String publicId,
String systemId,
String notationName)
throws SAXException
unparsedEntityDecl in interface DTDHandlerunparsedEntityDecl in class XMLFilterImplname - name of entitypublicId - public identifiersystemId - system identifiernotationName - notation name
SAXException - if an error occurs
public InputSource resolveEntity(String publicId,
String systemId)
throws SAXException,
IOException
resolveEntity in interface EntityResolverresolveEntity in class XMLFilterImplpublicId - public identifiersystemId - system identifier
SAXException - if an error occurs
IOException
public void skippedEntity(String name)
throws SAXException
skippedEntity in interface ContentHandlerskippedEntity in class XMLFilterImplname - name of entity to skip
SAXException - if an error occurs
public void notationDecl(String name,
String publicId,
String systemId)
throws SAXException
notationDecl in interface DTDHandlernotationDecl in class XMLFilterImplname - notation namepublicId - public identifiersystemId - system identifier
SAXException - if an error occurs
public void startPrefixMapping(String prefix,
String uri)
throws SAXException
startPrefixMapping in interface ContentHandlerstartPrefixMapping in class XMLFilterImplprefix - name of prefix to mapuri - URI of prefix to map
SAXException - if an error occurs
public void endPrefixMapping(String prefix)
throws SAXException
endPrefixMapping in interface ContentHandlerendPrefixMapping in class XMLFilterImplprefix - prefix to be mapped
SAXException - if an error occurs
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||