Added: 
jakarta/cactus/trunk/integration/maven2/src/main/java/org/apache/cactus/maven2/mojos/CactifyWarMojo.java
URL: 
http://svn.apache.org/viewvc/jakarta/cactus/trunk/integration/maven2/src/main/java/org/apache/cactus/maven2/mojos/CactifyWarMojo.java?rev=653066&view=auto
==============================================================================
--- 
jakarta/cactus/trunk/integration/maven2/src/main/java/org/apache/cactus/maven2/mojos/CactifyWarMojo.java
 (added)
+++ 
jakarta/cactus/trunk/integration/maven2/src/main/java/org/apache/cactus/maven2/mojos/CactifyWarMojo.java
 Sat May  3 05:42:29 2008
@@ -0,0 +1,504 @@
+/* 
+ * ========================================================================
+ * 
+ * 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.cactus.maven2.mojos;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.text.DecimalFormat;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Random;
+
+import org.apache.cactus.integration.api.cactify.CactifyUtils;
+import org.apache.maven.archiver.MavenArchiveConfiguration;
+import org.apache.maven.archiver.MavenArchiver;
+import org.apache.maven.artifact.DependencyResolutionRequiredException;
+import org.apache.maven.artifact.factory.ArtifactFactory;
+import org.apache.maven.plugin.AbstractMojo;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.MojoFailureException;
+import org.apache.maven.plugin.assembly.archive.ArchiveExpansionException;
+import org.apache.maven.plugin.assembly.utils.AssemblyFileUtils;
+import org.apache.maven.project.MavenProject;
+import org.apache.tools.ant.types.XMLCatalog;
+import org.codehaus.cargo.container.internal.util.ResourceUtils;
+import org.codehaus.cargo.module.webapp.DefaultWarArchive;
+import org.codehaus.cargo.module.webapp.EjbRef;
+import org.codehaus.cargo.module.webapp.WarArchive;
+import org.codehaus.cargo.module.webapp.WebXml;
+import org.codehaus.cargo.module.webapp.WebXmlIo;
+import org.codehaus.cargo.module.webapp.WebXmlUtils;
+import org.codehaus.cargo.module.webapp.merge.WebXmlMerger;
+import org.codehaus.plexus.archiver.ArchiverException;
+import org.codehaus.plexus.archiver.jar.ManifestException;
+import org.codehaus.plexus.archiver.manager.ArchiverManager;
+import org.codehaus.plexus.archiver.manager.NoSuchArchiverException;
+import org.codehaus.plexus.archiver.war.WarArchiver;
+import org.codehaus.plexus.util.FileUtils;
+import org.jdom.JDOMException;
+
+/**
+ * A maven2 mojo that injects elements necessary to run Cactus tests into an
+ * existing WAR file.
+ * 
+ * @version $Id: CactifyWarMojo.java 394252 2008-04-29 04:20:17Z ptahchiev $
+ * @goal cactifywar
+ * @requiresDependencyResolution compile
+ */
+public class CactifyWarMojo extends AbstractMojo
+{
+       
+    /**
+     * Get some non-crypto-grade randomness from various places.
+     */
+    private static Random rand = new Random(System.currentTimeMillis()
+            + Runtime.getRuntime().freeMemory());
+
+    /**
+     * For resolving entities such as DTDs.
+     */
+    private XMLCatalog xmlCatalog = null;
+
+    /**
+     * The archive that contains the web-app that should be cactified.
+     * @parameter
+     */
+    private File srcFile;
+    
+    /**
+     * The War archiver.
+     *
+     * @parameter 
expression="${component.org.codehaus.plexus.archiver.Archiver#war}"
+     * @required
+     */
+    private WarArchiver warArchiver;
+    
+    /**
+     * The maven project.
+     *
+     * @parameter expression="${project}"
+     * @required
+     * @readonly
+     */
+    private MavenProject project;
+    
+    /**
+     * The maven archive configuration to use.
+     *
+     * @parameter
+     */
+    private MavenArchiveConfiguration archive = new 
MavenArchiveConfiguration();
+
+    /**
+     * Location of the descriptor of which the content should be merged into 
+     * the descriptor of the cactified archive.
+     * @parameter
+     */
+    private File mergeWebXml;
+
+    /**
+     * The Cactus test redirectors.
+     * @parameter
+     */
+    private List redirectors = new ArrayList();
+    
+    /**
+     * List of ejb-refs to add to the deployment descriptor 
+     * of the cactified war.
+     */
+    private List ejbRefs = new ArrayList();
+    
+    /**
+     * The cargo ResourceUtils.
+     */
+    private ResourceUtils utils = new ResourceUtils();
+    
+    /**
+     * The archive manager.
+     * @component
+     */
+    private ArchiverManager archiverManager;
+    
+    /**
+     * Dependencies to be included in the WEB-INF/lib folder.
+     * @parameter
+     */
+    private List libDependencies;
+    
+    /**
+     * Should we install the cactified archive in the local maven repo?
+     * @parameter
+     */
+    private boolean installLocally = false;
+    
+    /**
+     * @plexus.requirement
+     */
+    private ArtifactFactory factory;
+  
+    /**
+     * The file that we want to produce.
+     * @parameter
+     */
+    private File destFile;
+    
+    /**
+     * The "main" method of the mojo.
+     * @throws MojoExecutionException in case an error occurs.
+     * @throws MojoFailureException in case a failure occurs.
+     */
+       public void execute() throws MojoExecutionException, 
MojoFailureException
+       {
+               
+               if(this.srcFile != null) 
+               {
+            getLog().info("Analyzing war: " + this.srcFile.getAbsolutePath());
+               }
+               
+        WebXml webXml = null;
+        
+        MavenArchiver archiver = new MavenArchiver();
+
+        archiver.setArchiver( warArchiver );
+
+        archiver.setOutputFile( destFile );
+        
+        File tmpWebXml = null;
+        
+               try 
+               {
+                       webXml = getOriginalWebXml();
+                       tmpWebXml = cactifyWebXml(webXml);
+                       
+                       //Add the required libs for Cactus.
+                       
warArchiver.addLib(addJarWithClass("org.aspectj.lang.JoinPoint", 
+                                       "AspectJ Runtime"));
+                       warArchiver.addLib(addJarWithClass("org.apache.cactus." 
+
+                                       "ServletTestCase", "Cactus Framework"));
+                       
warArchiver.addLib(addJarWithClass("org.apache.commons.logging.Log",
+                           "Commons-Logging"));
+                       
warArchiver.addLib(addJarWithClass("org.apache.commons." +
+                                       "httpclient.HttpClient", 
"Commons-HttpClient"));
+                       warArchiver.addLib(addJarWithClass("junit.framework." +
+                                       "TestCase", "JUnit"));
+                       
+               File tempLocation = createTempFile("cactus", "explode.tmp.dir",
+                       getProject().getBasedir(), true);
+                       
+                       tempLocation.mkdirs();
+                       tempLocation.deleteOnExit();
+                       
+                       //Now add all of the additional lib files.
+                       for (Iterator iter = 
libDependencies.iterator();iter.hasNext();)
+                       {
+                               org.apache.cactus.maven2.mojos.Dependency 
dependency = 
+                                       
(org.apache.cactus.maven2.mojos.Dependency) iter.next();
+                               warArchiver.addLib(new 
File(dependency.getDependencyPath(
+                                       project, getLog())));
+                       }
+                       
+                       try {
+                               AssemblyFileUtils.unpack( this.srcFile, 
tempLocation,
+                                               archiverManager );
+                       } catch (ArchiveExpansionException e) {
+                       throw new MojoExecutionException("Error extracting the" 
+
+                                       " archive.", e);
+                       } catch (NoSuchArchiverException e) {
+                       throw new MojoExecutionException("Problem reading the " 
+
+                                       "source archive.", e);
+                       }
+                       warArchiver.addDirectory(tempLocation);
+                       warArchiver.setWebxml(tmpWebXml);
+                       archiver.createArchive( getProject(), getArchive() );
+                       
+                       FileUtils.deleteDirectory(tempLocation);
+               } 
+               catch (ArchiverException e) 
+               {
+               throw new MojoExecutionException("Problem reading the " +
+                               "source archive.", e);
+               } 
+        catch (JDOMException e) 
+               {
+               throw new MojoExecutionException("Unable to cactify " +
+                               "your web.xml.", e);
+               }
+               catch (ManifestException e) 
+               {
+               throw new MojoExecutionException("Problem reading the " +
+                               "source archive.", e);
+               } 
+               catch (IOException e) 
+               {
+               throw new MojoExecutionException("Input/output error reading 
the" +
+                               "source archive.", e);
+               } 
+               catch (DependencyResolutionRequiredException e) 
+               {
+               throw new MojoExecutionException("Error resolving your " +
+                               "dependencies", e);
+               }
+       }
+       
+    /**
+     * Enhances the provided web deployment descriptor with the definitions 
+     * required for testing with Cactus.
+     * 
+     * @param theWebXml The original deployment descriptor
+     * @return A temporary file containing the cactified descriptor
+     * @throws JDOMException in case a JDOM exception is thrown.
+     * @throws MojoExecutionException in case any other error occurs.
+     */
+    private File cactifyWebXml(WebXml theWebXml) throws JDOMException, 
+                                                                               
                        MojoExecutionException
+    {
+       CactifyUtils utils = new CactifyUtils();
+       utils.addRedirectorDefinitions(theWebXml, redirectors);
+        addJspRedirector();
+        addEjbRefs(theWebXml);
+        
+        // If the user has specified a deployment descriptor to merge into the
+        // cactified descriptor, perform the merge 
+        if (this.mergeWebXml != null)
+        {
+            try
+            {
+                WebXml parsedMergeWebXml = WebXmlIo.parseWebXmlFromFile(
+                    this.mergeWebXml, this.xmlCatalog);
+                WebXmlMerger merger = new WebXmlMerger(theWebXml);
+                merger.setLogger(utils.getLogger());
+               
+                merger.merge(parsedMergeWebXml);
+            }
+            catch (IOException e)
+            {
+                throw new MojoExecutionException(
+                    "Could not merge deployment descriptors", e);
+            }
+        }
+        
+        // Serialize the cactified deployment descriptor into a temporary file,
+        // so that it can get picked up by the War task
+        //FileUtils fileUtils = FileUtils.newFileUtils();
+        File tmpDir = createTempFile("cactus", "tmp.dir",
+            getProject().getBasedir(), true);
+        tmpDir.mkdirs();
+        tmpDir.deleteOnExit();
+        File webXmlFile = null;
+        try
+        {
+            tmpDir.mkdir();
+            File[] files = WebXmlIo.writeAll(theWebXml, 
+                tmpDir.getAbsolutePath());
+            List includes = new ArrayList();
+            for (int i = 0; i < files.length; i++)
+            {
+                File f = files[i];
+                f.deleteOnExit();
+                if (f.getName().equals("web.xml"))
+                {
+                    webXmlFile = f;
+                }
+                else
+                {
+                    includes.add(f.getName());
+                }
+            }
+            String[] strIncludes = new String[includes.size()];
+            int i=0;
+            for(Iterator iter = includes.iterator(); iter.hasNext();)
+            {
+               strIncludes[i] = iter.next().toString();
+               i++;
+            }
+            try {
+                               warArchiver.addWebinf(tmpDir, strIncludes,null);
+                       } catch (ArchiverException e) {
+                               throw new MojoExecutionException(
+                               "Error reading the source archive.", e);
+                       }
+        }
+        catch (IOException ioe)
+        {
+            throw new MojoExecutionException(
+                "Could not write temporary deployment descriptor", ioe);
+        }
+        return webXmlFile;
+    }
+    
+    /**
+     * A method to create the temporary files.
+     * 
+     * @param thePrefix the prefix of the filename.
+     * @param theSuffix the suffix of the filename
+     * @param theParentDir the parent directory
+     * @param isDeleteOnExit should we delete the directories on exit?
+     * @return the temporary file
+     */
+    public File createTempFile(String thePrefix, String theSuffix, 
+                                   File theParentDir, boolean isDeleteOnExit) 
+    {
+    File result = null;
+    String parent = (theParentDir == null)
+            ? System.getProperty("java.io.tmpdir")
+            : theParentDir.getPath();
+
+        DecimalFormat fmt = new DecimalFormat("#####");
+        synchronized (rand) 
+        {
+            do 
+            {
+                result = new File(parent,
+                   thePrefix + fmt.format(Math.abs(rand.nextInt()))
+                   + theSuffix);
+            } 
+            while (result.exists());
+        }
+        if (isDeleteOnExit) 
+        {
+            result.deleteOnExit();
+        }
+        return result;
+    }
+    
+    /**
+     * Adds the Cactus JSP redirector file to the web application.
+     */
+    private void addJspRedirector()
+    {
+        // Now copy the actual JSP redirector file into the web application
+        File jspRedirectorFile = new File(
+            new File(System.getProperty("java.io.tmpdir")),
+            "jspRedirector.jsp");
+        jspRedirectorFile.deleteOnExit();
+        try
+        {
+            utils.copyResource("/org/apache/cactus/server/jspRedirector.jsp",
+                jspRedirectorFile);
+        }
+        catch (IOException e)
+        {
+            getLog().warn("Could not copy the JSP redirector (" + 
+                       e.getMessage() + ")");
+        }
+        try {
+                       warArchiver.addFile(jspRedirectorFile, 
jspRedirectorFile.getName());
+               } catch (ArchiverException e) {
+                       // TODO Auto-generated catch block
+                       e.printStackTrace();
+               }
+    }
+
+    /**
+     * Adds the JAR file containing the specified resource to the WEB-INF/lib
+     * folder of a web-application archive.
+     * 
+     * @param theClassName The name of the class that the JAR contains
+     * @param theDescription A description of the JAR that should be displayed
+     *        to the user in log messages
+     */
+    private File addJarWithClass(String theClassName, String theDescription)
+    {
+        String resourceName = "/" + theClassName.replace('.', '/') + ".class";
+        if (srcFile != null)
+        {
+            try
+            {
+                WarArchive srcWar = new DefaultWarArchive(
+                    new FileInputStream(srcFile));
+                if (srcWar.containsClass(theClassName))
+                {
+                    getLog().debug("The " + theDescription + " JAR is " +
+                               "already present in the WAR");
+                    return null;
+                }
+            }
+            catch (IOException ioe)
+            {
+                getLog().warn("Problem reading source WAR to when " +
+                       "trying to detect already present JAR files (" + ioe + 
")");
+            }
+        }
+        File file = utils.getResourceLocation(resourceName);
+        return file;   
+    }
+    
+    /**
+     * Extracts and parses the original web deployment descriptor from the
+     * web-app.
+     * 
+     * @return The parsed descriptor or null if not found
+     * @throws MojoExecutionException If the descriptor could not be 
+     *         parsed
+     * @throws JDOMException in case is JDOM exception is thrown.
+     */
+    private WebXml getOriginalWebXml() throws MojoExecutionException, 
+                                                                               
  JDOMException
+    {
+        // Open the archive as JAR file and extract the deployment descriptor
+        WarArchive war = null;
+        try
+        {
+            war = new DefaultWarArchive(new FileInputStream(this.srcFile));
+            WebXml webXml = war.getWebXml();
+            return webXml;
+        }
+        catch (IOException e)
+        {
+            throw new MojoExecutionException("Failed to open WAR", e);
+        }
+    }
+    
+    /**
+     * Add ejb references to a web.xml.
+     * 
+     * @param theWebXml the web.xml to modify
+     */
+    private void addEjbRefs(WebXml theWebXml)
+    {
+        Iterator i = ejbRefs.iterator();
+        while (i.hasNext())
+        {
+            EjbRef ref = (EjbRef) i.next();
+            WebXmlUtils.addEjbRef(theWebXml, ref);
+        }
+    }
+    
+    /**
+     * Getter method for the MavenProject.
+     * @return the MavenProject
+     */
+    public MavenProject getProject()
+    {
+        return project;
+    }
+    
+    /**
+     * Getter method for the MavenArchiveConfiguration.
+     * @return the MavenArchiveConfiguration
+     */
+    public MavenArchiveConfiguration getArchive()
+    {
+        return archive;
+    }
+}
\ No newline at end of file

