You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by re...@apache.org on 2007/06/20 10:14:04 UTC

svn commit: r548982 - in /cocoon/trunk/tools/cocoon-maven-plugin/src/main: java/org/apache/cocoon/maven/deployer/ java/org/apache/cocoon/maven/deployer/utils/ java/org/apache/cocoon/maven/rcl/ resources/org/apache/cocoon/maven/rcl/WEB-INF/

Author: reinhard
Date: Wed Jun 20 01:14:03 2007
New Revision: 548982

URL: http://svn.apache.org/viewvc?view=rev&rev=548982
Log:
- factor out web.xml rewriting into separate class
- use web.xml rewriting in ReloadingWebappMojo to rewrite the web.xml AFTER the 
  patches have been applied
- minor cleanups

Added:
    cocoon/trunk/tools/cocoon-maven-plugin/src/main/java/org/apache/cocoon/maven/deployer/WebXmlRewriter.java   (with props)
Modified:
    cocoon/trunk/tools/cocoon-maven-plugin/src/main/java/org/apache/cocoon/maven/deployer/AbstractDeployMojo.java
    cocoon/trunk/tools/cocoon-maven-plugin/src/main/java/org/apache/cocoon/maven/deployer/WebApplicationRewriter.java
    cocoon/trunk/tools/cocoon-maven-plugin/src/main/java/org/apache/cocoon/maven/deployer/utils/XMLUtils.java
    cocoon/trunk/tools/cocoon-maven-plugin/src/main/java/org/apache/cocoon/maven/rcl/ReloadingWebappMojo.java
    cocoon/trunk/tools/cocoon-maven-plugin/src/main/resources/org/apache/cocoon/maven/rcl/WEB-INF/web.xml

Modified: cocoon/trunk/tools/cocoon-maven-plugin/src/main/java/org/apache/cocoon/maven/deployer/AbstractDeployMojo.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/tools/cocoon-maven-plugin/src/main/java/org/apache/cocoon/maven/deployer/AbstractDeployMojo.java?view=diff&rev=548982&r1=548981&r2=548982
==============================================================================
--- cocoon/trunk/tools/cocoon-maven-plugin/src/main/java/org/apache/cocoon/maven/deployer/AbstractDeployMojo.java (original)
+++ cocoon/trunk/tools/cocoon-maven-plugin/src/main/java/org/apache/cocoon/maven/deployer/AbstractDeployMojo.java Wed Jun 20 01:14:03 2007
@@ -46,7 +46,7 @@
 
 /**
  * Create a Cocoon web application based on a block deployment descriptor.
- * 
+ *
  * @version $Id$
  */
 public abstract class AbstractDeployMojo extends AbstractWarMojo {
@@ -54,7 +54,7 @@
     /**
      * Artifact factory, needed to download source jars for inclusion in
      * classpath.
-     * 
+     *
      * @component role="org.apache.maven.artifact.factory.ArtifactFactory"
      * @required
      * @readonly
@@ -64,7 +64,7 @@
     /**
      * Artifact resolver, needed to download source jars for inclusion in
      * classpath.
-     * 
+     *
      * @component role="org.apache.maven.artifact.resolver.ArtifactResolver"
      * @required
      * @readonly
@@ -74,7 +74,7 @@
     /**
      * Artifact resolver, needed to download source jars for inclusion in
      * classpath.
-     * 
+     *
      * @component role="org.apache.maven.artifact.metadata.ArtifactMetadataSource"
      * @required
      * @readonly
@@ -83,7 +83,7 @@
 
     /**
      * Local maven repository.
-     * 
+     *
      * @parameter expression="${localRepository}"
      * @required
      * @readonly
@@ -92,7 +92,7 @@
 
     /**
      * Remote repositories which will be searched for blocks.
-     * 
+     *
      * @parameter expression="${project.remoteArtifactRepositories}"
      * @required
      * @readonly
@@ -105,7 +105,7 @@
 
     /**
      * The project whose project files to create.
-     * 
+     *
      * @parameter expression="${project}"
      * @required
      */
@@ -113,7 +113,7 @@
 
     /**
      * The directory containing generated classes.
-     * 
+     *
      * @parameter expression="${project.build.outputDirectory}"
      * @required
      * @readonly
@@ -122,7 +122,7 @@
 
     /**
      * The directory where the webapp is built.
-     * 
+     *
      * @parameter expression="${project.build.directory}/${project.build.finalName}"
      * @required
      */
@@ -130,7 +130,7 @@
 
     /**
      * Single directory for extra files to include in the WAR.
-     * 
+     *
      * @parameter expression="${basedir}/src/main/webapp"
      * @required
      */
@@ -138,21 +138,21 @@
 
     /**
      * The path to the web.xml file to use.
-     * 
+     *
      * @parameter expression="${maven.war.webxml}"
      */
     private String webXml;
 
     /**
      * Use shielded classloading
-     * 
+     *
      * @parameter expression="${maven.war.shieldingclassloader}"
      */
     private boolean useShieldingClassLoader = false;
 
     /**
      * Move jars for shielded classloading
-     * 
+     *
      * @parameter expression="${maven.war.shieldingrepository}"
      */
     private boolean useShieldingRepository = false;
@@ -163,7 +163,7 @@
      * features that the blocks-fw offers.
      */
     protected void deployWebapp() throws MojoExecutionException, MojoFailureException {
-        
+
         this.buildExplodedWebapp(getWebappDirectory());
 
         try {
@@ -172,8 +172,8 @@
             throw new MojoExecutionException("A problem occurred while copying webapp resources.", e);
         }
 
-        xpatch(getBlockArtifactsAsMap(this.getProject(), this.getLog()), new File[0], getWebappDirectory(), this.getLog());        
-        
+        xpatch(getBlockArtifactsAsMap(this.getProject(), this.getLog()), new File[0], getWebappDirectory(), this.getLog());
+
         // take care of shielded classloading
         if (this.useShieldingClassLoader) {
             WebApplicationRewriter.shieldWebapp(new File(getWebappDirectory(), "WEB-INF"), getLog(), this.useShieldingRepository);
@@ -201,20 +201,19 @@
                 throw new DeploymentException("Can't deploy '" + lib.getAbsolutePath() + "'.", e);
             }
         }
-        
+
         for (int i = 0; i < xpatchFiles.length; i++ ) {
             File patch = xpatchFiles[i];
             try {
                 xwebPatcher.addPatch(patch);
                 log.info("Adding xpatch: " + patch);
             } catch (IOException e) {
-                throw new DeploymentException("Can't use patches '" + patch + "'.", e);                
+                throw new DeploymentException("Can't use patches '" + patch + "'.", e);
             }
         }
 
         InputStream sourceWebXmlFile = null;
         File webXml = new File(basedir, "WEB-INF/web.xml");
-        System.out.println("webXml.getAbsolutePath=" + webXml.getAbsolutePath());
         try {
             sourceWebXmlFile = new FileInputStream(webXml);
             xwebPatcher.applyPatches(sourceWebXmlFile, "WEB-INF/web.xml");
@@ -224,8 +223,8 @@
             IOUtils.closeQuietly(sourceWebXmlFile);
         }
 
-    }    
-    
+    }
+
     /**
      * Create a <code>Map</code> of <code>java.io.File</code> objects
      * pointing to artifacts.

Modified: cocoon/trunk/tools/cocoon-maven-plugin/src/main/java/org/apache/cocoon/maven/deployer/WebApplicationRewriter.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/tools/cocoon-maven-plugin/src/main/java/org/apache/cocoon/maven/deployer/WebApplicationRewriter.java?view=diff&rev=548982&r1=548981&r2=548982
==============================================================================
--- cocoon/trunk/tools/cocoon-maven-plugin/src/main/java/org/apache/cocoon/maven/deployer/WebApplicationRewriter.java (original)
+++ cocoon/trunk/tools/cocoon-maven-plugin/src/main/java/org/apache/cocoon/maven/deployer/WebApplicationRewriter.java Wed Jun 20 01:14:03 2007
@@ -16,17 +16,12 @@
  */
 package org.apache.cocoon.maven.deployer;
 
