Return-Path: Delivered-To: apmail-xml-cocoon-cvs-archive@xml.apache.org Received: (qmail 16752 invoked by uid 500); 24 Apr 2002 12:06:00 -0000 Mailing-List: contact cocoon-cvs-help@xml.apache.org; run by ezmlm Precedence: bulk Reply-To: cocoon-dev@xml.apache.org list-help: list-unsubscribe: list-post: Delivered-To: mailing list cocoon-cvs@xml.apache.org Received: (qmail 16743 invoked by uid 500); 24 Apr 2002 12:05:59 -0000 Delivered-To: apmail-xml-cocoon2-cvs@apache.org Date: 24 Apr 2002 12:05:59 -0000 Message-ID: <20020424120559.61375.qmail@icarus.apache.org> From: cziegeler@apache.org To: xml-cocoon2-cvs@apache.org Subject: cvs commit: xml-cocoon2/src/java/org/apache/cocoon/components/source/impl CocoonToAvalonSource.java SourceFactoryWrapper.java X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N cziegeler 02/04/24 05:05:59 Added: src/java/org/apache/cocoon/components/source/impl CocoonToAvalonSource.java SourceFactoryWrapper.java Log: Adding wrapper for compatibility Revision Changes Path 1.1 xml-cocoon2/src/java/org/apache/cocoon/components/source/impl/CocoonToAvalonSource.java Index: CocoonToAvalonSource.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 apache@apache.org. 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 . For more information on the Apache Software Foundation, please see . */ package org.apache.cocoon.components.source.impl; import java.io.IOException; import java.io.InputStream; import org.apache.avalon.excalibur.pool.Recyclable; import org.apache.avalon.excalibur.xml.XMLizable; import org.apache.excalibur.source.*; import org.apache.excalibur.source.impl.validity.TimeStampValidity; import org.apache.cocoon.ProcessingException; import org.apache.cocoon.environment.ModifiableSource; import org.xml.sax.ContentHandler; import org.xml.sax.SAXException; /** * This source objects wraps an obsolete Cocoon Source object * to avoid recoding existing source objects. * * @author Carsten Ziegeler * @version CVS $Revision: 1.1 $ $Date: 2002/04/24 12:05:59 $ */ public final class CocoonToAvalonSource implements Source, XMLizable, Recyclable { /** The real source */ protected org.apache.cocoon.environment.Source source; /** * Constructor */ public CocoonToAvalonSource( org.apache.cocoon.environment.Source source ) { this.source = source; } /** * Return an InputStream object to read from the source. */ public InputStream getInputStream() throws IOException { try { return this.source.getInputStream(); } catch (ProcessingException pe) { throw new IOException("ProcessingException: " + pe.getMessage()); } } /** * Return the unique identifer for this source */ public String getSystemId() { return this.source.getSystemId(); } /** * Get the Validity object. This can either wrap the last modification * date or the expires information or... * If it is currently not possible to calculate such an information * null is returned. */ public SourceValidity getValidity() { if (this.source.getLastModified() > 0) { return new TimeStampValidity(this.source.getLastModified()); } return null; } /** * Refresh this object and update the last modified date * and content length. */ public void discardValidity() { if (this.source instanceof ModifiableSource) { ((ModifiableSource)this.source).refresh(); } } /** * The mime-type of the content described by this object. * If the source is not able to determine the mime-type by itself * this can be null. */ public String getMimeType() { return null; } /** * Stream content to the content handler */ public void toSAX(ContentHandler contentHandler) throws SAXException { try { this.source.toSAX( contentHandler ); } catch (ProcessingException pe) { throw new SAXException(pe); } } /** * Recyclable */ public void recycle() { this.source.recycle(); } } 1.1 xml-cocoon2/src/java/org/apache/cocoon/components/source/impl/SourceFactoryWrapper.java Index: SourceFactoryWrapper.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 apache@apache.org. 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 . For more information on the Apache Software Foundation, please see . */ package org.apache.cocoon.components.source.impl; import java.io.IOException; import java.net.MalformedURLException; import java.util.Map; import org.apache.excalibur.source.Source; import org.apache.excalibur.source.SourceFactory; import org.apache.avalon.framework.activity.Disposable; import org.apache.avalon.framework.component.Component; 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.configuration.Configurable; import org.apache.avalon.framework.configuration.Configuration; import org.apache.avalon.framework.configuration.ConfigurationException; import org.apache.avalon.framework.context.Context; import org.apache.avalon.framework.context.ContextException; import org.apache.avalon.framework.context.Contextualizable; import org.apache.avalon.framework.logger.AbstractLoggable; import org.apache.avalon.framework.logger.Loggable; import org.apache.avalon.framework.thread.ThreadSafe; import org.apache.cocoon.ProcessingException; import org.apache.cocoon.components.CocoonComponentManager; import org.apache.cocoon.environment.Environment; import org.apache.cocoon.util.ClassUtils; /** * This class wraps a Cocoon SourceFactory and makes it * usable within the Avalon Excalibur source resolving architecure. * The main purpose is to avoid recoding existing factories. * * @author Carsten Ziegeler * @version CVS $Id: SourceFactoryWrapper.java,v 1.1 2002/04/24 12:05:59 cziegeler Exp $ */ public final class SourceFactoryWrapper extends AbstractLoggable implements SourceFactory, ThreadSafe, Configurable, Disposable, Composable, Contextualizable { /** The ComponentManager */ private ComponentManager manager; /** The special Source factories */ private org.apache.cocoon.components.source.SourceFactory sourceFactory; /** The context */ private Context context; /** * Configure the SourceFactories */ public void configure(final Configuration conf) throws ConfigurationException { try { final Configuration factoryConf = conf.getChild("source-factory"); final String className = factoryConf.getAttribute("class"); if (this.getLogger().isDebugEnabled()) { this.getLogger().debug("Getting the SourceFactory " + className); } this.sourceFactory = (org.apache.cocoon.components.source.SourceFactory) ClassUtils.newInstance(className); this.init(this.sourceFactory, factoryConf); } catch (ConfigurationException e) { throw e; } catch (Exception e) { getLogger().error("Could not get SourceFactory", e); throw new ConfigurationException("Could not get parameters because: " + e.getMessage(), e); } } /** * Get the context */ public void contextualize(Context context) throws ContextException { this.context = context; } /** * Set the current ComponentManager instance used by this * Composable. */ public void compose(ComponentManager manager) throws ComponentException { this.manager = manager; } /** * Dispose */ public void dispose() { if (this.sourceFactory != null) { this.deinit(this.sourceFactory); } this.sourceFactory = null; } /** * Get a Source object. * @param parameters This is optional. */ public Source getSource( String location, Map parameters ) throws MalformedURLException, IOException { if( this.getLogger().isDebugEnabled() ) { this.getLogger().debug( "Creating source object for " + location ); } Object[] currentEnv = CocoonComponentManager.getCurrentEnvironment(); org.apache.cocoon.environment.Source source; try { source = this.sourceFactory.getSource((currentEnv == null ? null : (Environment)currentEnv[0]), location); } catch (ProcessingException pe) { this.getLogger().error("ProcessingException", pe); throw new IOException("ProcessingException: " + pe.getMessage()); } return new CocoonToAvalonSource( source ); } /** * Init a source factory */ private void init(org.apache.cocoon.components.source.SourceFactory factory, Configuration config) throws ContextException, ComponentException, ConfigurationException { if (factory instanceof Loggable) { ((Loggable) factory).setLogger(getLogger()); } if (factory instanceof Contextualizable) { ((Contextualizable) factory).contextualize (this.context); } if (factory instanceof Composable) { ((Composable) factory).compose(this.manager); } if (config != null && factory instanceof Configurable) { ((Configurable) factory).configure(config); } } /** * Deinit a source factory */ private void deinit(org.apache.cocoon.components.source.SourceFactory factory) { if (factory instanceof Disposable) { ((Disposable) factory).dispose(); } } } ---------------------------------------------------------------------- In case of troubles, e-mail: webmaster@xml.apache.org To unsubscribe, e-mail: cocoon-cvs-unsubscribe@xml.apache.org For additional commands, e-mail: cocoon-cvs-help@xml.apache.org