Propchange: 
jakarta/cactus/trunk/integration/maven2/src/main/java/org/apache/cactus/maven2/mojos/CactifyWarMojo.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: 
jakarta/cactus/trunk/integration/maven2/src/main/java/org/apache/cactus/maven2/mojos/Dependency.java
URL: 
http://svn.apache.org/viewvc/jakarta/cactus/trunk/integration/maven2/src/main/java/org/apache/cactus/maven2/mojos/Dependency.java?rev=653066&view=auto
==============================================================================
--- 
jakarta/cactus/trunk/integration/maven2/src/main/java/org/apache/cactus/maven2/mojos/Dependency.java
 (added)
+++ 
jakarta/cactus/trunk/integration/maven2/src/main/java/org/apache/cactus/maven2/mojos/Dependency.java
 Sat May  3 05:42:29 2008
@@ -0,0 +1,43 @@
+package org.apache.cactus.maven2.mojos;
+
+import java.io.File;
+
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.logging.Log;
+import org.apache.maven.project.MavenProject;
+
+/**
+ * 
+ * Dependency that we use for the lib folder add-on's.
+ *
+ */
+public class Dependency 
+extends org.codehaus.cargo.maven2.configuration.Dependency 
+{
+    public String getDependencyPath(MavenProject project, Log log) throws 
MojoExecutionException
+    {
+        String path = getLocation();
+
+        if (path == null)
+        {
+            if ((getGroupId() == null) || (getArtifactId() == null))
+            {
+                throw new MojoExecutionException("You must specify a 
groupId/artifactId or "
+                    + "a location that points to a directory or JAR");
+            }
+
+            // Default to jar if not type is specified
+            if (getType() == null)
+            {
+                setType("jar");
+            }
+
+            path = findArtifactLocation(project.getArtifacts(), log);
+        }
+
+        log.debug("Classpath location = [" + new File(path).getPath() + "]");
+
+        return new File(path).getPath();
+    }  
+
+}

