cziegeler 02/04/19 07:37:34 Modified: src/java/org/apache/cocoon/components/url ContextURLFactory.java src/webapp/WEB-INF cocoon.xconf Added: src/java/org/apache/cocoon/components/source ContextSourceFactory.java Log: Adding context protocol for new source resolver Revision Changes Path 1.1 xml-cocoon2/src/java/org/apache/cocoon/components/source/ContextSourceFactory.java Index: ContextSourceFactory.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; import java.io.IOException; import java.net.MalformedURLException; import java.net.URL; import java.util.Map; import org.apache.excalibur.source.Source; import org.apache.excalibur.source.impl.URLSource; import org.apache.avalon.framework.context.ContextException; import org.apache.avalon.framework.context.Contextualizable; import org.apache.avalon.framework.logger.AbstractLogEnabled; import org.apache.avalon.framework.thread.ThreadSafe; import org.apache.cocoon.Constants; import org.apache.cocoon.environment.Context; /** * A factory for the context protocol using the context of the servlet api * * @author <a href="mailto:[EMAIL PROTECTED]">Carsten Ziegeler</a> * @version $Id: ContextSourceFactory.java,v 1.1 2002/04/19 14:37:33 cziegeler Exp $ */ public class ContextSourceFactory extends AbstractLogEnabled implements org.apache.excalibur.source.SourceFactory, ThreadSafe { /** * The context */ protected org.apache.avalon.framework.context.Context context; /** * Get the context */ public void contextualize(org.apache.avalon.framework.context.Context context) throws ContextException { this.context = context; } /** * Get a <code>Source</code> 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 ); } Context envContext = null; try { envContext = (Context)this.context.get(Constants.CONTEXT_ENVIRONMENT_CONTEXT); } catch (ContextException e){ getLogger().error("ContextException in getURL",e); } final int pos = location.indexOf( "://" ); location = location.substring( pos + 3 ); URL u; if (envContext == null) { this.getLogger().warn("no environment-context in application context (making an absolute URL)"); u = new URL(location); } else { u = envContext.getResource("/" + location); } if ( u == null ) { this.getLogger().error(location + " could not be found. (possible context problem)"); throw new MalformedURLException(location + " could not be found. (possible context problem)"); } return new URLSource( u, parameters ); } } 1.4 +2 -2 xml-cocoon2/src/java/org/apache/cocoon/components/url/ContextURLFactory.java Index: ContextURLFactory.java =================================================================== RCS file: /home/cvs/xml-cocoon2/src/java/org/apache/cocoon/components/url/ContextURLFactory.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- ContextURLFactory.java 22 Feb 2002 07:00:14 -0000 1.3 +++ ContextURLFactory.java 19 Apr 2002 14:37:34 -0000 1.4 @@ -61,7 +61,7 @@ /** * @author <a href="mailto:[EMAIL PROTECTED]">Giacomo Pati</a> - * @version $Id: ContextURLFactory.java,v 1.3 2002/02/22 07:00:14 cziegeler Exp $ + * @version $Id: ContextURLFactory.java,v 1.4 2002/04/19 14:37:34 cziegeler Exp $ */ public class ContextURLFactory extends AbstractLoggable implements URLFactory, Contextualizable { @@ -95,7 +95,7 @@ return u; else { getLogger().error(location + " could not be found. (possible context problem)"); - throw new RuntimeException(location + " could not be found. (possible context problem)"); + throw new MalformedURLException(location + " could not be found. (possible context problem)"); } } 1.7 +1 -0 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.6 retrieving revision 1.7 diff -u -r1.6 -r1.7 --- cocoon.xconf 19 Apr 2002 11:02:59 -0000 1.6 +++ cocoon.xconf 19 Apr 2002 14:37:34 -0000 1.7 @@ -176,6 +176,7 @@ --> <source-factories> <component-instance class="org.apache.excalibur.source.impl.ResourceSourceFactory" name="resource"/> + <component-instance class="org.apache.cocoon.components.source.ContextSourceFactory" name="context"/> </source-factories>
---------------------------------------------------------------------- In case of troubles, e-mail: [EMAIL PROTECTED] To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]