2011/08/05 - Jakarta Cactus has been retired.

For more information, please explore the Attic.

Clover coverage report - Cactus 1.8dev for J2EE API 1.3
Coverage timestamp: Sun Mar 26 2006 18:50:18 BRT
file stats: LOC: 207   Methods: 5
NCLOC: 108   Classes: 1
30 day Evaluation Version distributed via the Maven Jar Repository. Clover is not free. You have 30 days to evaluate it. Please visit http://www.thecortex.net/clover to obtain a licensed version of Clover
 
 Source file Conditionals Statements Methods TOTAL
WarParser.java 37.5% 68.3% 100% 62.9%
coverage coverage
 1   
 /* 
 2   
  * ========================================================================
 3   
  * 
 4   
  * Copyright 2003 The Apache Software Foundation.
 5   
  *
 6   
  * Licensed under the Apache License, Version 2.0 (the "License");
 7   
  * you may not use this file except in compliance with the License.
 8   
  * You may obtain a copy of the License at
 9   
  * 
 10   
  *   http://www.apache.org/licenses/LICENSE-2.0
 11   
  * 
 12   
  * Unless required by applicable law or agreed to in writing, software
 13   
  * distributed under the License is distributed on an "AS IS" BASIS,
 14   
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 15   
  * See the License for the specific language governing permissions and
 16   
  * limitations under the License.
 17   
  * 
 18   
  * ========================================================================
 19   
  */
 20   
 package org.apache.cactus.integration.ant.deployment;
 21   
 
 22   
 import java.io.File;
 23   
 import java.io.IOException;
 24   
 import java.util.Iterator;
 25   
 
 26   
 import javax.xml.parsers.ParserConfigurationException;
 27   
 
 28   
 import org.apache.cactus.integration.ant.deployment.webapp.DefaultWarArchive;
 29   
 import org.apache.cactus.integration.ant.deployment.webapp.WarArchive;
 30   
 import org.apache.tools.ant.BuildException;
 31   
 import org.xml.sax.SAXException;
 32   
 
 33   
 /**
 34   
  * Parse an WAR descriptor to extract meaninful information for Cactus,
 35   
  * the results being stored in a {@link WarDeployableFile} object. 
 36   
  * 
 37   
  * @since Cactus 1.5
 38   
  * @version $Id: WarParser.java 239003 2004-05-31 20:05:27Z vmassol $
 39   
  */
 40   
 public class WarParser
 41   
 {
 42   
     /**
 43   
      * Parse an WAR descriptor to extract meaninful information for Cactus.
 44   
      * 
 45   
      * @param theDeployableFile the file to parse and deploy
 46   
      * @return the parse results as a {@link WarDeployableFile} object
 47   
      */
 48  3
     public static final WarDeployableFile parse(File theDeployableFile)
 49   
     {
 50  3
         WarDeployableFile deployable = new WarDeployableFile();
 51   
 
 52  3
         try
 53   
         {
 54  3
             deployable.setFile(theDeployableFile);
 55  3
             deployable.setWarArchive(new DefaultWarArchive(theDeployableFile));
 56  2
             deployable.setTestContext(parseWebContext(theDeployableFile));
 57  2
             deployable.setServletRedirectorMapping(
 58   
                 parseServletRedirectorMapping(deployable.getWarArchive()));
 59  2
             deployable.setFilterRedirectorMapping(
 60   
                 parseFilterRedirectorMapping(deployable.getWarArchive()));
 61  2
             deployable.setJspRedirectorMapping(
 62   
                 parseJspRedirectorMapping(deployable.getWarArchive()));
 63   
         }
 64   
         catch (IOException e)
 65   
         {
 66  1
             throw new BuildException("Failed to parse deployment descriptor "
 67   
                 + "for WAR file [" + theDeployableFile + "].", e);
 68   
         }
 69   
         catch (ParserConfigurationException e)
 70   
         {
 71  0
             throw new BuildException("Failed to parse deployment descriptor "
 72   
                 + "for WAR file [" + theDeployableFile + "].", e);
 73   
         }
 74   
         catch (SAXException e)
 75   
         {
 76  0
             throw new BuildException("Failed to parse deployment descriptor "
 77   
                 + "for WAR file [" + theDeployableFile + "].", e);
 78   
         }
 79   
         
 80  2
         return deployable;
 81   
     }   
 82   
 
 83   
     /**
 84   
      * @param theDeployableFile the file to parse and deploy
 85   
      * @return the test context that will be used to verify if the container
 86   
      *         is started or not
 87   
      */
 88  2
     protected static String parseWebContext(File theDeployableFile)
 89   
     {
 90  2
         String context = theDeployableFile.getName();
 91  2
         int warIndex = context.toLowerCase().lastIndexOf(".war");
 92  2
         if (warIndex >= 0)
 93   
         {
 94  2
             context = context.substring(0, warIndex);
 95   
         }        
 96  2
         return context;
 97   
     }
 98   
     
 99   
     /**
 100   
      * Find the first URL-pattern to which the Cactus servlet redirector is 
 101   
      * mapped in the deployment descriptor.
 102   
      *
 103   
      * @return the servlet redirector mapping if found or <code>null</code>
 104   
      *         if not found
 105   
      * @param theWar the WAR descriptor that is parsed when looking for
 106   
      *        a Cactus servlet redirector mapping  
 107   
      * @throws IOException If there was a problem reading the deployment
 108   
      *         descriptor in the WAR
 109   
      * @throws SAXException If the deployment descriptor of the WAR could not
 110   
      *         be parsed
 111   
      * @throws ParserConfigurationException If there is an XML parser
 112   
      *         configration problem
 113   
      */
 114  7
     static String parseServletRedirectorMapping(WarArchive theWar)
 115   
         throws SAXException, IOException, ParserConfigurationException
 116   
     {
 117  7
         Iterator servletNames = theWar.getWebXml().getServletNamesForClass(
 118   
             "org.apache.cactus.server.ServletTestRedirector");
 119  7
         if (servletNames.hasNext())
 120   
         {
 121   
             // we only care about the first definition and the first mapping
 122  5
             String name = (String) servletNames.next(); 
 123  5
             Iterator mappings = theWar.getWebXml().getServletMappings(name);
 124  5
             if (mappings.hasNext())
 125   
             {
 126  5
                 return (String) mappings.next();
 127   
             }
 128   
         }        
 129  2
         return null;
 130   
     }
 131   
 
 132   
     /**
 133   
      * Find the first URL-pattern to which the Cactus filter redirector is 
 134   
      * mapped in the deployment descriptor.
 135   
      * 
 136   
      * @return the filter redirector mapping if found or <code>null</code>
 137   
      *         if not found
 138   
      * @param theWar the WAR descriptor that is parsed when looking for
 139   
      *        a Cactus filter redirector mapping  
 140   
      * @throws IOException If there was a problem reading the  deployment
 141   
      *         descriptor in the WAR
 142   
      * @throws SAXException If the deployment descriptor of the WAR could not
 143   
      *         be parsed
 144   
      * @throws ParserConfigurationException If there is an XML parser
 145   
      *         configration problem
 146   
      */
 147  4
     static String parseFilterRedirectorMapping(WarArchive theWar)
 148   
         throws IOException, SAXException, ParserConfigurationException
 149   
     {
 150  4
         Iterator filterNames = theWar.getWebXml().getFilterNamesForClass(
 151   
             "org.apache.cactus.server.FilterTestRedirector");
 152  4
         if (filterNames.hasNext())
 153   
         {
 154   
             // we only care about the first definition and the first mapping
 155  0
             String name = (String) filterNames.next(); 
 156  0
             Iterator mappings = theWar.getWebXml().getFilterMappings(name);
 157  0
             if (mappings.hasNext())
 158   
             {
 159  0
                 return (String) mappings.next();
 160   
             }
 161   
         }
 162  4
         return null;
 163   
     }
 164   
 
 165   
     /**
 166   
      * Find the first URL-pattern to which the Cactus JSP redirector is 
 167   
      * mapped in the deployment descriptor.
 168   
      * 
 169   
      * @return the JSP redirector mapping if found or <code>null</code>
 170   
      *         if not found
 171   
      * @param theWar the WAR descriptor that is parsed when looking for
 172   
      *        a Cactus JSP redirector mapping  
 173   
      * @throws IOException If there was a problem reading the  deployment
 174   
      *         descriptor in the WAR
 175   
      * @throws SAXException If the deployment descriptor of the WAR could not
 176   
      *         be parsed
 177   
      * @throws ParserConfigurationException If there is an XML parser
 178   
      *         configration problem
 179   
      */
 180  4
     static String parseJspRedirectorMapping(WarArchive theWar)
 181   
         throws IOException, SAXException, ParserConfigurationException
 182   
     {
 183   
         // To get the JSP redirector mapping, we must first get the full path to
 184   
         // the corresponding JSP file in the WAR
 185  4
         String jspRedirectorPath = theWar.findResource("jspRedirector.jsp");
 186  4
         if (jspRedirectorPath != null)
 187   
         {
 188  0
             jspRedirectorPath = "/" + jspRedirectorPath;
 189  0
             Iterator jspNames = theWar.getWebXml().getServletNamesForJspFile(
 190   
                 jspRedirectorPath);
 191  0
             if (jspNames.hasNext())
 192   
             {
 193   
                 // we only care about the first definition and the first
 194   
                 // mapping
 195  0
                 String name = (String) jspNames.next(); 
 196  0
                 Iterator mappings = 
 197   
                     theWar.getWebXml().getServletMappings(name);
 198  0
                 if (mappings.hasNext())
 199   
                 {
 200  0
                     return (String) mappings.next();
 201   
                 }
 202   
             }
 203   
         }
 204  4
         return null;
 205   
     }
 206   
 }
 207