Propchange: 
jakarta/cactus/trunk/integration/maven2/src/main/java/org/apache/cactus/maven2/mojos/Dependency.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: 
jakarta/cactus/trunk/integration/maven2/src/main/java/org/apache/cactus/maven2/mojos/EjbRef.java
URL: 
http://svn.apache.org/viewvc/jakarta/cactus/trunk/integration/maven2/src/main/java/org/apache/cactus/maven2/mojos/EjbRef.java?rev=653066&view=auto
==============================================================================
--- 
jakarta/cactus/trunk/integration/maven2/src/main/java/org/apache/cactus/maven2/mojos/EjbRef.java
 (added)
+++ 
jakarta/cactus/trunk/integration/maven2/src/main/java/org/apache/cactus/maven2/mojos/EjbRef.java
 Sat May  3 05:42:29 2008
@@ -0,0 +1,27 @@
+/* 
+ * ========================================================================
+ * 
+ * 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.cactus.maven2.mojos;
+/**
+ * We extend the <code>org.codehaus.cargo.module.ejb.EjbDef</code> so that we 
+ * can define custom ejbRefs in our <code>pom.xml</code>. 
+ */
+public class EjbRef extends org.codehaus.cargo.module.ejb.EjbDef 
+{}

Propchange: 
jakarta/cactus/trunk/integration/maven2/src/main/java/org/apache/cactus/maven2/mojos/EjbRef.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: 
jakarta/cactus/trunk/integration/maven2/src/main/java/org/apache/cactus/maven2/mojos/FilterRedirector.java
URL: 
http://svn.apache.org/viewvc/jakarta/cactus/trunk/integration/maven2/src/main/java/org/apache/cactus/maven2/mojos/FilterRedirector.java?rev=653066&view=auto
==============================================================================
--- 
jakarta/cactus/trunk/integration/maven2/src/main/java/org/apache/cactus/maven2/mojos/FilterRedirector.java
 (added)
