cziegeler 2002/12/04 03:06:44 Modified: src/java/org/apache/cocoon/components/source/impl SitemapSource.java src/java/org/apache/cocoon/transformation TraxTransformer.java src/webapp/WEB-INF cocoon.xconf Added: src/java/org/apache/cocoon/components/source/impl SitemapSourceFactory.java Removed: src/java/org/apache/cocoon/components/source/impl CocoonSourceFactory.java Log: Cleaning up code a little bit Revision Changes Path 1.27 +38 -34 xml-cocoon2/src/java/org/apache/cocoon/components/source/impl/SitemapSource.java Index: SitemapSource.java =================================================================== RCS file: /home/cvs/xml-cocoon2/src/java/org/apache/cocoon/components/source/impl/SitemapSource.java,v retrieving revision 1.26 retrieving revision 1.27 diff -u -r1.26 -r1.27 --- SitemapSource.java 4 Dec 2002 09:48:40 -0000 1.26 +++ SitemapSource.java 4 Dec 2002 11:06:44 -0000 1.27 @@ -50,17 +50,10 @@ */ package org.apache.cocoon.components.source.impl; -import org.apache.excalibur.source.Recyclable; -import org.apache.excalibur.source.Source; -import org.apache.excalibur.source.SourceException; -import org.apache.excalibur.source.SourceNotFoundException; -import org.apache.excalibur.source.SourceValidity; -import org.apache.excalibur.source.impl.validity.AggregatedValidity; - import org.apache.avalon.excalibur.xml.XMLizable; - import org.apache.avalon.framework.component.ComponentException; import org.apache.avalon.framework.component.ComponentManager; +import org.apache.avalon.framework.logger.AbstractLogEnabled; import org.apache.avalon.framework.logger.Logger; import org.apache.cocoon.Processor; import org.apache.cocoon.ResourceNotFoundException; @@ -69,18 +62,21 @@ import org.apache.cocoon.components.pipeline.ProcessingPipeline; import org.apache.cocoon.environment.Environment; import org.apache.cocoon.environment.ObjectModelHelper; -import org.apache.cocoon.environment.Request; import org.apache.cocoon.environment.wrapper.EnvironmentWrapper; -import org.apache.cocoon.xml.AbstractXMLConsumer; import org.apache.cocoon.xml.ContentHandlerWrapper; import org.apache.cocoon.xml.XMLConsumer; +import org.apache.excalibur.source.Recyclable; +import org.apache.excalibur.source.Source; +import org.apache.excalibur.source.SourceException; +import org.apache.excalibur.source.SourceNotFoundException; +import org.apache.excalibur.source.SourceValidity; +import org.apache.excalibur.source.impl.validity.AggregatedValidity; import org.xml.sax.Attributes; import org.xml.sax.ContentHandler; import org.xml.sax.InputSource; import org.xml.sax.Locator; import org.xml.sax.SAXException; import org.xml.sax.ext.LexicalHandler; - import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; @@ -90,13 +86,14 @@ import java.util.Map; /** - * Description of a source which is defined by a pipeline. + * Implementation of a {@link Source} that gets its content + * by invoking a pipeline. * * @author <a href="mailto:[EMAIL PROTECTED]">Carsten Ziegeler</a> * @version CVS $Id$ */ public final class SitemapSource -extends AbstractXMLConsumer +extends AbstractLogEnabled implements Source, XMLizable, Recyclable { /** validities for the internal pipeline */ @@ -145,9 +142,9 @@ * Construct a new object */ public SitemapSource(ComponentManager manager, - String uri, - Map parameters, - Logger logger) + String uri, + Map parameters, + Logger logger) throws MalformedURLException { Environment env = CocoonComponentManager.getCurrentEnvironment(); @@ -183,7 +180,7 @@ this.prefix = null; this.processor = CocoonComponentManager.getCurrentProcessor(); } else { - throw new MalformedURLException("Malformed cocoon URI."); + throw new MalformedURLException("Malformed cocoon URI: " + uri); } // create the queryString (if available) @@ -195,6 +192,7 @@ } else if (position > 0) { uri = uri.substring(position); } + this.uri = uri; // build the request uri which is relative to the context String requestURI = (this.prefix == null ? env.getURIPrefix() + uri : uri); @@ -204,14 +202,18 @@ "cocoon://" + requestURI : "cocoon://" + requestURI + "?" + queryString; - this.environment = new EnvironmentWrapper(env, requestURI, queryString, logger, manager, rawMode); + // create environment... + this.environment = new EnvironmentWrapper(env, requestURI, + queryString, logger, manager, rawMode); + // ...and put information passed from the parent request to the internal request if ( null != parameters ) { this.environment.getObjectModel().put(ObjectModelHelper.PARENT_CONTEXT, parameters); } else { this.environment.getObjectModel().remove(ObjectModelHelper.PARENT_CONTEXT); } - this.uri = uri; - this.discardValidity(); + + // initialize + this.init(); } /** @@ -310,9 +312,15 @@ * and content length. */ public void discardValidity() { - reset(); - try { + this.reset(); + this.init(); + } + /** + * Initialize + */ + protected void init() { + try { this.processKey = CocoonComponentManager.startProcessing(this.environment); this.environment.setURI(this.prefix, this.uri); this.processingPipeline = this.processor.processInternal(this.environment); @@ -345,16 +353,6 @@ } /** - * Return a new <code>InputSource</code> object - */ - public InputSource getInputSource() - throws IOException, SourceException { - InputSource newObject = new InputSource(this.getInputStream()); - newObject.setSystemId(this.systemId); - return newObject; - } - - /** * Stream content to the content handler */ public void toSAX(ContentHandler contentHandler) @@ -403,6 +401,9 @@ } } + /** + * Reset everything + */ private void reset() { if (this.processingPipeline != null) this.processingPipeline.release(); if (this.processKey != null) { @@ -420,8 +421,11 @@ this.pipelineProcessor = null; } + /** + * Recyclable + */ public void recycle() { - reset(); + this.reset(); } /** 1.1 xml-cocoon2/src/java/org/apache/cocoon/components/source/impl/SitemapSourceFactory.java Index: SitemapSourceFactory.java =================================================================== /* ============================================================================ The Apache Software License, Version 1.1 ============================================================================ Copyright (C) 1999-2002 The Apache Software Foundation. All rights reserved. Redistribution and use in source and binary forms, with or without modifica- tion, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. 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. 3. The end-user documentation included with the redistribution, if any, must include the following acknowledgment: "This product includes software developed by the Apache Software Foundation (http://www.apache.org/)." Alternately, this acknowledgment may appear in the software itself, if and wherever such third-party acknowledgments normally appear. 4. The names "Apache Cocoon" and "Apache Software Foundation" must not be used to endorse or promote products derived from this software without prior written permission. For written permission, please contact [EMAIL PROTECTED] 5. Products derived from this software may not be called "Apache", nor may "Apache" appear in their name, without prior written permission of the Apache Software Foundation. THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED 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 APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- DING, 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. This software consists of voluntary contributions made by many individuals on behalf of the Apache Software Foundation and was originally created by Stefano Mazzocchi <[EMAIL PROTECTED]>. For more information on the Apache Software Foundation, please see <http://www.apache.org/>. */ package org.apache.cocoon.components.source.impl; import java.io.IOException; import java.net.MalformedURLException; import java.util.Map; import org.apache.avalon.framework.component.ComponentManager; import org.apache.avalon.framework.component.Composable; import org.apache.avalon.framework.logger.AbstractLogEnabled; import org.apache.avalon.framework.thread.ThreadSafe; import org.apache.excalibur.source.Source; import org.apache.excalibur.source.SourceFactory; /** * This class implements the cocoon: protocol. * It cannot be used like other source factories * as it needs the current <code>Sitemap</code> as input. * * @author <a href="mailto:[EMAIL PROTECTED]">Carsten Ziegeler</a> * @version CVS $Id: CocoonSourceFactory.java,v 1.3 2002/08/08 02:10:40 vgritsenko Exp $ */ public final class SitemapSourceFactory extends AbstractLogEnabled implements SourceFactory, ThreadSafe, Composable { /** The <code>ComponentManager</code> */ private ComponentManager manager; /** * Composable */ public void compose(ComponentManager manager) { this.manager = manager; } /** * Get a <code>Source</code> object. * @param parameters This is optional. */ public Source getSource( String location, Map parameters ) throws MalformedURLException, IOException { if( getLogger().isDebugEnabled() ) { getLogger().debug( "Creating source object for " + location ); } return new SitemapSource( this.manager, location, parameters, getLogger()); } } 1.37 +12 -9 xml-cocoon2/src/java/org/apache/cocoon/transformation/TraxTransformer.java Index: TraxTransformer.java =================================================================== RCS file: /home/cvs/xml-cocoon2/src/java/org/apache/cocoon/transformation/TraxTransformer.java,v retrieving revision 1.36 retrieving revision 1.37 diff -u -r1.36 -r1.37 --- TraxTransformer.java 11 Nov 2002 14:20:49 -0000 1.36 +++ TraxTransformer.java 4 Dec 2002 11:06:44 -0000 1.37 @@ -52,12 +52,10 @@ import org.apache.avalon.excalibur.xml.xslt.XSLTProcessor; import org.apache.avalon.excalibur.xml.xslt.XSLTProcessorException; - import org.apache.avalon.framework.activity.Disposable; import org.apache.avalon.framework.component.ComponentException; import org.apache.avalon.framework.component.ComponentManager; import org.apache.avalon.framework.component.Composable; -import org.apache.avalon.framework.component.ComponentException; import org.apache.avalon.framework.configuration.Configurable; import org.apache.avalon.framework.configuration.Configuration; import org.apache.avalon.framework.configuration.ConfigurationException; @@ -68,27 +66,26 @@ import org.apache.cocoon.components.browser.Browser; import org.apache.cocoon.components.deli.Deli; import org.apache.cocoon.components.source.SourceUtil; -import org.apache.cocoon.environment.Session; import org.apache.cocoon.environment.Cookie; import org.apache.cocoon.environment.ObjectModelHelper; import org.apache.cocoon.environment.Request; +import org.apache.cocoon.environment.Session; import org.apache.cocoon.environment.SourceResolver; import org.apache.cocoon.xml.XMLConsumer; - import org.apache.excalibur.source.Source; import org.apache.excalibur.source.SourceException; import org.apache.excalibur.source.SourceValidity; - import org.xml.sax.SAXException; import javax.xml.transform.sax.SAXResult; import javax.xml.transform.sax.TransformerHandler; + import java.io.IOException; -import java.util.Map; +import java.util.Enumeration; +import java.util.HashMap; import java.util.Iterator; +import java.util.Map; import java.util.Set; -import java.util.HashMap; -import java.util.Enumeration; /** * This Transformer is used to transform this incomming SAX stream using @@ -580,6 +577,9 @@ return true; } + /** + * Disposable + */ public void dispose() { this.manager.release(this.browser); this.manager.release(this.xsltProcessor); @@ -590,6 +590,9 @@ this.manager = null; } + /** + * Recyclable + */ public void recycle() { this.transformerHandler = null; this.transformerValidity = null; 1.47 +1 -1 xml-cocoon2/src/webapp/WEB-INF/cocoon.xconf Index: cocoon.xconf =================================================================== RCS file: /home/cvs/xml-cocoon2/src/webapp/WEB-INF/cocoon.xconf,v retrieving revision 1.46 retrieving revision 1.47 diff -u -r1.46 -r1.47 --- cocoon.xconf 4 Dec 2002 10:30:58 -0000 1.46 +++ cocoon.xconf 4 Dec 2002 11:06:44 -0000 1.47 @@ -157,7 +157,7 @@ <source-factories> <component-instance class="org.apache.excalibur.source.impl.ResourceSourceFactory" name="resource"/> <component-instance class="org.apache.cocoon.components.source.impl.ContextSourceFactory" name="context"/> - <component-instance class="org.apache.cocoon.components.source.impl.CocoonSourceFactory" name="cocoon"/> + <component-instance class="org.apache.cocoon.components.source.impl.SitemapSourceFactory" name="cocoon"/> <!-- file protocol : this is a WriteableSource --> <component-instance class="org.apache.cocoon.components.source.impl.FileSourceFactory" name="file"/>
---------------------------------------------------------------------- In case of troubles, e-mail: [EMAIL PROTECTED] To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]