package textbender.g.xml.sax.helpers; // Copyright 2005-2006, Michael Allan. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Textbender Software"), to deal in the Textbender Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicence, and/or sell copies of the Textbender Software, and to permit persons to whom the Textbender Software is furnished to do so, subject to the following conditions: The preceding copyright notice and this permission notice shall be included in all copies or substantial portions of the Textbender Software. THE TEXTBENDER SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE TEXTBENDER SOFTWARE OR THE USE OR OTHER DEALINGS IN THE TEXTBENDER SOFTWARE. import org.xml.sax.*; import org.xml.sax.ext.LexicalHandler; import org.xml.sax.helpers.XMLFilterImpl; import textbender.g.xml.sax.*; /** XMLFilterImpl extension. * Adds a passthrough field as a convenience for passing events to underlying handlers. *
* Also adds support for lexical events. It follows the same pattern as for content events. * In the base implementation (this class) events are passed unfiltered * to the underlying content handler (which is assumed to be a LexicalHandler). * Subclasses may modify this behaviour, to do the actual filtering. *
*/ public class XMLFilterImplX extends XMLFilterImpl implements XMLFilterCH, LexicalHandler { /** Passes events through to the XMLFilterImpl implementation, * which passes them to the attached handler, unmodified. * This is the same for an XMLFilterImpl subclass as invoking super.event(), * but it will work for sub-subclasses too, and sub-sub-subclasses, and so on. [And so will super.event(), so this is pointless. FIX.] */ protected final ContentHandlerL passthrough = new ContentHandlerL() // FIX to pass all XMLFilterCH methods, up and down { // - C o n t e n t - H a n d l e r -------------------------------------- public void characters( char[] ch, int start, int length ) throws SAXException { XMLFilterImplX.super.characters( ch, start, length ); } public void endDocument() throws SAXException { XMLFilterImplX.super.endDocument(); } public void endElement( String uri, String localName, String qName ) throws SAXException { XMLFilterImplX.super.endElement( uri, localName, qName ); } public void endPrefixMapping( String prefix ) throws SAXException { XMLFilterImplX.super.endPrefixMapping( prefix ); } public void ignorableWhitespace( char[] ch, int start, int length ) throws SAXException { XMLFilterImplX.super.ignorableWhitespace( ch, start, length ); } public void processingInstruction( String target, String data ) throws SAXException { XMLFilterImplX.super.processingInstruction( target, data ); } public void setDocumentLocator( Locator locator ) { XMLFilterImplX.super.setDocumentLocator( locator ); } public void skippedEntity( String name ) throws SAXException { XMLFilterImplX.super.skippedEntity( name ); } public void startDocument() throws SAXException { XMLFilterImplX.super.startDocument(); } public void startElement( String uri, String localName, String qName, Attributes atts ) throws SAXException { XMLFilterImplX.super.startElement( uri, localName, qName, atts ); } public void startPrefixMapping( String prefix, String uri ) throws SAXException { XMLFilterImplX.super.startPrefixMapping( prefix, uri ); } // - L e x i c a l - H a n d l e r ---------------------------------------------------- public void comment( char[] ch, int start, int length ) throws SAXException { LexicalHandler handler = (LexicalHandler)getContentHandler(); if( handler != null ) handler.comment( ch, start, length ); } public void endCDATA() throws SAXException { LexicalHandler handler = (LexicalHandler)getContentHandler(); if( handler != null ) handler.endCDATA(); } public void endDTD() throws SAXException { LexicalHandler handler = (LexicalHandler)getContentHandler(); if( handler != null ) handler.endDTD(); } public void endEntity( String name ) throws SAXException { LexicalHandler handler = (LexicalHandler)getContentHandler(); if( handler != null ) handler.endEntity( name ); } public void startCDATA() throws SAXException { LexicalHandler handler = (LexicalHandler)getContentHandler(); if( handler != null ) handler.startCDATA(); } public void startDTD( String name, String publicId, String systemId ) throws SAXException { LexicalHandler handler = (LexicalHandler)getContentHandler(); if( handler != null ) handler.startDTD( name, publicId, systemId ); } public void startEntity( String name ) throws SAXException { LexicalHandler handler = (LexicalHandler)getContentHandler(); if( handler != null ) handler.startEntity( name ); } }; // - L e x i c a l - H a n d l e r ---------------------------------------------------- public void comment( char[] ch, int start, int length ) throws SAXException { passthrough.comment( ch, start, length ); } public void endCDATA() throws SAXException { passthrough.endCDATA(); } public void endDTD() throws SAXException { passthrough.endDTD(); } public void endEntity( String name ) throws SAXException { passthrough.endEntity( name ); } public void startCDATA() throws SAXException { passthrough.startCDATA(); } public void startDTD( String name, String publicId, String systemId ) throws SAXException { passthrough.startDTD( name, publicId, systemId ); } public void startEntity( String name ) throws SAXException { passthrough.startEntity( name ); } }