+++ 
jakarta/cactus/trunk/integration/maven2/src/main/java/org/apache/cactus/maven2/mojos/FilterRedirector.java
 Sat May  3 05:42:29 2008
@@ -0,0 +1,29 @@
+/* 
+ * ========================================================================
+ * 
+ * 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.cactus.maven2.mojos;
+
+/**
+ * We extend the <code>FilterRedirector</code> so that we can define custom
+ * redirector definitions in the <code>pom.xml</code>. 
+ */
+public class FilterRedirector 
+extends org.apache.cactus.integration.api.cactify.FilterRedirector 
+{}

Propchange: 
jakarta/cactus/trunk/integration/maven2/src/main/java/org/apache/cactus/maven2/mojos/FilterRedirector.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: 
jakarta/cactus/trunk/integration/maven2/src/main/java/org/apache/cactus/maven2/mojos/JspRedirector.java
URL: 
http://svn.apache.org/viewvc/jakarta/cactus/trunk/integration/maven2/src/main/java/org/apache/cactus/maven2/mojos/JspRedirector.java?rev=653066&view=auto
==============================================================================
--- 
jakarta/cactus/trunk/integration/maven2/src/main/java/org/apache/cactus/maven2/mojos/JspRedirector.java
 (added)
+++ 
jakarta/cactus/trunk/integration/maven2/src/main/java/org/apache/cactus/maven2/mojos/JspRedirector.java
 Sat May  3 05:42:29 2008
@@ -0,0 +1,29 @@
+/* 
+ * ========================================================================
+ * 
+ * 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.cactus.maven2.mojos;
+
+/**
+ * We extend the <code>JspRedirector</code> so that we can define custom
+ * redirector definitions in the <code>pom.xml</code>. 
+ */
+public class JspRedirector 
+extends org.apache.cactus.integration.api.cactify.JspRedirector
+{}

Propchange: 
jakarta/cactus/trunk/integration/maven2/src/main/java/org/apache/cactus/maven2/mojos/JspRedirector.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: 
jakarta/cactus/trunk/integration/maven2/src/main/java/org/apache/cactus/maven2/mojos/ServletRedirector.java
URL: 
http://svn.apache.org/viewvc/jakarta/cactus/trunk/integration/maven2/src/main/java/org/apache/cactus/maven2/mojos/ServletRedirector.java?rev=653066&view=auto
==============================================================================
--- 
jakarta/cactus/trunk/integration/maven2/src/main/java/org/apache/cactus/maven2/mojos/ServletRedirector.java
 (added)
+++ 
jakarta/cactus/trunk/integration/maven2/src/main/java/org/apache/cactus/maven2/mojos/ServletRedirector.java
 Sat May  3 05:42:29 2008
@@ -0,0 +1,28 @@
+/* 
+ * ========================================================================
+ * 
+ * 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.cactus.maven2.mojos;
+
+/**
+ * We extend the <code>ServletRedirector</code> so that we can define custom
+ * redirector definitions in the <code>pom.xml</code>. 
+ */
+public class ServletRedirector 
+extends org.apache.cactus.integration.api.cactify.ServletRedirector {}

Propchange: 
jakarta/cactus/trunk/integration/maven2/src/main/java/org/apache/cactus/maven2/mojos/ServletRedirector.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: jakarta/cactus/trunk/integration/pom.xml
URL: 
http://svn.apache.org/viewvc/jakarta/cactus/trunk/integration/pom.xml?rev=653066&r1=653065&r2=653066&view=diff
==============================================================================
--- jakarta/cactus/trunk/integration/pom.xml (original)
+++ jakarta/cactus/trunk/integration/pom.xml Sat May  3 05:42:29 2008
@@ -31,6 +31,7 @@
                <module>shared-api</module>
                <module>ant</module>
                <module>maven</module>
+               <module>maven2</module>
     <module>eclipse</module>
        </modules>
        <build>

Modified: jakarta/cactus/trunk/integration/shared-api/pom.xml
URL: 
http://svn.apache.org/viewvc/jakarta/cactus/trunk/integration/shared-api/pom.xml?rev=653066&r1=653065&r2=653066&view=diff
==============================================================================
--- jakarta/cactus/trunk/integration/shared-api/pom.xml (original)
+++ jakarta/cactus/trunk/integration/shared-api/pom.xml Sat May  3 05:42:29 2008
@@ -39,6 +39,11 @@
                        <version>1.6.5</version>
                </dependency>
                <dependency>
+                       <groupId>jdom</groupId>
+                       <artifactId>jdom</artifactId>
+                       <version>1.0</version>
+               </dependency>
+               <dependency>
                        <groupId>org.codehaus.cargo</groupId>
                        <artifactId>cargo-core-uberjar</artifactId>
                </dependency>

Modified: 
jakarta/cactus/trunk/integration/shared-api/src/main/java/org/apache/cactus/container/ContainerRunner.java
URL: 
http://svn.apache.org/viewvc/jakarta/cactus/trunk/integration/shared-api/src/main/java/org/apache/cactus/container/ContainerRunner.java?rev=653066&r1=653065&r2=653066&view=diff
==============================================================================
--- 
jakarta/cactus/trunk/integration/shared-api/src/main/java/org/apache/cactus/container/ContainerRunner.java
 (original)
+++ 
jakarta/cactus/trunk/integration/shared-api/src/main/java/org/apache/cactus/container/ContainerRunner.java
 Sat May  3 05:42:29 2008
@@ -25,7 +25,7 @@
 import java.net.HttpURLConnection;
 import java.net.URL;
 