-import java.io.BufferedInputStream;
 import java.io.File;
-import java.io.FileInputStream;
 import java.io.FileOutputStream;
 import java.io.IOException;
-import java.io.InputStream;
 import java.net.JarURLConnection;
 import java.net.URL;
 import java.util.Enumeration;
-import java.util.Iterator;
-import java.util.List;
 import java.util.jar.JarEntry;
 import java.util.jar.JarFile;
 import java.util.jar.JarOutputStream;
@@ -41,19 +36,12 @@
 import org.codehaus.plexus.util.FileUtils;
 import org.codehaus.plexus.util.IOUtil;
 import org.w3c.dom.Document;
-import org.w3c.dom.Element;
 
 /**
  * @version $Id$
  */
 public class WebApplicationRewriter {
 
-    protected static final String SERVLET_CLASS = ShieldingServlet.class.getName();
-
-    protected static final String LISTENER_CLASS = ShieldingListener.class.getName();
-
-    protected static final String FILTER_CLASS = ShieldingServletFilter.class.getName();
-
     protected static final String CLASSLOADER_JAR = "cocoon-deployer-plugin-classloading.jar";
 
     protected static final String JAR_ENTRY_PREFIX = ShieldedClassLoaderManager.class.getPackage().getName().replace('.', '/');
@@ -81,26 +69,17 @@
         }
 
         // load web.xml
-        InputStream is = null;
         final Document webAppDoc;
         try {
-            is = new BufferedInputStream(new FileInputStream(new File(webInfSlashWebXml)));
-            webAppDoc = XMLUtils.parseXml(is);
+            webAppDoc = XMLUtils.parseXml(new File(webInfSlashWebXml));
         } catch (Exception e) {
             throw new MojoExecutionException("Unable to read web.xml from " + webInfSlashWebXml, e);
-        } finally {
-            if ( is != null ) {
-                try {
-                    is.close();
-                } catch (IOException ignore) {
-                    // ignore
-                }
-            }
         }
 
         // rewrite
-        if ( WebApplicationRewriter.rewrite(webAppDoc, useShieldingRepository) ) {
-
+        WebXmlRewriter webXmlRewriter = new WebXmlRewriter(ShieldingServlet.class.getName(), ShieldingListener.class
+                        .getName(), ShieldingServletFilter.class.getName(), useShieldingRepository);
+        if ( webXmlRewriter.rewrite(webAppDoc) ) {
             // save web.xml
             try {
                 if ( log.isDebugEnabled() ) {
@@ -165,7 +144,7 @@
                 throw new MojoExecutionException("Unable to find jar file for shielded class loading classes.");
             }
         } catch (IOException ioe) {
-            throw new MojoExecutionException("unable to find classes for shielded class loading.", ioe);            
+            throw new MojoExecutionException("unable to find classes for shielded class loading.", ioe);
         }
     }
 
@@ -200,149 +179,5 @@
                 }
             }
         }
