Package org.xwiki.xml

Class 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:

    
     <p>click <a href="realyLongURL" title="Here">here</a> to view the result</p>
     
    is
    
     <p>ck <a href="realyLongURL" title="Here">here</a> to</p>
     
    Since:
    1.6M2
    Version:
    $Id: b00e780e1f82791ed4c29b805e13282902d16727 $