-import org.apache.cactus.integration.api.exception.CactusRuntimeException;
+import org.apache.cactus.integration.api.exceptions.CactusRuntimeException;
 import org.codehaus.cargo.util.log.Logger;
 
 /**

Added: 
jakarta/cactus/trunk/integration/shared-api/src/main/java/org/apache/cactus/integration/api/cactify/CactifyUtils.java
URL: 
http://svn.apache.org/viewvc/jakarta/cactus/trunk/integration/shared-api/src/main/java/org/apache/cactus/integration/api/cactify/CactifyUtils.java?rev=653066&view=auto
==============================================================================
--- 
jakarta/cactus/trunk/integration/shared-api/src/main/java/org/apache/cactus/integration/api/cactify/CactifyUtils.java
 (added)
+++ 
jakarta/cactus/trunk/integration/shared-api/src/main/java/org/apache/cactus/integration/api/cactify/CactifyUtils.java
 Sat May  3 05:42:29 2008
@@ -0,0 +1,121 @@
+package org.apache.cactus.integration.api.cactify;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.util.Iterator;
+import java.util.List;
+
+import org.codehaus.cargo.container.internal.util.ResourceUtils;
+import org.codehaus.cargo.module.webapp.DefaultWarArchive;
+import org.codehaus.cargo.module.webapp.WarArchive;
+import org.codehaus.cargo.module.webapp.WebXml;
+import org.codehaus.cargo.util.internal.log.AbstractLogger;
+
+/**
+ * Util class for cactifying purposes.
+ * @author tahchiev
+ */
+public class CactifyUtils {
+       
+    /**
+     * The cargo ResourceUtils.
+     */
+    private ResourceUtils utils = new ResourceUtils();
+    /**
+     * The abstract cargo logger used both by Ant and Maven2.
+     */
+    private AbstractLogger logger;
+       
+
+    /**
+     * Log debug the given message.
+     * @param msg
+     */
+    public void debug(String msg)
+    {
+       getLogger().debug(msg, this.getClass().getName());
+    }
+    /**
+     * Log info the given message.
+     * @param msg
+     */
+    public void info(String msg)
+    {
+       getLogger().info(msg, this.getClass().getName());
+    }
+    /**
+     * Log warn the given message.
+     * @param msg
+     */
+    public void warn(String msg)
+    {
+       getLogger().warn(msg, this.getClass().getName());
+    }
+    
+    /**
+     * Adds the definitions corresponding to the nested redirector elements to
+     * the provided deployment descriptor. 
+     * 
+     * @param theWebXml The deployment descriptor
+     */
+    public void addRedirectorDefinitions(WebXml theWebXml, List redirectors)
+    {
+        boolean filterRedirectorDefined = false;
+        boolean jspRedirectorDefined = false;
+        boolean servletRedirectorDefined = false;
+        
+        // add the user defined redirectors
+        for (Iterator i = redirectors.iterator(); i.hasNext();)
+        {
+        
+            Redirector redirector = (Redirector) i.next();
+            if (redirector instanceof FilterRedirector)
+            {
+                filterRedirectorDefined = true;
+            }
+            else if (redirector instanceof JspRedirector)
+            {
+                jspRedirectorDefined = true;
+            }
+            else if (redirector instanceof ServletRedirector)
+            {
+                servletRedirectorDefined = true;
+            }
+            redirector.mergeInto(theWebXml);
+        }
+
+        // now add the default redirectors if they haven't been provided by
+        // the user
+        if (!filterRedirectorDefined)
+        {
+            new FilterRedirector(getLogger())
+                .mergeInto(theWebXml);
+        }
+        if (!servletRedirectorDefined)
+        {
+            new ServletRedirector(getLogger())
+                .mergeInto(theWebXml);
+        }
+        if (!jspRedirectorDefined)
+        {
+            new JspRedirector(getLogger()).mergeInto(theWebXml);
+        }
+    }
+    /**
+     * Getter method for the logger.
+     * @return AbstractLogger
+     */
+       public AbstractLogger getLogger() {
+               return logger;
+       }
+       
+       /**
+        * Setter method for the logger.
+        * @param logger
+        */
+       public void setLogger(AbstractLogger logger) {
+               this.logger = logger;
+       }
+
+}

Propchange: 
jakarta/cactus/trunk/integration/shared-api/src/main/java/org/apache/cactus/integration/api/cactify/CactifyUtils.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: 
jakarta/cactus/trunk/integration/shared-api/src/main/java/org/apache/cactus/integration/api/cactify/FilterRedirector.java
URL: 
http://svn.apache.org/viewvc/jakarta/cactus/trunk/integration/shared-api/src/main/java/org/apache/cactus/integration/api/cactify/FilterRedirector.java?rev=653066&r1=653065&r2=653066&view=diff
==============================================================================
--- 
jakarta/cactus/trunk/integration/shared-api/src/main/java/org/apache/cactus/integration/api/cactify/FilterRedirector.java
 (original)
+++ 
jakarta/cactus/trunk/integration/shared-api/src/main/java/org/apache/cactus/integration/api/cactify/FilterRedirector.java
 Sat May  3 05:42:29 2008
@@ -21,13 +21,16 @@
 package org.apache.cactus.integration.api.cactify;
 
 import org.codehaus.cargo.module.webapp.WebXml;
+import org.codehaus.cargo.module.webapp.WebXmlTag;
+import org.codehaus.cargo.module.webapp.WebXmlUtils;
 import org.codehaus.cargo.module.webapp.WebXmlVersion;
+import org.codehaus.cargo.module.webapp.elements.FilterMapping;
 import org.codehaus.cargo.util.log.Logger;
 
 /**
  * Implementation of <code>Redirector</code> for filter test redirectors. 
  */