-    }
-
-    public static boolean rewrite(Document webAppDoc, boolean useShieldingRepository) {
-        boolean rewritten = false;
-        final Element rootElement = webAppDoc.getDocumentElement();
-        // first rewrite servlets
-        final List servlets = XMLUtils.getChildNodes(rootElement, "servlet");
-        Iterator i = servlets.iterator();
-        while ( i.hasNext() ) {
-            final Element servletElement = (Element)i.next();
-            final Element servletClassElement = XMLUtils.getChildNode(servletElement, "servlet-class");
-            if ( servletClassElement != null ) {
-                final String className = XMLUtils.getValue(servletClassElement);
-                XMLUtils.setValue(servletClassElement, SERVLET_CLASS);
-                // create init-param with real servlet class
-                final Element initParamElem = webAppDoc.createElementNS(null, "init-param");
-                final Element initParamNameElem = webAppDoc.createElementNS(null, "param-name");
-                final Element initParamValueElem = webAppDoc.createElementNS(null, "param-value");
-                initParamElem.appendChild(initParamNameElem);
-                initParamElem.appendChild(initParamValueElem);
-                XMLUtils.setValue(initParamNameElem, "servlet-class");
-                XMLUtils.setValue(initParamValueElem, className);
-                Element beforeElement = XMLUtils.getChildNode(servletElement, "load-on-startup");
-                if ( beforeElement == null ) {
-                    beforeElement = XMLUtils.getChildNode(servletElement, "run-as");                    
-                    if ( beforeElement == null ) {
-                        beforeElement = XMLUtils.getChildNode(servletElement, "security-role-ref");                    
-                    }
-                }
-                if ( beforeElement == null ) {
-                    servletElement.appendChild(initParamElem);
-                } else {
-                    servletElement.insertBefore(initParamElem, beforeElement);
-                }
-                rewritten = true;
-            }
-        }
-
-        // now rewrite listeners
-        final List listeners = XMLUtils.getChildNodes(rootElement, "listener");
-        i = listeners.iterator();
-        boolean hasListener = false;
-        final StringBuffer rewrittenListeners = new StringBuffer();
-        while ( i.hasNext() ) {
-            final Element listenerElement = (Element)i.next();
-            final Element listenerClassElement = XMLUtils.getChildNode(listenerElement, "listener-class");
-            if ( listenerClassElement != null ) {
-                final String className = XMLUtils.getValue(listenerClassElement);
-                if ( rewrittenListeners.length() > 0 ) {
-                    rewrittenListeners.append(',');
-                }
-                rewrittenListeners.append(className);
-                if ( hasListener ) {
-                    rootElement.removeChild(listenerElement);                        
-                } else {
-                    XMLUtils.setValue(listenerClassElement, LISTENER_CLASS);
-                    hasListener = true;
-                }
-                rewritten = true;
-            }
-        }
-        // remove old parameter
-        i = XMLUtils.getChildNodes(rootElement, "context-param").iterator();
-        while ( i.hasNext() ) {
-            final Element child = (Element)i.next();
-            if ( LISTENER_CLASS.equals(XMLUtils.getValue(XMLUtils.getChildNode(child, "param-name")))) {
-                rootElement.removeChild(child);
-            }
-        }
-        if ( hasListener ) {
-            addContextParameter(rootElement, LISTENER_CLASS, rewrittenListeners.toString());
-        }
-
-        // and now filters
-        i = XMLUtils.getChildNodes(rootElement, "filter").iterator();
-        while ( i.hasNext() ) {
-            final Element filterElement = (Element)i.next();
-            final Element filterClassElement = XMLUtils.getChildNode(filterElement, "filter-class");
-            if ( filterClassElement != null ) {
-                final String className = XMLUtils.getValue(filterClassElement);
-                XMLUtils.setValue(filterClassElement, FILTER_CLASS);
-                // create init-param with real servlet class
-                final Element initParamElem = webAppDoc.createElementNS(null, "init-param");
-                final Element initParamNameElem = webAppDoc.createElementNS(null, "param-name");
-                final Element initParamValueElem = webAppDoc.createElementNS(null, "param-value");
-                initParamElem.appendChild(initParamNameElem);
-                initParamElem.appendChild(initParamValueElem);
-                XMLUtils.setValue(initParamNameElem, "filter-class");
-                XMLUtils.setValue(initParamValueElem, className);
-                filterElement.appendChild(initParamElem);
-                rewritten = true;
-            }
-        }
-
-        if ( !useShieldingRepository ) {
-            addContextParameter(rootElement,
-                                ShieldedClassLoaderManager.SHIELDED_CLASSLOADER_USE_REPOSITORY,
-                                "false");
-            rewritten = true;
-        } else {
-            if ( removeContextParameter(rootElement, ShieldedClassLoaderManager.SHIELDED_CLASSLOADER_USE_REPOSITORY) ) {
-                rewritten = true;
-            }
-        }
-
-        return rewritten;
-    }
-
-    protected static boolean removeContextParameter(Element root, String name) {
-        boolean removed = false;
-        final Iterator i = XMLUtils.getChildNodes(root, "context-param").iterator();
-        while ( !removed && i.hasNext() ) {
-            final Element parameterElement = (Element)i.next();
-            final String paramName = XMLUtils.getValue(XMLUtils.getChildNode(parameterElement, "param-name"));
-            if ( name.equals(paramName) ) {
-                parameterElement.getParentNode().removeChild(parameterElement);
-                removed = true;
-            }
-        }
-        return removed;
-    }
-
-    protected static void addContextParameter(Element root, String name, String value) {
-        removeContextParameter(root, name);
-        // search the element where we have to put the new context parameter before!
-        // we know that we have listeners so this is the last element to search for
-        Element searchElement = XMLUtils.getChildNode(root, "context-param");
-        if ( searchElement == null ) {
-            searchElement = XMLUtils.getChildNode(root, "filter");
-            if ( searchElement == null ) {
-                searchElement = XMLUtils.getChildNode(root, "filter-mapping");
-                if ( searchElement == null ) {
-                    searchElement = XMLUtils.getChildNode(root, "listener");
-                }
-            }
-        }
-        final Element contextParamElement = root.getOwnerDocument().createElementNS(null, "context-param");
-        final Element contextParamNameElement = root.getOwnerDocument().createElementNS(null, "param-name");
-        final Element contextParamValueElement = root.getOwnerDocument().createElementNS(null, "param-value");
-        contextParamElement.appendChild(contextParamNameElement);
-        contextParamElement.appendChild(contextParamValueElement);
-        XMLUtils.setValue(contextParamNameElement, name);
-        XMLUtils.setValue(contextParamValueElement, value);
-        root.insertBefore(contextParamElement, searchElement);
     }
 }

