vgritsenko 02/03/07 20:28:14 Modified: src/java/org/apache/cocoon/transformation AbstractDOMTransformer.java Log: Rewrite transformer, encapsulate DOMBuilder, but not extend. (It was required to have two setContentHandler methods, which is impossible in Java ;) One was needed for Transformer and another for DOMBuilder.) Revision Changes Path 1.6 +137 -65 xml-cocoon2/src/java/org/apache/cocoon/transformation/AbstractDOMTransformer.java Index: AbstractDOMTransformer.java =================================================================== RCS file: /home/cvs/xml-cocoon2/src/java/org/apache/cocoon/transformation/AbstractDOMTransformer.java,v retrieving revision 1.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- AbstractDOMTransformer.java 22 Feb 2002 07:03:56 -0000 1.5 +++ AbstractDOMTransformer.java 8 Mar 2002 04:28:13 -0000 1.6 @@ -50,22 +50,22 @@ */ package org.apache.cocoon.transformation; -import org.apache.avalon.excalibur.pool.Recyclable; import org.apache.avalon.framework.activity.Disposable; -import org.apache.avalon.framework.component.Component; import org.apache.avalon.framework.component.ComponentManager; import org.apache.avalon.framework.component.Composable; import org.apache.avalon.framework.parameters.Parameters; + +import org.apache.avalon.excalibur.pool.Recyclable; + import org.apache.cocoon.ProcessingException; -import org.apache.cocoon.components.parser.Parser; import org.apache.cocoon.environment.SourceResolver; -import org.apache.cocoon.xml.XMLConsumer; import org.apache.cocoon.xml.dom.DOMBuilder; import org.apache.cocoon.xml.dom.DOMStreamer; + import org.w3c.dom.Document; -import org.xml.sax.ContentHandler; import org.xml.sax.SAXException; -import org.xml.sax.ext.LexicalHandler; +import org.xml.sax.Locator; +import org.xml.sax.Attributes; import java.io.IOException; import java.util.Map; @@ -79,18 +79,30 @@ * * @author <a href="mailto:[EMAIL PROTECTED]">Ross Burton</a> * @author <a href="mailto:[EMAIL PROTECTED]">Bruce G. Robertson</a> - * @version CVS $Id: AbstractDOMTransformer.java,v 1.5 2002/02/22 07:03:56 cziegeler Exp $ + * @author <a href="mailto:[EMAIL PROTECTED]">Vadim Gritsenko</a> + * @version CVS $Id: AbstractDOMTransformer.java,v 1.6 2002/03/08 04:28:13 vgritsenko Exp $ */ -public abstract class AbstractDOMTransformer extends DOMBuilder - implements Transformer, DOMBuilder.Listener, Composable, Disposable,Recyclable { +public abstract class AbstractDOMTransformer extends AbstractTransformer + implements Transformer, DOMBuilder.Listener, Composable, Disposable, Recyclable { - /** The SAX entity resolver */ + /** + * The SAX entity resolver + */ protected SourceResolver resolver; - /** The request object model */ + + /** + * The request object model + */ protected Map objectModel; - /** The URI requested */ + + /** + * The URI requested + */ protected String source; - /** Parameters in the sitemap */ + + /** + * Parameters in the sitemap + */ protected Parameters parameters; /** @@ -98,9 +110,16 @@ */ protected ComponentManager manager; + /** + * The <code>DOMBuilder</code> used to build DOM tree out of + *incoming SAX events. + */ + protected DOMBuilder builder; + + public AbstractDOMTransformer() { super(); - super.listener = this; + this.builder = new DOMBuilder(this); } /** @@ -111,17 +130,6 @@ } /** - * Recycle the component. - */ - public void recycle() { - this.resolver = null; - this.source = null; - this.objectModel = null; - this.parameters = null; - } - - - /** * Set the <code>SourceResolver</code>, objectModel <code>Map</code>, * the source and sitemap <code>Parameters</code> used to process the request. * @@ -129,7 +137,8 @@ * <code>super()</code> and then add your code. */ public void setup(SourceResolver resolver, Map objectModel, String src, Parameters par) - throws ProcessingException, SAXException, IOException { + throws ProcessingException, SAXException, IOException { + this.resolver = resolver; this.objectModel = objectModel; this.source = src; @@ -137,6 +146,26 @@ } /** + * Recycle the component. + */ + public void recycle() { + this.resolver = null; + this.source = null; + this.objectModel = null; + this.parameters = null; + this.builder.recycle(); + } + + /** + * dispose + */ + public void dispose() { + this.builder = null; + this.manager = null; + this.builder = null; + } + + /** * This method is called when the Document is finished. * @param doc The DOM Document object representing this SAX stream * @see org.apache.cocoon.xml.dom.DOMBuilder.Listener @@ -144,7 +173,8 @@ public void notify(Document doc) throws SAXException { // Call the user's transform method Document newdoc = transform(doc); - // Now we stream the DOM tree out + + // Now we stream the resulting DOM tree down the pipe DOMStreamer s = new DOMStreamer(contentHandler, lexicalHandler); s.stream(newdoc); } @@ -154,53 +184,95 @@ * @param doc The DOM Document representing the SAX stream * @returns A DOM Document to stream down the pipeline */ - protected abstract Document transform(Document doc) ; + protected abstract Document transform(Document doc); - /** The <code>ContentHandler</code> receiving SAX events. */ - protected ContentHandler contentHandler; + // + // SAX Methods. Send incoming SAX events to the DOMBuilder. + // - /** The <code>LexicalHandler</code> receiving SAX events. */ - protected LexicalHandler lexicalHandler; + public void setDocumentLocator(Locator locator) { + builder.setDocumentLocator(locator); + } - /** - * Set the <code>XMLConsumer</code> that will receive XML data. - * <br> - * This method will simply call <code>setContentHandler(consumer)</code> - * and <code>setLexicalHandler(consumer)</code>. - */ - public void setConsumer(XMLConsumer consumer) { - this.contentHandler = consumer; - this.lexicalHandler = consumer; + public void startDocument() throws SAXException { + builder.startDocument(); } - /** - * Set the <code>ContentHandler</code> that will receive XML data. - * <br> - * Subclasses may retrieve this <code>ContentHandler</code> instance - * accessing the protected <code>super.contentHandler</code> field. - */ - public void setContentHandler(ContentHandler handler) { - this.contentHandler = handler; + public void endDocument() throws SAXException { + builder.endDocument(); } - /** - * Set the <code>LexicalHandler</code> that will receive XML data. - * <br> - * Subclasses may retrieve this <code>LexicalHandler</code> instance - * accessing the protected <code>super.lexicalHandler</code> field. - * - * @exception IllegalStateException If the <code>LexicalHandler</code> or - * the <code>XMLConsumer</code> were - * already set. - */ - public void setLexicalHandler(LexicalHandler handler) { - this.lexicalHandler = handler; + public void startPrefixMapping(String prefix, String uri) throws SAXException { + builder.startPrefixMapping(prefix, uri); } - /** - * dispose - */ - public void dispose() { + public void endPrefixMapping(String prefix) throws SAXException { + builder.endPrefixMapping(prefix); + } + + public void startElement(String uri, String loc, String raw, Attributes a) + throws SAXException { + builder.startElement(uri, loc, raw, a); + } + + public void endElement(String uri, String loc, String raw) + throws SAXException { + builder.endElement(uri, loc, raw); + } + + public void characters(char c[], int start, int len) + throws SAXException { + builder.characters(c, start, len); + } + + public void ignorableWhitespace(char c[], int start, int len) + throws SAXException { + builder.ignorableWhitespace(c, start, len); + } + + public void processingInstruction(String target, String data) + throws SAXException { + builder.processingInstruction(target, data); + } + + public void skippedEntity(String name) + throws SAXException { + builder.skippedEntity(name); + } + + public void startDTD(String name, String publicId, String systemId) + throws SAXException { + builder.startDTD(name, publicId, systemId); + } + + public void endDTD() + throws SAXException { + builder.endDTD(); + } + + public void startEntity(String name) + throws SAXException { + builder.startEntity(name); + } + + public void endEntity(String name) + throws SAXException { + builder.endEntity(name); + } + + public void startCDATA() + throws SAXException { + builder.startCDATA(); + } + + public void endCDATA() + throws SAXException { + builder.endCDATA(); + } + + public void comment(char ch[], int start, int len) + throws SAXException { + builder.comment(ch, start, len); } }
---------------------------------------------------------------------- In case of troubles, e-mail: [EMAIL PROTECTED] To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]