-public final class FilterRedirector extends Redirector
+public class FilterRedirector extends Redirector
 {
 
     /**
@@ -66,17 +69,50 @@
      */
     public void mergeInto(WebXml theWebXml)
     {
+       //If no version is specified then we accept the version is 2.2
+       //and we don't add the filter redirector.
+       if(theWebXml.getVersion() == null)
+               return;
         if (WebXmlVersion.V2_3.compareTo(theWebXml.getVersion()) <= 0)
         {
-            if (theWebXml.getFilterNamesForClass
-                (FILTER_REDIRECTOR_CLASS).hasNext() && logger != null) 
+            if (WebXmlUtils.getFilterNamesForClass
+                (theWebXml,FILTER_REDIRECTOR_CLASS).hasNext() && logger != 
null) 
             {
                 logger.warn("WARNING: Your web.xml already includes " 
                 + this.name + " mapping. Cactus is adding another one " 
                 + "which may prevent your container from starting.", 
"WARNING");
             }
-            theWebXml.addFilter(this.name, FILTER_REDIRECTOR_CLASS);
-            theWebXml.addFilterMapping(this.name, this.mapping);
+            WebXmlUtils.addFilter(theWebXml, this.name, 
FILTER_REDIRECTOR_CLASS);
+              
+            
+//             WebXmlTag s = new WebXmlTag(theWebXml.getDescriptorType(), "");
+            
+//            Iterator iter = WebXmlUtils.getFilterMappingElements(theWebXml, 
name);
+            
+            
+            //Element filterMappingElement =
+            //    
theWebXml.getDocument().createElement(WebXmlType.FILTER_MAPPING);
+            
//filterMappingElement.appendChild(createNestedText(WebXmlTag.FILTER_NAME, 
filterName));
+            
//filterMappingElement.appendChild(createNestedText(WebXmlTag.URL_PATTERN, 
urlPattern));
+            //addElement(WebXmlTag.FILTER_MAPPING, filterMappingElement, 
getRootElement());
+            
+            
+            WebXmlTag tag = 
(WebXmlTag)theWebXml.getDescriptorType().getTagByName("filter-mapping");
+            FilterMapping filterMapping = new FilterMapping(tag);
+            filterMapping.setName(this.name);
+            filterMapping.setUrlPattern(this.mapping);
+            filterMapping.setFilterName(this.name);
+            
+            
+            theWebXml.addTag(filterMapping);
+//            
+//            theWebXml.addTag(filterM);
+//            
+//            FilterMapping filterMapping = new FilterMapping();
+
+
+            
+            WebXmlUtils.addFilterMapping(theWebXml, filterMapping);
             if (this.roles != null)
             {
                 addSecurity(theWebXml);

Modified: 
jakarta/cactus/trunk/integration/shared-api/src/main/java/org/apache/cactus/integration/api/cactify/JspRedirector.java
URL: 
http://svn.apache.org/viewvc/jakarta/cactus/trunk/integration/shared-api/src/main/java/org/apache/cactus/integration/api/cactify/JspRedirector.java?rev=653066&r1=653065&r2=653066&view=diff
==============================================================================
--- 
jakarta/cactus/trunk/integration/shared-api/src/main/java/org/apache/cactus/integration/api/cactify/JspRedirector.java
 (original)
+++ 
jakarta/cactus/trunk/integration/shared-api/src/main/java/org/apache/cactus/integration/api/cactify/JspRedirector.java
 Sat May  3 05:42:29 2008
@@ -21,12 +21,13 @@
 package org.apache.cactus.integration.api.cactify;
 
 import org.codehaus.cargo.module.webapp.WebXml;
+import org.codehaus.cargo.module.webapp.WebXmlUtils;
 import org.codehaus.cargo.util.log.Logger;
 
 /**
  * Implementation of <code>Redirector</code> for JSP test redirectors. 
  */
-public final class JspRedirector extends Redirector
+public class JspRedirector extends Redirector
 {
     /**
      * The default mapping of the Cactus JSP redirector.
@@ -60,15 +61,15 @@
     public void mergeInto(WebXml theWebXml)
     {
         //The iterator is never null
-        if (theWebXml.getServletNamesForJspFile
-                ("/jspRedirector.jsp").hasNext() && logger != null) 
+        if (WebXmlUtils.getServletNamesForJspFile
+                (theWebXml, "/jspRedirector.jsp").hasNext() && logger != null) 
         {
             logger.warn("WARNING: Your web.xml already includes " 
             + this.name + " mapping. Cactus is adding another one " 
             + "which may prevent your container from starting.", "WARNING");
         }
-        theWebXml.addJspFile(this.name, "/jspRedirector.jsp");
-        theWebXml.addServletMapping(this.name, this.mapping);
+        WebXmlUtils.addJspFile(theWebXml, this.name, "/jspRedirector.jsp");
+        WebXmlUtils.addServletMapping(theWebXml, this.name, this.mapping);
         if (this.roles != null)
         {
             addSecurity(theWebXml);

Modified: 
jakarta/cactus/trunk/integration/shared-api/src/main/java/org/apache/cactus/integration/api/cactify/Redirector.java
URL: 
http://svn.apache.org/viewvc/jakarta/cactus/trunk/integration/shared-api/src/main/java/org/apache/cactus/integration/api/cactify/Redirector.java?rev=653066&r1=653065&r2=653066&view=diff
==============================================================================
--- 
jakarta/cactus/trunk/integration/shared-api/src/main/java/org/apache/cactus/integration/api/cactify/Redirector.java
 (original)
+++ 
jakarta/cactus/trunk/integration/shared-api/src/main/java/org/apache/cactus/integration/api/cactify/Redirector.java
 Sat May  3 05:42:29 2008
@@ -25,6 +25,7 @@
 import java.util.StringTokenizer;
 
 import org.codehaus.cargo.module.webapp.WebXml;
+import org.codehaus.cargo.module.webapp.WebXmlUtils;
 import org.codehaus.cargo.util.log.Logger;
 
 /**
@@ -132,21 +133,21 @@
         while (tokenizer.hasMoreTokens())
         {
             String role = tokenizer.nextToken().trim();
-            if (!theWebXml.hasSecurityRole(role))
+            if (!WebXmlUtils.hasSecurityRole(theWebXml,role))
             {
-                theWebXml.addSecurityRole(role);
+                WebXmlUtils.addSecurityRole(theWebXml,role);
             }
             roles.add(role);
         }
         if (!roles.isEmpty())
         {
-            if (!theWebXml.hasLoginConfig())
+            if (!WebXmlUtils.hasLoginConfig(theWebXml))
             {
-                theWebXml.setLoginConfig("BASIC", "myrealm");
+                WebXmlUtils.setLoginConfig(theWebXml, "BASIC", "myrealm");
             }
-            if (!theWebXml.hasSecurityConstraint(this.mapping))
+            if (!WebXmlUtils.hasSecurityConstraint(theWebXml,this.mapping))
             {
-                theWebXml.addSecurityConstraint("Cactus Test Redirector",
+                WebXmlUtils.addSecurityConstraint(theWebXml,"Cactus Test 
Redirector",
                     this.mapping, roles);
             }
         }

Modified: 
jakarta/cactus/trunk/integration/shared-api/src/main/java/org/apache/cactus/integration/api/cactify/ServletRedirector.java
URL: 
http://svn.apache.org/viewvc/jakarta/cactus/trunk/integration/shared-api/src/main/java/org/apache/cactus/integration/api/cactify/ServletRedirector.java?rev=653066&r1=653065&r2=653066&view=diff
==============================================================================
--- 
jakarta/cactus/trunk/integration/shared-api/src/main/java/org/apache/cactus/integration/api/cactify/ServletRedirector.java
 (original)
+++ 
jakarta/cactus/trunk/integration/shared-api/src/main/java/org/apache/cactus/integration/api/cactify/ServletRedirector.java
 Sat May  3 05:42:29 2008
@@ -21,12 +21,13 @@
 package org.apache.cactus.integration.api.cactify;
 
 import org.codehaus.cargo.module.webapp.WebXml;
+import org.codehaus.cargo.module.webapp.WebXmlUtils;
 import org.codehaus.cargo.util.log.Logger;
 
 /**
  * Implementation of <code>Redirector</code> for servlet test redirectors. 
  */
-public final class ServletRedirector extends Redirector
+public class ServletRedirector extends Redirector
 {
 
     /**
@@ -64,15 +65,15 @@
      */
     public void mergeInto(WebXml theWebXml)
     {
-        if (theWebXml.getServletNamesForClass
-            (SERVLET_REDIRECTOR_CLASS).hasNext() && logger != null) 
+        if (WebXmlUtils.getServletNamesForClass
+            (theWebXml, SERVLET_REDIRECTOR_CLASS).hasNext() && logger != null) 
         {
             logger.warn("WARNING: Your web.xml already includes " 
             + this.name + " mapping. Cactus is adding another one " 
             + "which may prevent your container from starting.", "WARNING");
         }
-        theWebXml.addServlet(this.name, SERVLET_REDIRECTOR_CLASS);
-        theWebXml.addServletMapping(this.name, this.mapping);
+        WebXmlUtils.addServlet(theWebXml, this.name, SERVLET_REDIRECTOR_CLASS);
+        WebXmlUtils.addServletMapping(theWebXml, this.name, this.mapping);
         if (this.roles != null)
         {
             addSecurity(theWebXml);

Modified: 
jakarta/cactus/trunk/integration/shared-api/src/main/java/org/apache/cactus/integration/api/deployable/EarParser.java
URL: 
http://svn.apache.org/viewvc/jakarta/cactus/trunk/integration/shared-api/src/main/java/org/apache/cactus/integration/api/deployable/EarParser.java?rev=653066&r1=653065&r2=653066&view=diff
==============================================================================
--- 
jakarta/cactus/trunk/integration/shared-api/src/main/java/org/apache/cactus/integration/api/deployable/EarParser.java
 (original)
+++ 
jakarta/cactus/trunk/integration/shared-api/src/main/java/org/apache/cactus/integration/api/deployable/EarParser.java
 Sat May  3 05:42:29 2008
@@ -27,11 +27,12 @@
 
 import javax.xml.parsers.ParserConfigurationException;
 
-import org.apache.tools.ant.BuildException;
+import org.apache.cactus.integration.api.exceptions.CactusRuntimeException;
 import org.codehaus.cargo.module.application.ApplicationXml;
 import org.codehaus.cargo.module.application.DefaultEarArchive;
 import org.codehaus.cargo.module.application.EarArchive;
 import org.codehaus.cargo.module.webapp.WarArchive;
+import org.jdom.JDOMException;
 import org.xml.sax.SAXException;
 
 /**
@@ -62,14 +63,14 @@
             String webUri = getUriOfCactifiedWebModule(earArchive);
             if (webUri == null)
             {
-                throw new BuildException("Could not find cactified web "
+                throw new CactusRuntimeException("Could not find cactified web 
"
                     + "module in the [" + theDeployableFile + "] EAR.");
             }
 
             WarArchive warArchive = earArchive.getWebModule(webUri);
             if (warArchive == null)
             {
-                throw new BuildException("Could not find the WAR [" + webUri
+                throw new CactusRuntimeException("Could not find the WAR [" + 
webUri
                     + "] in the [" + theDeployableFile + "] EAR.");
             }
             
@@ -87,17 +88,22 @@
         }
         catch (IOException e)
         {
-            throw new BuildException("Failed to parse deployment descriptor "
+            throw new CactusRuntimeException("Failed to parse deployment 
descriptor "
                 + "for EAR file [" + theDeployableFile + "].", e);
         }
         catch (ParserConfigurationException e)
         {
-            throw new BuildException("Failed to parse deployment descriptor "
+            throw new CactusRuntimeException("Failed to parse deployment 
descriptor "
                 + "for EAR file [" + theDeployableFile + "].", e);
         }
         catch (SAXException e)
         {
-            throw new BuildException("Failed to parse deployment descriptor "
+            throw new CactusRuntimeException("Failed to parse deployment 
descriptor "
+                + "for EAR file [" + theDeployableFile + "].", e);
+        }
+        catch (JDOMException e)
+        {
+            throw new CactusRuntimeException("Failed to parse deployment 
descriptor "
                 + "for EAR file [" + theDeployableFile + "].", e);
         }
         
@@ -117,10 +123,11 @@
      *         be parsed
      * @throws ParserConfigurationException If there is an XML parser
      *         configration problem
+     * @throws JDOMException 
      */
     protected static final String parseTestContext(EarArchive theEar, 
         String theWebUri) 
-        throws ParserConfigurationException, IOException, SAXException
+        throws ParserConfigurationException, IOException, SAXException, 
JDOMException
     {
         String context = theEar.getApplicationXml()
             .getWebModuleContextRoot(theWebUri);
@@ -128,7 +135,7 @@
         {
             // The application.xml does not define a <context-root> element.
             // This is wrong!
-            throw new BuildException("Your application.xml must define a "
+            throw new CactusRuntimeException("Your application.xml must define 
a "
                 + "<context-root> element in the <web> module definition.");
         }
 
@@ -157,9 +164,10 @@
      *         be parsed
      * @throws ParserConfigurationException If there is an XML parser
      *         configration problem
+     * @throws JDOMException 
      */
     protected static final String getUriOfCactifiedWebModule(EarArchive theEar)
-        throws SAXException, IOException, ParserConfigurationException
+        throws SAXException, IOException, ParserConfigurationException, 
JDOMException
     {
         ApplicationXml applicationXml = theEar.getApplicationXml();
         for (Iterator i = applicationXml.getWebModuleUris(); i.hasNext();)

Modified: 
jakarta/cactus/trunk/integration/shared-api/src/main/java/org/apache/cactus/integration/api/deployable/WarParser.java
URL: 
http://svn.apache.org/viewvc/jakarta/cactus/trunk/integration/shared-api/src/main/java/org/apache/cactus/integration/api/deployable/WarParser.java?rev=653066&r1=653065&r2=653066&view=diff
==============================================================================
--- 
jakarta/cactus/trunk/integration/shared-api/src/main/java/org/apache/cactus/integration/api/deployable/WarParser.java
 (original)
+++ 
jakarta/cactus/trunk/integration/shared-api/src/main/java/org/apache/cactus/integration/api/deployable/WarParser.java
 Sat May  3 05:42:29 2008
@@ -27,9 +27,11 @@
 
 import javax.xml.parsers.ParserConfigurationException;
 
-import org.apache.tools.ant.BuildException;
+import org.apache.cactus.integration.api.exceptions.CactusRuntimeException;
 import org.codehaus.cargo.module.webapp.DefaultWarArchive;
 import org.codehaus.cargo.module.webapp.WarArchive;
+import org.codehaus.cargo.module.webapp.WebXmlUtils;
+import org.jdom.JDOMException;
 import org.xml.sax.SAXException;
 
 /**
@@ -66,17 +68,22 @@
         }
         catch (IOException e)
         {
-            throw new BuildException("Failed to parse deployment descriptor "
+            throw new CactusRuntimeException("Failed to parse deployment 
descriptor "
                 + "for WAR file [" + theDeployableFile + "].", e);
         }
         catch (ParserConfigurationException e)
         {
-            throw new BuildException("Failed to parse deployment descriptor "
+            throw new CactusRuntimeException("Failed to parse deployment 
descriptor "
                 + "for WAR file [" + theDeployableFile + "].", e);
         }
         catch (SAXException e)
         {
-            throw new BuildException("Failed to parse deployment descriptor "
+            throw new CactusRuntimeException("Failed to parse deployment 
descriptor "
+                + "for WAR file [" + theDeployableFile + "].", e);
+        }
+        catch (JDOMException e)
+        {
+            throw new CactusRuntimeException("Failed to parse deployment 
descriptor "
                 + "for WAR file [" + theDeployableFile + "].", e);
         }
         
@@ -113,18 +120,19 @@
      *         be parsed
      * @throws ParserConfigurationException If there is an XML parser
      *         configration problem
+     * @throws JDOMException 
      */
     static String parseServletRedirectorMapping(WarArchive theWar)
-        throws SAXException, IOException, ParserConfigurationException
+        throws SAXException, IOException, ParserConfigurationException, 
JDOMException
     {
-        Iterator servletNames = theWar.getWebXml().getServletNamesForClass(
+        Iterator servletNames = 
WebXmlUtils.getServletNamesForClass(theWar.getWebXml(),
             "org.apache.cactus.server.ServletTestRedirector");
         if (servletNames.hasNext())
         {
             // we iterate over all of the servlet names but return the first 
met only --//TODO to be fixed
             while(servletNames.hasNext()) {
                        String name = (String) servletNames.next(); 
-                   Iterator mappings = 
theWar.getWebXml().getServletMappings(name);
+                   Iterator mappings = 
WebXmlUtils.getServletMappings(theWar.getWebXml(), name);
                    if (mappings.hasNext())
                    {
                        return (String) mappings.next();
@@ -148,17 +156,18 @@
      *         be parsed
      * @throws ParserConfigurationException If there is an XML parser
      *         configration problem
+     * @throws JDOMException 
      */
     static String parseFilterRedirectorMapping(WarArchive theWar)
-        throws IOException, SAXException, ParserConfigurationException
+        throws IOException, SAXException, ParserConfigurationException, 
JDOMException
     {
-        Iterator filterNames = theWar.getWebXml().getFilterNamesForClass(
+        Iterator filterNames = 
WebXmlUtils.getFilterNamesForClass(theWar.getWebXml(),
             "org.apache.cactus.server.FilterTestRedirector");
         if (filterNames.hasNext())
         {
             // we only care about the first definition and the first mapping
             String name = (String) filterNames.next(); 
-            Iterator mappings = theWar.getWebXml().getFilterMappings(name);
+            Iterator mappings = 
WebXmlUtils.getFilterMappings(theWar.getWebXml(), name);
             if (mappings.hasNext())
             {
                 return (String) mappings.next();
@@ -181,9 +190,10 @@
      *         be parsed
      * @throws ParserConfigurationException If there is an XML parser
      *         configration problem
+     * @throws JDOMException 
      */
     static String parseJspRedirectorMapping(WarArchive theWar)
-        throws IOException, SAXException, ParserConfigurationException
+        throws IOException, SAXException, ParserConfigurationException, 
JDOMException
     {
         // To get the JSP redirector mapping, we must first get the full path 
to
         // the corresponding JSP file in the WAR
@@ -191,7 +201,7 @@
         if (jspRedirectorPath != null)
         {
             jspRedirectorPath = "/" + jspRedirectorPath;
-            Iterator jspNames = theWar.getWebXml().getServletNamesForJspFile(
+            Iterator jspNames = 
WebXmlUtils.getServletNamesForClass(theWar.getWebXml(),
                 jspRedirectorPath);
             if (jspNames.hasNext())
             {
@@ -199,7 +209,7 @@
                 // mapping
                 String name = (String) jspNames.next(); 
                 Iterator mappings = 
-                    theWar.getWebXml().getServletMappings(name);
+                       WebXmlUtils.getServletMappings(theWar.getWebXml(),name);
                 if (mappings.hasNext())
                 {
                     return (String) mappings.next();

Added: 
jakarta/cactus/trunk/integration/shared-api/src/main/java/org/apache/cactus/integration/api/exceptions/CactusRuntimeException.java
URL: 
http://svn.apache.org/viewvc/jakarta/cactus/trunk/integration/shared-api/src/main/java/org/apache/cactus/integration/api/exceptions/CactusRuntimeException.java?rev=653066&view=auto
==============================================================================
--- 
jakarta/cactus/trunk/integration/shared-api/src/main/java/org/apache/cactus/integration/api/exceptions/CactusRuntimeException.java
 (added)
+++ 
jakarta/cactus/trunk/integration/shared-api/src/main/java/org/apache/cactus/integration/api/exceptions/CactusRuntimeException.java
 Sat May  3 05:42:29 2008
@@ -0,0 +1,43 @@
+/* 
+ * ========================================================================
+ * 
+ * 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.cactus.integration.api.exceptions;
+
+/**
+ * The custom cactus exception raised when internal
+ * cactus problem with the shared-api has happened.
+ * 
+ * @since 1.8.1 
+ * @author ptahchiev
+ */
+public class CactusRuntimeException extends RuntimeException
+{
+       private static final long serialVersionUID = 1L;
+
+       public CactusRuntimeException(String msg)
+       {
+               super(msg);
+       }
+       
+       public CactusRuntimeException(String msg, Exception ex)
+       {
+               super(msg, ex);
+       }
+}

Propchange: 
jakarta/cactus/trunk/integration/shared-api/src/main/java/org/apache/cactus/integration/api/exceptions/CactusRuntimeException.java
------------------------------------------------------------------------------
    svn:eol-style = native



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to