Added: cocoon/trunk/tools/cocoon-maven-plugin/src/main/java/org/apache/cocoon/maven/deployer/WebXmlRewriter.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/tools/cocoon-maven-plugin/src/main/java/org/apache/cocoon/maven/deployer/WebXmlRewriter.java?view=auto&rev=548982
==============================================================================
--- cocoon/trunk/tools/cocoon-maven-plugin/src/main/java/org/apache/cocoon/maven/deployer/WebXmlRewriter.java (added)
+++ cocoon/trunk/tools/cocoon-maven-plugin/src/main/java/org/apache/cocoon/maven/deployer/WebXmlRewriter.java Wed Jun 20 01:14:03 2007
@@ -0,0 +1,187 @@
+/*
+ * 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.maven.deployer;
+
+import java.util.Iterator;
+import java.util.List;
+
+import org.apache.cocoon.maven.deployer.servlet.ShieldedClassLoaderManager;
+import org.apache.cocoon.maven.deployer.utils.XMLUtils;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+
+/**
+ * @version $Id$
+ */
+public class WebXmlRewriter {
+
+    private String servletClass;
+    private String listenerClass;
+    private String filterClass;
+    private boolean useShieldingRepositoryParameter;
+
+    public WebXmlRewriter(String servletClass, String listenerClass, String filterClass, boolean useShieldingRepository) {
+        this.servletClass = servletClass;
+        this.listenerClass = listenerClass;
+        this.filterClass = filterClass;
+        this.useShieldingRepositoryParameter = useShieldingRepository;
+    }
+
+    public boolean rewrite(Document webAppDoc) {
+        boolean rewritten = false;
+        final Element rootElement = webAppDoc.getDocumentElement();
+        // first rewrite servlets
+        final List servlets = XMLUtils.getChildNodes(rootElement, "servlet");
+        Iterator i = servlets.iterator();
+        while ( i.hasNext() ) {
+            final Element servletElement = (Element)i.next();
+            final Element servletClassElement = XMLUtils.getChildNode(servletElement, "servlet-class");
+            if ( servletClassElement != null ) {
+                final String className = XMLUtils.getValue(servletClassElement);
+                XMLUtils.setValue(servletClassElement, this.servletClass);
+                // create init-param with real servlet class
+                final Element initParamElem = webAppDoc.createElementNS(null, "init-param");
+                final Element initParamNameElem = webAppDoc.createElementNS(null, "param-name");
+                final Element initParamValueElem = webAppDoc.createElementNS(null, "param-value");
+                initParamElem.appendChild(initParamNameElem);
+                initParamElem.appendChild(initParamValueElem);
+                XMLUtils.setValue(initParamNameElem, "servlet-class");
+                XMLUtils.setValue(initParamValueElem, className);
+                Element beforeElement = XMLUtils.getChildNode(servletElement, "load-on-startup");
+                if ( beforeElement == null ) {
+                    beforeElement = XMLUtils.getChildNode(servletElement, "run-as");
+                    if ( beforeElement == null ) {
+                        beforeElement = XMLUtils.getChildNode(servletElement, "security-role-ref");
+                    }
+                }
+                if ( beforeElement == null ) {
+                    servletElement.appendChild(initParamElem);
+                } else {
+                    servletElement.insertBefore(initParamElem, beforeElement);
+                }
+                rewritten = true;
+            }
+        }
+
+        // now rewrite listeners
+        final List listeners = XMLUtils.getChildNodes(rootElement, "listener");
+        i = listeners.iterator();
+        boolean hasListener = false;
+        final StringBuffer rewrittenListeners = new StringBuffer();
+        while ( i.hasNext() ) {
+            final Element listenerElement = (Element)i.next();
+            final Element listenerClassElement = XMLUtils.getChildNode(listenerElement, "listener-class");
+            if ( listenerClassElement != null ) {
+                final String className = XMLUtils.getValue(listenerClassElement);
+                if ( rewrittenListeners.length() > 0 ) {
+                    rewrittenListeners.append(',');
+                }
+                rewrittenListeners.append(className);
+                if ( hasListener ) {
+                    rootElement.removeChild(listenerElement);
+                } else {
+                    XMLUtils.setValue(listenerClassElement, this.listenerClass);
+                    hasListener = true;
+                }
+                rewritten = true;
+            }
+        }
+        // remove old parameter
+        i = XMLUtils.getChildNodes(rootElement, "context-param").iterator();
+        while ( i.hasNext() ) {
+            final Element child = (Element)i.next();
+            if ( this.listenerClass.equals(XMLUtils.getValue(XMLUtils.getChildNode(child, "param-name")))) {
+                rootElement.removeChild(child);
+            }
+        }
+        if ( hasListener ) {
+            addContextParameter(rootElement, this.listenerClass, rewrittenListeners.toString());
+        }
+
+        // and now filters
+        i = XMLUtils.getChildNodes(rootElement, "filter").iterator();
+        while ( i.hasNext() ) {
+            final Element filterElement = (Element)i.next();
+            final Element filterClassElement = XMLUtils.getChildNode(filterElement, "filter-class");
+            if ( filterClassElement != null ) {
+                final String className = XMLUtils.getValue(filterClassElement);
+                XMLUtils.setValue(filterClassElement, this.filterClass);
+                // create init-param with real servlet class
+                final Element initParamElem = webAppDoc.createElementNS(null, "init-param");
+                final Element initParamNameElem = webAppDoc.createElementNS(null, "param-name");
+                final Element initParamValueElem = webAppDoc.createElementNS(null, "param-value");
+                initParamElem.appendChild(initParamNameElem);
+                initParamElem.appendChild(initParamValueElem);
+                XMLUtils.setValue(initParamNameElem, "filter-class");
+                XMLUtils.setValue(initParamValueElem, className);
+                filterElement.appendChild(initParamElem);
+                rewritten = true;
+            }
+        }
+
+        if ( !this.useShieldingRepositoryParameter ) {
+            addContextParameter(rootElement,
+                                ShieldedClassLoaderManager.SHIELDED_CLASSLOADER_USE_REPOSITORY,
+                                "false");
+            rewritten = true;
+        } else {
+            if ( removeContextParameter(rootElement, ShieldedClassLoaderManager.SHIELDED_CLASSLOADER_USE_REPOSITORY) ) {
+                rewritten = true;
+            }
+        }
+
+        return rewritten;
+    }
+
+    protected static boolean removeContextParameter(Element root, String name) {
+        boolean removed = false;
+        final Iterator i = XMLUtils.getChildNodes(root, "context-param").iterator();
+        while ( !removed && i.hasNext() ) {
+            final Element parameterElement = (Element)i.next();
+            final String paramName = XMLUtils.getValue(XMLUtils.getChildNode(parameterElement, "param-name"));
+            if ( name.equals(paramName) ) {
+                parameterElement.getParentNode().removeChild(parameterElement);
+                removed = true;
+            }
+        }
+        return removed;
+    }
+
+    protected static void addContextParameter(Element root, String name, String value) {
+        removeContextParameter(root, name);
+        // search the element where we have to put the new context parameter before!
+        // we know that we have listeners so this is the last element to search for
+        Element searchElement = XMLUtils.getChildNode(root, "context-param");
+        if ( searchElement == null ) {
+            searchElement = XMLUtils.getChildNode(root, "filter");
+            if ( searchElement == null ) {
+                searchElement = XMLUtils.getChildNode(root, "filter-mapping");
+                if ( searchElement == null ) {
+                    searchElement = XMLUtils.getChildNode(root, "listener");
+                }
+            }
+        }
+        final Element contextParamElement = root.getOwnerDocument().createElementNS(null, "context-param");
+        final Element contextParamNameElement = root.getOwnerDocument().createElementNS(null, "param-name");
+        final Element contextParamValueElement = root.getOwnerDocument().createElementNS(null, "param-value");
+        contextParamElement.appendChild(contextParamNameElement);
+        contextParamElement.appendChild(contextParamValueElement);
+        XMLUtils.setValue(contextParamNameElement, name);
+        XMLUtils.setValue(contextParamValueElement, value);
+        root.insertBefore(contextParamElement, searchElement);
+    }
+}
\ No newline at end of file

Propchange: cocoon/trunk/tools/cocoon-maven-plugin/src/main/java/org/apache/cocoon/maven/deployer/WebXmlRewriter.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cocoon/trunk/tools/cocoon-maven-plugin/src/main/java/org/apache/cocoon/maven/deployer/WebXmlRewriter.java
------------------------------------------------------------------------------
    svn:keywords = Id

Propchange: cocoon/trunk/tools/cocoon-maven-plugin/src/main/java/org/apache/cocoon/maven/deployer/WebXmlRewriter.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: cocoon/trunk/tools/cocoon-maven-plugin/src/main/java/org/apache/cocoon/maven/deployer/utils/XMLUtils.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/tools/cocoon-maven-plugin/src/main/java/org/apache/cocoon/maven/deployer/utils/XMLUtils.java?view=diff&rev=548982&r1=548981&r2=548982
==============================================================================
--- cocoon/trunk/tools/cocoon-maven-plugin/src/main/java/org/apache/cocoon/maven/deployer/utils/XMLUtils.java (original)
+++ cocoon/trunk/tools/cocoon-maven-plugin/src/main/java/org/apache/cocoon/maven/deployer/utils/XMLUtils.java Wed Jun 20 01:14:03 2007
@@ -16,6 +16,9 @@
  */
 package org.apache.cocoon.maven.deployer.utils;
 
