Package org.xwiki.xml
Class ExtractHandler
- java.lang.Object
-
- org.xml.sax.helpers.DefaultHandler
-
- org.xwiki.xml.ExtractHandler
-
- All Implemented Interfaces:
ContentHandler,DTDHandler,EntityResolver,ErrorHandler
public class ExtractHandler extends DefaultHandler
Extracts a well-formed XML fragment by listening to SAX events. The result has the following semantic:
xmlInput.dropAllTags().substring(start, length).unDropAssociatedTags()So basically we would create an instance like
new ExtractHandler(0, 400)in order to obtain an XML fragment with its inner text length of at most 400 characters, starting at position (character) 0 in the source (input) XML's inner text. The ExtractHandler is used in feed plug-in to obtain a preview of an XML (HTML, to be more specific). Another use case could be to paginate an XML source (keeping pages well-formed).As an example, the result of applying an
ExtractHandler(3, 13)to:
is<p>click <a href="realyLongURL" title="Here">here</a> to view the result</p><p>ck <a href="realyLongURL" title="Here">here</a> to</p>- Since:
- 1.6M2
- Version:
- $Id: b00e780e1f82791ed4c29b805e13282902d16727 $
-
-
Constructor Summary
Constructors Constructor Description ExtractHandler(int start, int length)Creates a new instance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidcharacters(char[] ch, int start, int length)voidendDocument()voidendElement(String namespaceURI, String localName, String qName)StringgetResult()booleanisFinished()voidstartDocument()voidstartElement(String namespaceURI, String localName, String qName, Attributes atts)-
Methods inherited from class org.xml.sax.helpers.DefaultHandler
endPrefixMapping, error, fatalError, ignorableWhitespace, notationDecl, processingInstruction, resolveEntity, setDocumentLocator, skippedEntity, startPrefixMapping, unparsedEntityDecl, warning
-
-
-
-
Constructor Detail
-
ExtractHandler
public ExtractHandler(int start, int length) throws SAXExceptionCreates a new instance.- Parameters:
start- The character index from where to start the extraction.length- The number of plain text characters to extract.- Throws:
SAXException- if start is less than zero or length is less than or equal to zero.
-
-
Method Detail
-
getResult
public String getResult()
- Returns:
- The extracted text.
-
isFinished
public boolean isFinished()
- Returns:
- true if the extraction process has succeeded; false if an exception occurred during the process.
-
startDocument
public void startDocument() throws SAXException- Specified by:
startDocumentin interfaceContentHandler- Overrides:
startDocumentin classDefaultHandler- Throws:
SAXException
-
startElement
public void startElement(String namespaceURI, String localName, String qName, Attributes atts) throws SAXException
- Specified by:
startElementin interfaceContentHandler- Overrides:
startElementin classDefaultHandler- Throws:
SAXException
-
characters
public void characters(char[] ch, int start, int length) throws SAXException- Specified by:
charactersin interfaceContentHandler- Overrides:
charactersin classDefaultHandler- Throws:
SAXException
-
endElement
public void endElement(String namespaceURI, String localName, String qName) throws SAXException
- Specified by:
endElementin interfaceContentHandler- Overrides:
endElementin classDefaultHandler- Throws:
SAXException
-
endDocument
public void endDocument() throws SAXException- Specified by:
endDocumentin interfaceContentHandler- Overrides:
endDocumentin classDefaultHandler- Throws:
SAXException
-
-