You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by da...@apache.org on 2006/10/07 17:27:00 UTC

svn commit: r453931 - in /cocoon/trunk/core: cocoon-blocks-fw/cocoon-blocks-fw-demo1/src/main/resources/META-INF/spring/ cocoon-blocks-fw/cocoon-blocks-fw-demo2/src/main/resources/META-INF/spring/ cocoon-blocks-fw/cocoon-blocks-fw-impl/src/main/java/or...

Author: danielf
Date: Sat Oct  7 08:26:58 2006
New Revision: 453931

URL: http://svn.apache.org/viewvc?view=rev&rev=453931
Log:
Spring based block framework:
* Got (thanks to Carsten's help) the context handling working in the SitemapServlet
* Created a block source (by modifying the previous OSGi based URL), and removed the configuration of the previous simple block protocol from core as their named clashed, this might affect some sample
* Created a block path module (that translates block URI:s to absolute URI:s)
* Created a block property module
* Changed name on the property blocksServletClass to servletClass in the BlockServlet for the embedded ServletContextWrapper.java
* Removed the dependency on OSGi for the blocks fw

Added:
    cocoon/trunk/core/cocoon-blocks-fw/cocoon-blocks-fw-impl/src/main/java/org/apache/cocoon/blocks/components/
    cocoon/trunk/core/cocoon-blocks-fw/cocoon-blocks-fw-impl/src/main/java/org/apache/cocoon/blocks/components/BlockPathModule.java
    cocoon/trunk/core/cocoon-blocks-fw/cocoon-blocks-fw-impl/src/main/java/org/apache/cocoon/blocks/components/BlockPropertyModule.java
    cocoon/trunk/core/cocoon-blocks-fw/cocoon-blocks-fw-impl/src/main/java/org/apache/cocoon/blocks/components/BlockSource.java
    cocoon/trunk/core/cocoon-blocks-fw/cocoon-blocks-fw-impl/src/main/java/org/apache/cocoon/blocks/components/BlockSourceFactory.java
    cocoon/trunk/core/cocoon-blocks-fw/cocoon-blocks-fw-impl/src/main/resources/META-INF/
    cocoon/trunk/core/cocoon-blocks-fw/cocoon-blocks-fw-impl/src/main/resources/META-INF/legacy/
    cocoon/trunk/core/cocoon-blocks-fw/cocoon-blocks-fw-impl/src/main/resources/META-INF/legacy/xconf/
    cocoon/trunk/core/cocoon-blocks-fw/cocoon-blocks-fw-impl/src/main/resources/META-INF/legacy/xconf/cocoon-blocks-fw-block-path-module.xconf
    cocoon/trunk/core/cocoon-blocks-fw/cocoon-blocks-fw-impl/src/main/resources/META-INF/legacy/xconf/cocoon-blocks-fw-block-property-module.xconf
    cocoon/trunk/core/cocoon-blocks-fw/cocoon-blocks-fw-impl/src/main/resources/META-INF/legacy/xconf/cocoon-blocks-fw-block-source-factory.xconf
Removed:
    cocoon/trunk/core/cocoon-blocks-fw/cocoon-blocks-fw-impl/src/main/java/org/apache/cocoon/blocks/Activator.java
    cocoon/trunk/core/cocoon-blocks-fw/cocoon-blocks-fw-impl/src/main/java/org/apache/cocoon/blocks/BlockProtocol.java
Modified:
    cocoon/trunk/core/cocoon-blocks-fw/cocoon-blocks-fw-demo1/src/main/resources/META-INF/spring/cocoon-blocks-fw-demo1-blockServlet.xml
    cocoon/trunk/core/cocoon-blocks-fw/cocoon-blocks-fw-demo2/src/main/resources/META-INF/spring/cocoon-blocks-fw-demo2-blockServlet.xml
    cocoon/trunk/core/cocoon-blocks-fw/cocoon-blocks-fw-impl/src/main/java/org/apache/cocoon/blocks/BlockConnection.java
    cocoon/trunk/core/cocoon-blocks-fw/cocoon-blocks-fw-impl/src/main/java/org/apache/cocoon/blocks/BlockContext.java
    cocoon/trunk/core/cocoon-blocks-fw/cocoon-blocks-fw-impl/src/main/java/org/apache/cocoon/blocks/BlockServlet.java
    cocoon/trunk/core/cocoon-blocks-fw/cocoon-blocks-fw-impl/src/main/java/org/apache/cocoon/blocks/util/ServletContextWrapper.java
    cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/sitemap/SitemapServlet.java
    cocoon/trunk/core/cocoon-core/src/main/resources/META-INF/legacy/xconf/cocoon-core-source-factories.xconf

Modified: cocoon/trunk/core/cocoon-blocks-fw/cocoon-blocks-fw-demo1/src/main/resources/META-INF/spring/cocoon-blocks-fw-demo1-blockServlet.xml
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-blocks-fw/cocoon-blocks-fw-demo1/src/main/resources/META-INF/spring/cocoon-blocks-fw-demo1-blockServlet.xml?view=diff&rev=453931&r1=453930&r2=453931
==============================================================================
--- cocoon/trunk/core/cocoon-blocks-fw/cocoon-blocks-fw-demo1/src/main/resources/META-INF/spring/cocoon-blocks-fw-demo1-blockServlet.xml (original)
+++ cocoon/trunk/core/cocoon-blocks-fw/cocoon-blocks-fw-demo1/src/main/resources/META-INF/spring/cocoon-blocks-fw-demo1-blockServlet.xml Sat Oct  7 08:26:58 2006
@@ -22,7 +22,7 @@
        xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
 	<bean id="org.apache.cocoon.blocks.demo1.block" class="org.apache.cocoon.blocks.BlockServlet">
 		<property name="mountPath" value="/test1"/>
-		<property name="blockServletClass" value="org.apache.cocoon.blocks.demo1.DemoServlet"/>
+		<property name="servletClass" value="org.apache.cocoon.blocks.demo1.DemoServlet"/>
 		<property name="properties">
 			<map>
 				<entry key="foo" value="baz"/>

Modified: cocoon/trunk/core/cocoon-blocks-fw/cocoon-blocks-fw-demo2/src/main/resources/META-INF/spring/cocoon-blocks-fw-demo2-blockServlet.xml
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-blocks-fw/cocoon-blocks-fw-demo2/src/main/resources/META-INF/spring/cocoon-blocks-fw-demo2-blockServlet.xml?view=diff&rev=453931&r1=453930&r2=453931
==============================================================================
--- cocoon/trunk/core/cocoon-blocks-fw/cocoon-blocks-fw-demo2/src/main/resources/META-INF/spring/cocoon-blocks-fw-demo2-blockServlet.xml (original)
+++ cocoon/trunk/core/cocoon-blocks-fw/cocoon-blocks-fw-demo2/src/main/resources/META-INF/spring/cocoon-blocks-fw-demo2-blockServlet.xml Sat Oct  7 08:26:58 2006
@@ -22,6 +22,6 @@
        xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
   <bean id="org.apache.cocoon.blocks.demo2.block" class="org.apache.cocoon.blocks.BlockServlet">
     <property name="mountPath" value="/test2"/>
-    <property name="blockServletClass" value="org.apache.cocoon.blocks.demo2.DemoServlet"/>
+    <property name="servletClass" value="org.apache.cocoon.blocks.demo2.DemoServlet"/>
   </bean>
 </beans>

Modified: cocoon/trunk/core/cocoon-blocks-fw/cocoon-blocks-fw-impl/src/main/java/org/apache/cocoon/blocks/BlockConnection.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-blocks-fw/cocoon-blocks-fw-impl/src/main/java/org/apache/cocoon/blocks/BlockConnection.java?view=diff&rev=453931&r1=453930&r2=453931
==============================================================================
--- cocoon/trunk/core/cocoon-blocks-fw/cocoon-blocks-fw-impl/src/main/java/org/apache/cocoon/blocks/BlockConnection.java (original)
+++ cocoon/trunk/core/cocoon-blocks-fw/cocoon-blocks-fw-impl/src/main/java/org/apache/cocoon/blocks/BlockConnection.java Sat Oct  7 08:26:58 2006
@@ -23,16 +23,15 @@
 import java.net.MalformedURLException;
 import java.net.URI;
 import java.net.URISyntaxException;
-import java.net.URL;
 import java.net.URLConnection;
 
 import javax.servlet.RequestDispatcher;
 import javax.servlet.ServletContext;
 import javax.servlet.ServletException;
 
+import org.apache.avalon.framework.logger.Logger;
 import org.apache.cocoon.blocks.util.BlockCallHttpServletRequest;
 import org.apache.cocoon.blocks.util.BlockCallHttpServletResponse;
-import org.osgi.service.log.LogService;
 
 /**
  * Implementation of a {@link URLConnection} that gets its content by
@@ -43,7 +42,7 @@
  * @version $Id$
  */
 public final class BlockConnection
-    extends URLConnection {
+    /*extends URLConnection*/ {
 
     /** Wrapped request */
     private BlockCallHttpServletRequest request;
@@ -59,20 +58,19 @@
     
     private String systemId;
     
-    private LogService logger;
+    private Logger logger;
 
     /**
      * Construct a new object
      */
-    public BlockConnection(URL url, LogService logger)
+    public BlockConnection(String url, Logger logger)
         throws MalformedURLException {
 
-        super(url);
         this.logger = logger;
         
         this.context = BlockCallStack.getCurrentBlockContext();
         if (this.context == null)
-            throw new MalformedURLException("Must be used in a block context " + this.getURL());
+            throw new MalformedURLException("Must be used in a block context " + url);
 
         URI blockURI = null;
         try {
@@ -118,7 +116,7 @@
         }
     }
 
-    protected final LogService getLogger() {
+    protected final Logger getLogger() {
         return this.logger;
     }
 
@@ -131,10 +129,10 @@
         }
         String scheme = uri.getScheme();
 
-        this.getLogger().log(LogService.LOG_DEBUG, "BlockSource: resolving " + uri.toString() + " with scheme " +
-                        uri.getScheme() + " and ssp " + uri.getSchemeSpecificPart());
+        this.logger.debug("BlockSource: resolving " + uri.toString() + " with scheme " +
+                uri.getScheme() + " and ssp " + uri.getSchemeSpecificPart());
         uri = new URI(uri.getSchemeSpecificPart());
-        this.getLogger().log(LogService.LOG_DEBUG, "BlockSource: resolved to " + uri.toString());
+        this.logger.debug("BlockSource: resolved to " + uri.toString());
         
         this.blockName = uri.getScheme();
         String path = uri.getPath();

Modified: cocoon/trunk/core/cocoon-blocks-fw/cocoon-blocks-fw-impl/src/main/java/org/apache/cocoon/blocks/BlockContext.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-blocks-fw/cocoon-blocks-fw-impl/src/main/java/org/apache/cocoon/blocks/BlockContext.java?view=diff&rev=453931&r1=453930&r2=453931
==============================================================================
--- cocoon/trunk/core/cocoon-blocks-fw/cocoon-blocks-fw-impl/src/main/java/org/apache/cocoon/blocks/BlockContext.java (original)
+++ cocoon/trunk/core/cocoon-blocks-fw/cocoon-blocks-fw-impl/src/main/java/org/apache/cocoon/blocks/BlockContext.java Sat Oct  7 08:26:58 2006
@@ -294,7 +294,7 @@
     public ServletContext getNamedContext(String name) {
         BlockServlet blockServlet =
             (BlockServlet) this.connections.get(name);
-        return blockServlet.getBlockContext();
+        return blockServlet != null ? blockServlet.getBlockContext() : null;
     }
         
     /**

Modified: cocoon/trunk/core/cocoon-blocks-fw/cocoon-blocks-fw-impl/src/main/java/org/apache/cocoon/blocks/BlockServlet.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-blocks-fw/cocoon-blocks-fw-impl/src/main/java/org/apache/cocoon/blocks/BlockServlet.java?view=diff&rev=453931&r1=453930&r2=453931
==============================================================================
--- cocoon/trunk/core/cocoon-blocks-fw/cocoon-blocks-fw-impl/src/main/java/org/apache/cocoon/blocks/BlockServlet.java (original)
+++ cocoon/trunk/core/cocoon-blocks-fw/cocoon-blocks-fw-impl/src/main/java/org/apache/cocoon/blocks/BlockServlet.java Sat Oct  7 08:26:58 2006
@@ -38,8 +38,8 @@
  */
 public class BlockServlet extends HttpServlet {
     private BlockContext blockContext;
-    private String blockServletClass;
-    private Servlet blockServlet;
+    private String embededServletClass;
+    private Servlet embededServlet;
 
     /* (non-Javadoc)
      * @see javax.servlet.GenericServlet#init(javax.servlet.ServletConfig)
@@ -76,8 +76,8 @@
         
         // create and initialize the embeded servlet
         try {
-            this.blockServlet =
-                (Servlet) this.getClass().getClassLoader().loadClass(this.blockServletClass).newInstance();
+            this.embededServlet =
+                (Servlet) this.getClass().getClassLoader().loadClass(this.embededServletClass).newInstance();
         } catch (InstantiationException e) {
             // TODO Auto-generated catch block
             e.printStackTrace();
@@ -88,15 +88,15 @@
             // TODO Auto-generated catch block
             e.printStackTrace();
         }
-        this.blockServlet.init(blockServletConfig);
-        this.blockContext.setServlet(this.blockServlet);
+        this.embededServlet.init(blockServletConfig);
+        this.blockContext.setServlet(this.embededServlet);
     }
 
     /* (non-Javadoc)
      * @see javax.servlet.GenericServlet#destroy()
      */
     public void destroy() {
-        this.blockServlet.destroy();
+        this.embededServlet.destroy();
         super.destroy();
     }
 
@@ -147,8 +147,8 @@
         this.blockContext.setBlockContextURL(blockContextURL);
     }
 
-    public void setBlockServletClass(String blockServletClass) {
-        this.blockServletClass = blockServletClass;
+    public void setServletClass(String servletClass) {
+        this.embededServletClass = servletClass;
     }
 
     public void setProperties(Map properties) {

Added: cocoon/trunk/core/cocoon-blocks-fw/cocoon-blocks-fw-impl/src/main/java/org/apache/cocoon/blocks/components/BlockPathModule.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-blocks-fw/cocoon-blocks-fw-impl/src/main/java/org/apache/cocoon/blocks/components/BlockPathModule.java?view=auto&rev=453931
==============================================================================
--- cocoon/trunk/core/cocoon-blocks-fw/cocoon-blocks-fw-impl/src/main/java/org/apache/cocoon/blocks/components/BlockPathModule.java (added)
+++ cocoon/trunk/core/cocoon-blocks-fw/cocoon-blocks-fw-impl/src/main/java/org/apache/cocoon/blocks/components/BlockPathModule.java Sat Oct  7 08:26:58 2006
@@ -0,0 +1,70 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.cocoon.blocks.components;
+
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.util.Iterator;
+import java.util.Map;
+
+import org.apache.avalon.framework.configuration.Configuration;
+import org.apache.avalon.framework.configuration.ConfigurationException;
+import org.apache.avalon.framework.thread.ThreadSafe;
+import org.apache.cocoon.blocks.BlockContext;
+import org.apache.cocoon.environment.Environment;
+import org.apache.cocoon.blocks.BlockCallStack;
+import org.apache.cocoon.components.modules.input.InputModule;
+import org.apache.cocoon.environment.internal.EnvironmentHelper;
+
+/**
+ * BlockPathModule returns the absolute path of a block protocol path.
+ *
+ * @version $Id: BlockPathModule.java 448464 2006-09-21 05:29:11Z crossley $
+ */
+public class BlockPathModule implements InputModule, ThreadSafe {
+
+    public Object getAttribute( String name, Configuration modeConf, Map objectModel )
+    throws ConfigurationException {
+        Environment env = EnvironmentHelper.getCurrentEnvironment();
+        BlockContext blockContext = (BlockContext) BlockCallStack.getCurrentBlockContext();
+        String absoluteURI = null;
+        /* No relative block paths yet
+        String baseURI = env.getURIPrefix();
+        if (baseURI.length() == 0 || !baseURI.startsWith("/"))
+            baseURI = "/" + baseURI;
+         */
+        try {
+            // URI uri = BlockSource.resolveURI(new URI(name), new URI(null, null, baseURI, null));
+            URI uri = new URI(name);
+            absoluteURI= blockContext.absolutizeURI(uri).toString();
+        } catch (URISyntaxException e) {
+            throw new ConfigurationException("Couldn't absolutize " + name);
+        }
+        return absoluteURI;
+    }
+
+    public Object[] getAttributeValues(String name, Configuration modeConf, Map objectModel)
+        throws ConfigurationException {
+        throw new UnsupportedOperationException();
+    }
+
+    public Iterator getAttributeNames(Configuration modeConf, Map objectModel)
+        throws ConfigurationException {
+        throw new UnsupportedOperationException();
+    }
+}

Added: cocoon/trunk/core/cocoon-blocks-fw/cocoon-blocks-fw-impl/src/main/java/org/apache/cocoon/blocks/components/BlockPropertyModule.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-blocks-fw/cocoon-blocks-fw-impl/src/main/java/org/apache/cocoon/blocks/components/BlockPropertyModule.java?view=auto&rev=453931
==============================================================================
--- cocoon/trunk/core/cocoon-blocks-fw/cocoon-blocks-fw-impl/src/main/java/org/apache/cocoon/blocks/components/BlockPropertyModule.java (added)
+++ cocoon/trunk/core/cocoon-blocks-fw/cocoon-blocks-fw-impl/src/main/java/org/apache/cocoon/blocks/components/BlockPropertyModule.java Sat Oct  7 08:26:58 2006
@@ -0,0 +1,50 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.cocoon.blocks.components;
+
+import java.util.Iterator;
+import java.util.Map;
+
+import org.apache.avalon.framework.configuration.Configuration;
+import org.apache.avalon.framework.configuration.ConfigurationException;
+import org.apache.avalon.framework.thread.ThreadSafe;
+import org.apache.cocoon.blocks.BlockCallStack;
+import org.apache.cocoon.components.modules.input.InputModule;
+
+/**
+ * BlockPropertyModule provides access to the properties of the current block.
+ *
+ * @version $Id: BlockPropertyModule.java 448464 2006-09-21 05:29:11Z crossley $
+ */
+public class BlockPropertyModule implements InputModule, ThreadSafe {
+
+    public Object getAttribute( String name, Configuration modeConf, Map objectModel )
+    throws ConfigurationException {
+        return BlockCallStack.getCurrentBlockContext().getInitParameter(name);
+    }
+
+    public Object[] getAttributeValues(String name, Configuration modeConf, Map objectModel)
+        throws ConfigurationException {
+        throw new UnsupportedOperationException();
+    }
+
+    public Iterator getAttributeNames(Configuration modeConf, Map objectModel)
+        throws ConfigurationException {
+        throw new UnsupportedOperationException();
+    }
+}

Added: cocoon/trunk/core/cocoon-blocks-fw/cocoon-blocks-fw-impl/src/main/java/org/apache/cocoon/blocks/components/BlockSource.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-blocks-fw/cocoon-blocks-fw-impl/src/main/java/org/apache/cocoon/blocks/components/BlockSource.java?view=auto&rev=453931
==============================================================================
--- cocoon/trunk/core/cocoon-blocks-fw/cocoon-blocks-fw-impl/src/main/java/org/apache/cocoon/blocks/components/BlockSource.java (added)
+++ cocoon/trunk/core/cocoon-blocks-fw/cocoon-blocks-fw-impl/src/main/java/org/apache/cocoon/blocks/components/BlockSource.java Sat Oct  7 08:26:58 2006
@@ -0,0 +1,58 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.cocoon.blocks.components;
+
+import java.io.IOException;
+import java.io.InputStream;
+
+import org.apache.avalon.framework.logger.Logger;
+import org.apache.cocoon.blocks.BlockConnection;
+import org.apache.excalibur.source.Source;
+import org.apache.excalibur.source.SourceException;
+import org.apache.excalibur.source.impl.AbstractSource;
+
+/**
+ * Implementation of a {@link Source} that gets its content by
+ * invoking the Block. 
+ *
+ * @version $Id$
+ */
+public class BlockSource extends AbstractSource {
+    
+    private BlockConnection blockConnection;
+
+    public BlockSource(String location, Logger logger) throws IOException {
+        this.blockConnection = new BlockConnection(location, logger);
+        this.blockConnection.connect();
+    }
+
+    /* (non-Javadoc)
+     * @see org.apache.excalibur.source.impl.AbstractSource#getInputStream()
+     */
+    public InputStream getInputStream() throws IOException, SourceException {
+        return this.blockConnection.getInputStream();
+    }
+
+    /**
+     * Returns true always.
+     * @see org.apache.excalibur.source.Source#exists()
+     */
+    public boolean exists() {
+        return true;
+    }
+
+}

Added: cocoon/trunk/core/cocoon-blocks-fw/cocoon-blocks-fw-impl/src/main/java/org/apache/cocoon/blocks/components/BlockSourceFactory.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-blocks-fw/cocoon-blocks-fw-impl/src/main/java/org/apache/cocoon/blocks/components/BlockSourceFactory.java?view=auto&rev=453931
==============================================================================
--- cocoon/trunk/core/cocoon-blocks-fw/cocoon-blocks-fw-impl/src/main/java/org/apache/cocoon/blocks/components/BlockSourceFactory.java (added)
+++ cocoon/trunk/core/cocoon-blocks-fw/cocoon-blocks-fw-impl/src/main/java/org/apache/cocoon/blocks/components/BlockSourceFactory.java Sat Oct  7 08:26:58 2006
@@ -0,0 +1,71 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.cocoon.blocks.components;
+
+import java.io.IOException;
+import java.net.MalformedURLException;
+import java.util.Map;
+
+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;
+import org.apache.excalibur.source.SourceUtil;
+import org.apache.excalibur.source.URIAbsolutizer;
+
+/**
+ * This class implements the block: protocol.
+ *
+ *
+ * @version $Id$
+ */
+public final class BlockSourceFactory
+extends AbstractLogEnabled
+implements SourceFactory, ThreadSafe, URIAbsolutizer
+{
+
+/* (non-Javadoc)
+ * @see org.apache.excalibur.source.SourceFactory#getSource(java.lang.String, java.util.Map)
+ */
+public Source getSource( String location, Map parameters )
+    throws MalformedURLException, IOException {
+    if( getLogger().isDebugEnabled() ) {
+        getLogger().debug( "Creating source object for " + location );
+    }
+
+    return new BlockSource(location, getLogger());
+}
+
+/* (non-Javadoc)
+ * @see org.apache.excalibur.source.SourceFactory#release(org.apache.excalibur.source.Source)
+ */
+public void release( Source source ) {
+    if ( null != source ) {
+        if ( this.getLogger().isDebugEnabled() ) {
+            this.getLogger().debug("Releasing source " + source.getURI());
+        }
+    }
+}
+
+/* (non-Javadoc)
+ * @see org.apache.excalibur.source.URIAbsolutizer#absolutize(java.lang.String, java.lang.String)
+ */
+public String absolutize(String baseURI, String location) {
+    return SourceUtil.absolutize(baseURI, location, true);
+}
+
+}

Modified: cocoon/trunk/core/cocoon-blocks-fw/cocoon-blocks-fw-impl/src/main/java/org/apache/cocoon/blocks/util/ServletContextWrapper.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-blocks-fw/cocoon-blocks-fw-impl/src/main/java/org/apache/cocoon/blocks/util/ServletContextWrapper.java?view=diff&rev=453931&r1=453930&r2=453931
==============================================================================
--- cocoon/trunk/core/cocoon-blocks-fw/cocoon-blocks-fw-impl/src/main/java/org/apache/cocoon/blocks/util/ServletContextWrapper.java (original)
+++ cocoon/trunk/core/cocoon-blocks-fw/cocoon-blocks-fw-impl/src/main/java/org/apache/cocoon/blocks/util/ServletContextWrapper.java Sat Oct  7 08:26:58 2006
@@ -203,7 +203,9 @@
      * @see javax.servlet.ServletContext#getInitParameter(java.lang.String)
      */
     public String getInitParameter(String path) {
-        return this.servletContext.getInitParameter(path);
+        // FIXME hack to get around problem with initalization order of blocks
+        // that makes inheritance of init parameters not necesarrily working during init
+        return this.servletContext != null ? this.servletContext.getInitParameter(path) : null;
     }
 
     /*

Added: cocoon/trunk/core/cocoon-blocks-fw/cocoon-blocks-fw-impl/src/main/resources/META-INF/legacy/xconf/cocoon-blocks-fw-block-path-module.xconf
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-blocks-fw/cocoon-blocks-fw-impl/src/main/resources/META-INF/legacy/xconf/cocoon-blocks-fw-block-path-module.xconf?view=auto&rev=453931
==============================================================================
--- cocoon/trunk/core/cocoon-blocks-fw/cocoon-blocks-fw-impl/src/main/resources/META-INF/legacy/xconf/cocoon-blocks-fw-block-path-module.xconf (added)
+++ cocoon/trunk/core/cocoon-blocks-fw/cocoon-blocks-fw-impl/src/main/resources/META-INF/legacy/xconf/cocoon-blocks-fw-block-path-module.xconf Sat Oct  7 08:26:58 2006
@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  Licensed to the Apache Software Foundation (ASF) under one or more
+  contributor license agreements.  See the NOTICE file distributed with
+  this work for additional information regarding copyright ownership.
+  The ASF licenses this file to You under the Apache License, Version 2.0
+  (the "License"); you may not use this file except in compliance with
+  the License.  You may obtain a copy of the License at
+
+      http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+-->
+<!-- SVN $Id$ -->
+<components>
+
+  <input-modules>
+    <component-instance name="block-path" class="org.apache.cocoon.blocks.components.BlockPathModule" />
+  </input-modules>
+
+</components>

Added: cocoon/trunk/core/cocoon-blocks-fw/cocoon-blocks-fw-impl/src/main/resources/META-INF/legacy/xconf/cocoon-blocks-fw-block-property-module.xconf
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-blocks-fw/cocoon-blocks-fw-impl/src/main/resources/META-INF/legacy/xconf/cocoon-blocks-fw-block-property-module.xconf?view=auto&rev=453931
==============================================================================
--- cocoon/trunk/core/cocoon-blocks-fw/cocoon-blocks-fw-impl/src/main/resources/META-INF/legacy/xconf/cocoon-blocks-fw-block-property-module.xconf (added)
+++ cocoon/trunk/core/cocoon-blocks-fw/cocoon-blocks-fw-impl/src/main/resources/META-INF/legacy/xconf/cocoon-blocks-fw-block-property-module.xconf Sat Oct  7 08:26:58 2006
@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  Licensed to the Apache Software Foundation (ASF) under one or more
+  contributor license agreements.  See the NOTICE file distributed with
+  this work for additional information regarding copyright ownership.
+  The ASF licenses this file to You under the Apache License, Version 2.0
+  (the "License"); you may not use this file except in compliance with
+  the License.  You may obtain a copy of the License at
+
+      http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+-->
+<!-- SVN $Id$ -->
+<components>
+
+  <input-modules>
+    <component-instance name="block-property" class="org.apache.cocoon.blocks.components.BlockPropertyModule" />
+  </input-modules>
+
+</components>

Added: cocoon/trunk/core/cocoon-blocks-fw/cocoon-blocks-fw-impl/src/main/resources/META-INF/legacy/xconf/cocoon-blocks-fw-block-source-factory.xconf
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-blocks-fw/cocoon-blocks-fw-impl/src/main/resources/META-INF/legacy/xconf/cocoon-blocks-fw-block-source-factory.xconf?view=auto&rev=453931
==============================================================================
--- cocoon/trunk/core/cocoon-blocks-fw/cocoon-blocks-fw-impl/src/main/resources/META-INF/legacy/xconf/cocoon-blocks-fw-block-source-factory.xconf (added)
+++ cocoon/trunk/core/cocoon-blocks-fw/cocoon-blocks-fw-impl/src/main/resources/META-INF/legacy/xconf/cocoon-blocks-fw-block-source-factory.xconf Sat Oct  7 08:26:58 2006
@@ -0,0 +1,30 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  Licensed to the Apache Software Foundation (ASF) under one or more
+  contributor license agreements.  See the NOTICE file distributed with
+  this work for additional information regarding copyright ownership.
+  The ASF licenses this file to You under the Apache License, Version 2.0
+  (the "License"); you may not use this file except in compliance with
+  the License.  You may obtain a copy of the License at
+
+      http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+-->
+<!-- SVN $Id$ -->
+<components>
+
+  <!--+
+      | Source Factories
+      |
+      | Each source factory adds a special uri schemes to the system.
+      +-->
+  <source-factories>
+    <component-instance name="block" class="org.apache.cocoon.blocks.components.BlockSourceFactory"/>
+  </source-factories>
+
+</components>

Modified: cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/sitemap/SitemapServlet.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/sitemap/SitemapServlet.java?view=diff&rev=453931&r1=453930&r2=453931
==============================================================================
--- cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/sitemap/SitemapServlet.java (original)
+++ cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/sitemap/SitemapServlet.java Sat Oct  7 08:26:58 2006
@@ -17,6 +17,8 @@
 package org.apache.cocoon.sitemap;
 
 import java.io.IOException;
+import java.net.MalformedURLException;
+import java.net.URL;
 
 import javax.servlet.ServletConfig;
 import javax.servlet.ServletException;
@@ -38,8 +40,8 @@
 import org.apache.cocoon.environment.http.HttpContext;
 import org.apache.cocoon.environment.http.HttpEnvironment;
 import org.apache.cocoon.environment.internal.EnvironmentHelper;
-import org.springframework.beans.factory.BeanFactory;
 import org.springframework.web.context.WebApplicationContext;
+import org.springframework.web.context.support.WebApplicationContextUtils;
 
 /**
  * Use this servlet as entry point to Cocoon. It wraps the @link {@link TreeProcessor} and delegates
@@ -50,57 +52,66 @@
 public class SitemapServlet extends HttpServlet {
 
     private static final String DEFAULT_CONTAINER_ENCODING = "ISO-8859-1";
-	private static final String DEFAULT_SITEMAP_PATH = "context://sitemap.xmap";	
+	private static final String DEFAULT_SITEMAP_PATH = "/sitemap.xmap";	
 	private static final String SITEMAP_PATH_PROPERTY = "sitemapPath";
 
-	private BeanFactory beanFactory;
 	private Logger logger;
-	private String sitemapPath;
     protected Context cocoonContext;
 	private Processor processor;	
 	private Settings settings;
 
-	/**
-	 * Initialize the servlet. The main purpose of this method is creating a configured @link {@link TreeProcessor}.
-	 */
+    /**
+     * Initialize the servlet. The main purpose of this method is creating a configured @link {@link TreeProcessor}.
+     */
     public void init(ServletConfig config) throws ServletException {
-    	super.init(config);
-
-        // Get a bean factory from the servlet context
-        this.beanFactory =
-            (BeanFactory) this.getServletContext().getAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE);
-        if (this.beanFactory == null)
-            throw new ServletException("No BeanFactory in the context");
+        super.init(config);
         
-        this.sitemapPath = this.getServletContext().getInitParameter(SITEMAP_PATH_PROPERTY);
-        if (this.sitemapPath == null)
-            this.sitemapPath = DEFAULT_SITEMAP_PATH;
+        // Get a bean factory from the servlet context
+        WebApplicationContext container =
+            WebApplicationContextUtils.getRequiredWebApplicationContext(config.getServletContext());
         
-    	// get components from the beanFactory
-    	this.logger = (Logger) this.beanFactory.getBean(ProcessingUtil.LOGGER_ROLE);
-    	this.settings = (Settings) this.beanFactory.getBean(Settings.ROLE);
+        // get components from the beanFactory
+        this.logger = (Logger) container.getBean(ProcessingUtil.LOGGER_ROLE);
+        this.settings = (Settings) container.getBean(Settings.ROLE);
         ServiceManager serviceManager = (ServiceManager) 
-    		this.beanFactory.getBean(ProcessingUtil.SERVICE_MANAGER_ROLE);    	
-    	
-    	// create the Cocoon context out of the Servlet context
-        this.cocoonContext = new HttpContext(config.getServletContext());
+        container.getBean(ProcessingUtil.SERVICE_MANAGER_ROLE);     
         
+        // create the Cocoon context out of the Servlet context
+        this.cocoonContext = new HttpContext(config.getServletContext());
+
+        // get the uri to the sitemap location and resolve it in the curent servlet context,
+        // observere that it is very important that the Treeprocessor get a resolved uri,
+        // just providing a relative uri relative to the current context is not enough
+        // and doesn't work
+        String sitemapPath = this.getServletContext().getInitParameter(SITEMAP_PATH_PROPERTY);
+        if (sitemapPath== null)
+            sitemapPath= DEFAULT_SITEMAP_PATH;
+
+        String sitemapURI;
+        try {
+            URL uri = this.getServletContext().getResource(sitemapPath);
+            if (uri == null)
+                throw new ServletException("Couldn't find the sitemap " + sitemapPath);
+            sitemapURI = uri.toExternalForm();
+        } catch (MalformedURLException e) {
+            throw new ServletException(e);
+        }
+
         // create the tree processor
         try {
-			TreeProcessor treeProcessor =  new TreeProcessor();
+            TreeProcessor treeProcessor =  new TreeProcessor();
             // TODO (DF/RP) The treeProcessor doesn't need to be a managed component at all. 
             this.processor = (Processor) LifecycleHelper.setupComponent(treeProcessor,
                     this.logger,
                     null,
                     serviceManager,
-                    createTreeProcessorConfiguration());
-		} catch (Exception e) {
+                    createTreeProcessorConfiguration(sitemapURI));
+        } catch (Exception e) {
             throw new ServletException(e);
-		}
-		
+        }
     }
     
-    /**
+	/**
      * Process the incoming request using the Cocoon tree processor.
      */
 	protected void service(HttpServletRequest request, HttpServletResponse response) 
@@ -148,10 +159,10 @@
     /**
      * Create an Avalon Configuration @link {@link Configuration} that configures the tree processor.
      */
-	private Configuration createTreeProcessorConfiguration() {
+	private Configuration createTreeProcessorConfiguration(String sitemapURI) {
 		DefaultConfiguration treeProcessorConf = new DefaultConfiguration("treeProcessorConfiguration");
         treeProcessorConf.setAttribute("check-reload", true);
-        treeProcessorConf.setAttribute("file", this.sitemapPath);
+        treeProcessorConf.setAttribute("file", sitemapURI);
 		return treeProcessorConf;
 	}	    
 }

Modified: cocoon/trunk/core/cocoon-core/src/main/resources/META-INF/legacy/xconf/cocoon-core-source-factories.xconf
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-core/src/main/resources/META-INF/legacy/xconf/cocoon-core-source-factories.xconf?view=diff&rev=453931&r1=453930&r2=453931
==============================================================================
--- cocoon/trunk/core/cocoon-core/src/main/resources/META-INF/legacy/xconf/cocoon-core-source-factories.xconf (original)
+++ cocoon/trunk/core/cocoon-core/src/main/resources/META-INF/legacy/xconf/cocoon-core-source-factories.xconf Sat Oct  7 08:26:58 2006
@@ -27,7 +27,7 @@
     <component-instance name="resource" class="org.apache.excalibur.source.impl.ResourceSourceFactory"/>
     <component-instance name="context" class="org.apache.cocoon.components.source.impl.ContextSourceFactory"/>
     <component-instance name="cocoon" class="org.apache.cocoon.components.source.impl.SitemapSourceFactory"/>
-    <component-instance name="block" class="org.apache.cocoon.components.source.impl.BlockSourceFactory"/>
+    <!--component-instance name="block" class="org.apache.cocoon.components.source.impl.BlockSourceFactory"/-->
     
     <!--+
         | The "file:" source protocol is modifiable (can be written to) and