+import java.io.BufferedInputStream;
+import java.io.File;
+import java.io.FileInputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
@@ -46,6 +49,23 @@
  * @version $Id$
  */
 public class XMLUtils {
+
+    public static Document parseXml(File file) throws IOException, SAXException {
+        InputStream is = null;
+        try {
+            is = new BufferedInputStream(new FileInputStream(file));
+            return parseXml(is);
+        } finally {
+            if ( is != null ) {
+                try {
+                    is.close();
+                } catch (IOException ignore) {
+                    // ignore
+                }
+            }
+        }
+
+    }
 
     public static Document parseXml(InputStream source) throws IOException, SAXException {
         try {

Modified: cocoon/trunk/tools/cocoon-maven-plugin/src/main/java/org/apache/cocoon/maven/rcl/ReloadingWebappMojo.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/tools/cocoon-maven-plugin/src/main/java/org/apache/cocoon/maven/rcl/ReloadingWebappMojo.java?view=diff&rev=548982&r1=548981&r2=548982
==============================================================================
--- cocoon/trunk/tools/cocoon-maven-plugin/src/main/java/org/apache/cocoon/maven/rcl/ReloadingWebappMojo.java (original)
+++ cocoon/trunk/tools/cocoon-maven-plugin/src/main/java/org/apache/cocoon/maven/rcl/ReloadingWebappMojo.java Wed Jun 20 01:14:03 2007
@@ -41,6 +41,8 @@
 
 import org.antlr.stringtemplate.StringTemplate;
 import org.apache.cocoon.maven.deployer.AbstractDeployMojo;
+import org.apache.cocoon.maven.deployer.WebXmlRewriter;
+import org.apache.cocoon.maven.deployer.utils.XMLUtils;
 import org.apache.commons.configuration.ConfigurationException;
 import org.apache.commons.io.FileUtils;
 import org.apache.commons.io.IOUtils;
@@ -59,83 +61,85 @@
 import org.apache.maven.project.MavenProject;
 import org.apache.maven.project.artifact.InvalidDependencyVersionException;
 import org.apache.maven.project.artifact.MavenMetadataSource;
+import org.w3c.dom.Document;
+import org.xml.sax.SAXException;
 
 /**
  * The ReloadingWebappMojo creates a web application environment for a Cocoon block.
- * 
+ *
  * @goal rcl
  * @requiresProject true
  * @requiresDependencyResolution runtime
  * @execute phase="process-classes"
- * @version $Id$ 
+ * @version $Id$
  */
 public class ReloadingWebappMojo extends AbstractMojo {
 
     private static final String LIB_VERSION_WRAPPER = "1.0.0-M2-SNAPSHOT";
-    
-    private static final String LIB_VERSION_SPRING_RELOADER = "1.0.0-M2-SNAPSHOT";    
-    
+
+    private static final String LIB_VERSION_SPRING_RELOADER = "1.0.0-M2-SNAPSHOT";
+
     private static final String WEB_INF_WEB_XML = "WEB-INF/web.xml";
 
     private static final String WEB_INF_APP_CONTEXT = "WEB-INF/applicationContext.xml";
 
     private static final String WEB_INF_LOG4J = "WEB-INF/log4j.xml";
-    
+
     private static final String WEB_INF_LIB = "WEB-INF/lib";
-    
+
     private static final String WEB_INF_COCOON_SPRING_PROPS = "WEB-INF/cocoon/spring/rcl.properties";
 
-    private static final String WEB_INF_COCOON_PROPS = "WEB-INF/cocoon/properties/rcl.properties";   
+    private static final String WEB_INF_COCOON_PROPS = "WEB-INF/cocoon/properties/rcl.properties";
 
     private static final String WEB_INF_RCL_URLCL_CONF = "WEB-INF/cocoon/rclwrapper.urlcl.conf";
-    
+
     private static final String WEB_INF_RCLWRAPPER_RCL_CONF = "WEB-INF/cocoon/rclwrapper.rcl.conf";
-    
-    private static final String WEB_INF_RCLWRAPPER_PROPERTIES = "/WEB-INF/cocoon/rclwrapper.properties";     
+
+    private static final String WEB_INF_RCLWRAPPER_PROPERTIES = "/WEB-INF/cocoon/rclwrapper.properties";
 
 
     /**
      * The directory that contains the Cocoon web application.
-     * 
+     *
      * @parameter expression="./target/rcl"
      */
     private File target;
-    
+
     /**
      * The central property file that contains all information about where to find blocks.
-     * 
+     *
      * @parameter expression="./rcl.properties"
      */
-    private File rclPropertiesFile;    
+    private File rclPropertiesFile;
 
     /**
      * Logging: Use socket appender?
-     * 
+     *
      * @parameter expression="${cocoon.rcl.log4j.useSocketAppender}"
      */
     private boolean useSocketAppender = false;
 
     /**
      * Logging: Use console appender?
-     * 
+     *
      * @parameter expression="${cocoon.rcl.log4j.useConsoleAppender}"
      */
     private boolean useConsoleAppender = false;
-    
+
     /**
      * Enable reloading or just use this goal to produce a web application environment.
-     * 
+     *
      * @parameter
      */
-    private boolean reloadingSpringEnabled = true;
+    private boolean reloadingSpringEnabled = false;
 
     /**
      * Logging: Use a custom log4j xml configuration file=
-     * 
+     *
      * @parameter expression="${cocoon.rcl.log4j.conf}"
      */
     private String customLog4jXconf;
-    
+
     /**
      * Artifact factory, needed to download source jars for inclusion in classpath.
      *
@@ -143,8 +147,8 @@
      * @required
      * @readonly
      */
-    private ArtifactFactory artifactFactory;     
-    
+    private ArtifactFactory artifactFactory;
+
     /**
      * Artifact resolver, needed to download source jars for inclusion in classpath.
      *
@@ -152,8 +156,8 @@
      * @required
      * @readonly
      */
-    private ArtifactResolver artifactResolver;     
-    
+    private ArtifactResolver artifactResolver;
+
     /**
      * Remote repositories which will be searched for blocks.
      *
@@ -161,8 +165,8 @@
      * @required
      * @readonly
      */
-    private List remoteArtifactRepositories;  
-    
+    private List remoteArtifactRepositories;
+
     /**
      * Local maven repository.
      *
@@ -170,8 +174,8 @@
      * @required
      * @readonly
      */
-    private ArtifactRepository localRepository;   
-    
+    private ArtifactRepository localRepository;
+
     /**
      * Artifact resolver, needed to download source jars for inclusion in classpath.
      *
@@ -179,61 +183,63 @@
      * @required
      * @readonly
      */
-    private MavenMetadataSource metadataSource;    
-    
+    private MavenMetadataSource metadataSource;
+
     /**
      * The project whose project files to create.
-     * 
+     *
      * @parameter expression="${project}"
      * @required
      */
-    private MavenProject project;    
+    private MavenProject project;
 
     public void execute() throws MojoExecutionException {
         // check if this plugin is useful at all
-        if(!project.getPackaging().equals("jar") || 
+        if(!project.getPackaging().equals("jar") ||
                 !(new File(project.getBasedir(), "src/main/resources/COB-INF").exists()) ||
                 !rclPropertiesFile.exists()) {
-            getLog().info("Don't execute the Cocoon RCL plugin becaues either its packaging " + 
-                    "type is not 'jar' or it doesn't have a directory 'src/main/resources/COB-INF' or " + 
+            getLog().info("Don't execute the Cocoon RCL plugin becaues either its packaging " +
+                    "type is not 'jar' or it doesn't have a directory 'src/main/resources/COB-INF' or " +
                     "there is no rcl.properties file in the block's base directory.");
             return;
         }
-        
+
         getLog().info("Creating a reloading Cocoon web application.");
-        
+
         // create web application containing all necessary files (web.xml, applicationContext.xml, log4j.xconf)
         File webAppBaseDir = new File(target, "webapp");
-        writeInputStreamToFile(readResourceFromClassloader(WEB_INF_WEB_XML), 
+        writeInputStreamToFile(readResourceFromClassloader(WEB_INF_WEB_XML),
                 createPath(new File(webAppBaseDir, WEB_INF_WEB_XML)));
-        writeInputStreamToFile(readResourceFromClassloader(WEB_INF_APP_CONTEXT), 
+        writeInputStreamToFile(readResourceFromClassloader(WEB_INF_APP_CONTEXT),
                 createPath(new File(webAppBaseDir, WEB_INF_APP_CONTEXT)));
-        writeLog4jXml(webAppBaseDir);        
+        writeLog4jXml(webAppBaseDir);
 
         // copy rcl webapp wrapper and all its dependencies to WEB-INF/lib
         copyRclWrapperLibs(webAppBaseDir);
-        
+
         // read the properties
         RwmProperties props = readProperties();
-        
+
         // create a file that contains the URLs of all libraries (config for the UrlClassLoader)
-        createUrlClassLoaderConf(webAppBaseDir, props);   
-        
+        createUrlClassLoaderConf(webAppBaseDir, props);
+
         // create a file that contains the URLs of all classes directories (config for the ReloadingClassLoader)
         createReloadingClassLoaderConf(webAppBaseDir, props);
-        
+
         // based on the RCL configuration file, create a Spring properties file
         createSpringProperties(webAppBaseDir, props);
-        
+
         // based on the RCL configuration file, create a Cocoon properties file
         createCocoonProperties(webAppBaseDir, props);
-        
+
         // create RCL properties
         createProperties(webAppBaseDir);
-        
+
         // apply xpatch files
         applyXpatchFiles(webAppBaseDir, props);
 
+        // rewrite WebXml
+        rewriteWebXml(webAppBaseDir);
     }
 
     protected RwmProperties readProperties() throws MojoExecutionException {
@@ -252,7 +258,7 @@
             FileWriter fw = new FileWriter(urlClConfFile);
             for(Iterator aIt = props.getClassesDirs().iterator(); aIt.hasNext();) {
                 String dir = (String) aIt.next();
-                fw.write(dir + "\n");            
+                fw.write(dir + "\n");
                 this.getLog().debug("Adding classes-dir to RCLClassLoader configuration: " + dir);
             }
             fw.close();
@@ -266,22 +272,22 @@
         try {
             FileWriter fw = new FileWriter(urlClConfFile);
             Set excludeLibProps = props.getExcludedLibProps();
-            
+
             for(Iterator aIt = props.getClassesDirs().iterator(); aIt.hasNext();) {
                 String dir = (String) aIt.next();
                 fw.write(dir + "\n");
                 this.getLog().debug("Adding classes-dir (URLClassLoader configuration): " + dir);
             }
-            
+
             // add all project artifacts
             Set artifacts = project.getArtifacts();
             ScopeArtifactFilter filter = new ScopeArtifactFilter(Artifact.SCOPE_RUNTIME);
-            
+
             // add the Spring reloader lib
-            Set springReloaderArtifacts = getDependencies("org.apache.cocoon", "cocoon-rcl-spring-reloader", 
+            Set springReloaderArtifacts = getDependencies("org.apache.cocoon", "cocoon-rcl-spring-reloader",
                             LIB_VERSION_SPRING_RELOADER, "jar");
             artifacts.addAll(springReloaderArtifacts);
-            
+
             for (Iterator iter = artifacts.iterator(); iter.hasNext();) {
                 Artifact artifact = (Artifact) iter.next();
                 if (!artifact.isOptional() && filter.include(artifact) &&
@@ -308,7 +314,7 @@
             throw new MojoExecutionException("Can't write to  " + springPropFile.getAbsolutePath(), e);
         }
     }
-    
+
     protected void createCocoonProperties(File webAppBaseDir, RwmProperties props) throws MojoExecutionException {
         File springPropFile = createPath(new File(webAppBaseDir, WEB_INF_COCOON_PROPS));
         try {
@@ -321,7 +327,7 @@
     }
 
     protected void copyRclWrapperLibs(File webAppBaseDir) throws MojoExecutionException {
-        Set rclWebappDependencies = getDependencies("org.apache.cocoon",  "cocoon-rcl-webapp-wrapper", LIB_VERSION_WRAPPER, "jar");        
+        Set rclWebappDependencies = getDependencies("org.apache.cocoon",  "cocoon-rcl-webapp-wrapper", LIB_VERSION_WRAPPER, "jar");
         for (Iterator rclIt = rclWebappDependencies.iterator(); rclIt.hasNext();) {
             Artifact artifact = (Artifact) rclIt.next();
             try {
@@ -333,17 +339,17 @@
                     + artifact.getVersion() + ":" + artifact.getType());
         }
     }
-    
+
     protected void createProperties(File webAppBaseDir) throws MojoExecutionException {
-        File rclProps = createPath(new File(webAppBaseDir, WEB_INF_RCLWRAPPER_PROPERTIES));       
+        File rclProps = createPath(new File(webAppBaseDir, WEB_INF_RCLWRAPPER_PROPERTIES));
         try {
             Properties props = new Properties();
             props.setProperty("reloading.spring.enabled", Boolean.toString(this.reloadingSpringEnabled));
             props.save(new FileOutputStream(rclProps), "Reloading Classloader Properties");
         } catch (IOException e) {
             throw new MojoExecutionException("Can't write to  " + rclProps.getAbsolutePath(), e);
-        } 
-    }    
+        }
+    }
 
     protected void writeLog4jXml(File webAppBaseDir) throws MojoExecutionException {
         Map log4jTemplateMap = new HashMap();
@@ -351,7 +357,7 @@
         log4jTemplateMap.put("useSocketAppender", new Boolean(this.useSocketAppender));
         writeStringTemplateToFile(webAppBaseDir, WEB_INF_LOG4J, customLog4jXconf, log4jTemplateMap);
     }
-    
+
 
     private void applyXpatchFiles(File webAppBaseDir, RwmProperties props) throws MojoExecutionException {
         // find all xpatch files in all configured blocks
@@ -365,7 +371,7 @@
                     public boolean accept(File d, String name) {
                         return name.toLowerCase().endsWith(".xweb");
                     }
-                }); 
+                });
                 if(xmlFiles != null) {
                     File[] mergedArray = new File[allXPatchFiles.length + xmlFiles.length];
                     System.arraycopy(allXPatchFiles, 0, mergedArray, 0, allXPatchFiles.length);
@@ -375,11 +381,40 @@
             } catch (URISyntaxException e) {
             }
         }
-        
+
         Map libs = AbstractDeployMojo.getBlockArtifactsAsMap(this.project, this.getLog());
         AbstractDeployMojo.xpatch(libs, allXPatchFiles, webAppBaseDir, this.getLog());
     }
-    
+
+    protected void rewriteWebXml(File webAppBaseDir) throws MojoExecutionException {
+        File webXml = new File(webAppBaseDir, WEB_INF_WEB_XML);
+        Document webXmlDocument;
+        try {
+            webXmlDocument = XMLUtils.parseXml(webXml);
+        } catch (IOException e) {
+            throw new MojoExecutionException("Problem while reading from " + webXml);
+        } catch (SAXException e) {
+            throw new MojoExecutionException("Problem while parsing " + webXml);
+        }
+        WebXmlRewriter webXmlRewriter = new WebXmlRewriter(
+                        "org.apache.cocoon.tools.rcl.wrapper.servlet.ReloadingServlet",
+                        "org.apache.cocoon.tools.rcl.wrapper.servlet.ReloadingListener",
+                        "org.apache.cocoon.tools.rcl.wrapper.servlet.ReloadingServletFilter",
+                        false);
+        if ( webXmlRewriter.rewrite(webXmlDocument) ) {
+            // save web.xml
+            try {
+                if ( this.getLog().isDebugEnabled() ) {
+                    this.getLog().debug("Rewriting web.xml: " + webXml);
+                }
+                XMLUtils.write(webXmlDocument, new FileOutputStream(webXml));
+            } catch (Exception e) {
+                throw new MojoExecutionException("Unable to write web.xml to " + webXml, e);
+            }
+        }
+    }
+
+
     // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ utility methods ~~~~~~~~~~
 
     protected Set getDependencies(final String groupId, final String artifactId, final String version,
@@ -388,12 +423,12 @@
         try {
             Set artifacts = null;
             ArtifactResolutionResult result = null;
-            
+
             Dependency dependency = new Dependency();
             dependency.setGroupId(groupId);
             dependency.setArtifactId(artifactId);
             dependency.setVersion(version);
-            
+
             List dependencies = new ArrayList();
             dependencies.add(dependency);
             Artifact pomArtifact = artifactFactory.createBuildArtifact("unspecified", "unspecified", "0.0", "jar");
@@ -401,7 +436,7 @@
             artifacts = MavenMetadataSource.createArtifacts(artifactFactory, dependencies, "compile", null, null);
             result = artifactResolver.resolveTransitively(artifacts, pomArtifact, managedDependencies, localRepository,
                     remoteArtifactRepositories, metadataSource);
-            
+
             for (Iterator i = artifacts.iterator(); i.hasNext();) {
                 Artifact artifact = (Artifact) i.next();
                 returnSet.add(artifact);
@@ -420,7 +455,7 @@
         }
         return returnSet;
     }
-    
+
     protected void writeStringTemplateToFile(final File basedir, final String fileName, final String customFile,
             final Map templateObjects) throws MojoExecutionException {
         OutputStream fos = null;
@@ -470,17 +505,17 @@
         }
         return file;
     }
-    
+
     protected void writeInputStreamToFile(final InputStream is, final File f) throws MojoExecutionException {
         Validate.notNull(is);
-        Validate.notNull(f);        
+        Validate.notNull(f);
         try {
             FileWriter fw = new FileWriter(f);
             IOUtils.copy(is, fw);
             fw.close();
         } catch (IOException e) {
             throw new MojoExecutionException("Can't write to file " + f);
-        }    
+        }
     }
-    
+
 }

Modified: cocoon/trunk/tools/cocoon-maven-plugin/src/main/resources/org/apache/cocoon/maven/rcl/WEB-INF/web.xml
URL: http://svn.apache.org/viewvc/cocoon/trunk/tools/cocoon-maven-plugin/src/main/resources/org/apache/cocoon/maven/rcl/WEB-INF/web.xml?view=diff&rev=548982&r1=548981&r2=548982
==============================================================================
--- cocoon/trunk/tools/cocoon-maven-plugin/src/main/resources/org/apache/cocoon/maven/rcl/WEB-INF/web.xml (original)
+++ cocoon/trunk/tools/cocoon-maven-plugin/src/main/resources/org/apache/cocoon/maven/rcl/WEB-INF/web.xml Wed Jun 20 01:14:03 2007
@@ -15,131 +15,96 @@
   See the License for the specific language governing permissions and
   limitations under the License.
 -->
-<!--+
-    | This is the Cocoon web-app configurations file
-    +-->
-    <!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd">
-    <web-app>
-      <context-param>
-        <param-name>org.apache.cocoon.tools.rcl.wrapper.servlet.ReloadingListener</param-name>
-        <param-value>
-          org.springframework.web.context.ContextLoaderListener
-        </param-value>
-      </context-param>
-      
-      <filter>
-        <filter-name>ReloadingSpringFilter</filter-name>
-        <display-name>ReloadingSpringFilter</display-name>
-        <description>Reloads the Spring application context if a classloader change was detected.</description>
-        <filter-class>org.apache.cocoon.tools.rcl.wrapper.servlet.ReloadingServletFilter</filter-class>
-        <init-param>
-          <param-name>filter-class</param-name>
-          <param-value>org.apache.cocoon.tools.rcl.wrapper.servlet.ReloadingSpringFilter</param-value>
-        </init-param>
-      </filter>         
-      <filter>
-        <filter-name>RequestContextFilter</filter-name>
-        <display-name>Request context filter</display-name>
-        <description>Servlet filter that exposes the request to the current thread.</description>
-        <filter-class>org.apache.cocoon.tools.rcl.wrapper.servlet.ReloadingServletFilter</filter-class>
-        <init-param>
-          <param-name>filter-class</param-name>
-          <param-value>org.springframework.web.filter.RequestContextFilter</param-value>
-        </init-param>
-      </filter>       
-      <filter>
-        <filter-name>CocoonDebugFilter</filter-name>
-        <display-name>Cocoon debug filter</display-name>
-        <description>Log debug information about each request</description>
-        <filter-class>org.apache.cocoon.tools.rcl.wrapper.servlet.ReloadingServletFilter</filter-class>
-        <init-param>
-          <param-name>filter-class</param-name>
-          <param-value>org.apache.cocoon.servlet.DebugFilter</param-value>
-        </init-param>
-      </filter>    
-      <filter>
-        <filter-name>CocoonMultipartFilter</filter-name>
-        <display-name>Cocoon multipart filter</display-name>
-        <description>Multipart MIME handling filter for Cocoon</description>
-        <filter-class>org.apache.cocoon.tools.rcl.wrapper.servlet.ReloadingServletFilter</filter-class>
-        <init-param>
-          <param-name>filter-class</param-name>
-          <param-value>org.apache.cocoon.servlet.multipart.MultipartFilter</param-value>
-        </init-param>
-      </filter>     
-                  
-      <filter-mapping>
-        <filter-name>ReloadingSpringFilter</filter-name>
-        <servlet-name>DispatcherServlet</servlet-name>
-      </filter-mapping>                    
-      <filter-mapping>
-        <filter-name>RequestContextFilter</filter-name>
-        <servlet-name>DispatcherServlet</servlet-name>
-      </filter-mapping>   
-      <filter-mapping>
-        <filter-name>CocoonDebugFilter</filter-name>
-        <servlet-name>DispatcherServlet</servlet-name>
-      </filter-mapping>                 
-      <filter-mapping>
-        <filter-name>CocoonMultipartFilter</filter-name>
-        <servlet-name>DispatcherServlet</servlet-name>
-      </filter-mapping> 
-      
-      <listener>
-        <listener-class>org.apache.cocoon.tools.rcl.wrapper.servlet.ReloadingListener</listener-class>
-      </listener> 
-           
-      <servlet>
-        <servlet-name>DispatcherServlet</servlet-name>
-        <display-name>DispatcherServlet</display-name>
-        <description>Cocoon blocks dispatcher</description>
-        <servlet-class>org.apache.cocoon.tools.rcl.wrapper.servlet.ReloadingServlet</servlet-class>
-        <init-param>
-          <param-name>servlet-class</param-name>
-          <param-value>org.apache.cocoon.servletservice.DispatcherServlet</param-value>
-        </init-param>
-        <load-on-startup>1</load-on-startup>
-      </servlet>
-      
-      <servlet-mapping>
-        <servlet-name>DispatcherServlet</servlet-name>
-        <url-pattern>/*</url-pattern>
-      </servlet-mapping>
-      <servlet-mapping>
-        <servlet-name>DispatcherServlet</servlet-name>
-        <url-pattern>*.jsp</url-pattern>
-      </servlet-mapping>
-      <servlet-mapping>
-        <servlet-name>DispatcherServlet</servlet-name>
-        <url-pattern>*.html</url-pattern>
-      </servlet-mapping>
-      <!-- various MIME type mappings ====================================== -->
-      <mime-mapping>
-        <extension>css</extension>
-        <mime-type>text/css</mime-type>
-      </mime-mapping>
-      <mime-mapping>
-        <extension>xml</extension>
-        <mime-type>text/xml</mime-type>
-      </mime-mapping>
-      <mime-mapping>
-        <extension>xsl</extension>
-        <mime-type>text/xml</mime-type>
-      </mime-mapping>
-      <mime-mapping>
-        <extension>xconf</extension>
-        <mime-type>text/xml</mime-type>
-      </mime-mapping>
-      <mime-mapping>
-        <extension>xmap</extension>
-        <mime-type>text/xml</mime-type>
-      </mime-mapping>
-      <mime-mapping>
-        <extension>ent</extension>
-        <mime-type>text/plain</mime-type>
-      </mime-mapping>
-      <mime-mapping>
-        <extension>grm</extension>
-        <mime-type>text/plain</mime-type>
-      </mime-mapping>
-    </web-app>    
+<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd">
+<web-app>
+
+  <filter>
+    <filter-name>ReloadingSpringFilter</filter-name>
+    <display-name>ReloadingSpringFilter</display-name>
+    <description>Reloads the Spring application context if a classloader change was detected.</description>
+    <filter-class>org.apache.cocoon.tools.rcl.wrapper.servlet.ReloadingSpringFilter</filter-class>
+  </filter>
+  <filter>
+    <description>Multipart MIME handling filter for Cocoon</description>
+    <display-name>Cocoon multipart filter</display-name>
+    <filter-name>CocoonMultipartFilter</filter-name>
+    <filter-class>org.apache.cocoon.servlet.multipart.MultipartFilter</filter-class>
+  </filter>
+  <filter>
+    <description>Log debug information about each request</description>
+    <display-name>Cocoon debug filter</display-name>
+    <filter-name>CocoonDebugFilter</filter-name>
+    <filter-class>org.apache.cocoon.servlet.DebugFilter</filter-class>
+  </filter>
+
+  <filter-mapping>
+    <filter-name>ReloadingSpringFilter</filter-name>
+    <servlet-name>DispatcherServlet</servlet-name>
+  </filter-mapping>
+  <filter-mapping>
+    <filter-name>CocoonDebugFilter</filter-name>
+    <servlet-name>DispatcherServlet</servlet-name>
+  </filter-mapping>
+  <filter-mapping>
+    <filter-name>CocoonMultipartFilter</filter-name>
+    <servlet-name>DispatcherServlet</servlet-name>
+  </filter-mapping>
+
+  <listener>
+    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
+  </listener>
+  <listener>
+    <listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
+  </listener>
+
+  <servlet>
+    <description>Cocoon blocks dispatcher</description>
+    <display-name>DispatcherServlet</display-name>
+    <servlet-name>DispatcherServlet</servlet-name>
+    <servlet-class>org.apache.cocoon.servletservice.DispatcherServlet</servlet-class>
+    <load-on-startup>1</load-on-startup>
+  </servlet>
+
+  <servlet-mapping>
+    <servlet-name>DispatcherServlet</servlet-name>
+    <url-pattern>/*</url-pattern>
+  </servlet-mapping>
+  <servlet-mapping>
+    <servlet-name>DispatcherServlet</servlet-name>
+    <url-pattern>*.jsp</url-pattern>
+  </servlet-mapping>
+  <servlet-mapping>
+    <servlet-name>DispatcherServlet</servlet-name>
+    <url-pattern>*.html</url-pattern>
+  </servlet-mapping>
+
+  <!-- various MIME type mappings ====================================== -->
+  <mime-mapping>
+    <extension>css</extension>
+    <mime-type>text/css</mime-type>
+  </mime-mapping>
+  <mime-mapping>
+    <extension>xml</extension>
+    <mime-type>text/xml</mime-type>
+  </mime-mapping>
+  <mime-mapping>
+    <extension>xsl</extension>
+    <mime-type>text/xml</mime-type>
+  </mime-mapping>
+  <mime-mapping>
+    <extension>xconf</extension>
+    <mime-type>text/xml</mime-type>
+  </mime-mapping>
+  <mime-mapping>
+    <extension>xmap</extension>
+    <mime-type>text/xml</mime-type>
+  </mime-mapping>
+  <mime-mapping>
+    <extension>ent</extension>
+    <mime-type>text/plain</mime-type>
+  </mime-mapping>
+  <mime-mapping>
+    <extension>grm</extension>
+    <mime-type>text/plain</mime-type>
+  </mime-mapping>
+</web-app>