dion        02/05/28 21:13:34

  Modified:    src/test/org/apache/maven/j2ee WarFileTest.java
               src/java/org/apache/maven/j2ee WarFile.java
  Log:
  Added support in WarFile for retrieving the servlet mappings
  
  Revision  Changes    Path
  1.6       +16 -1     
jakarta-turbine-maven/src/test/org/apache/maven/j2ee/WarFileTest.java
  
  Index: WarFileTest.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-turbine-maven/src/test/org/apache/maven/j2ee/WarFileTest.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- WarFileTest.java  20 May 2002 06:14:46 -0000      1.5
  +++ WarFileTest.java  29 May 2002 04:13:34 -0000      1.6
  @@ -70,7 +70,7 @@
    * Unit test for {@link WarFile}.
    * 
    * @author <a href="mailto:[EMAIL PROTECTED]";>dIon Gillard</a>
  - * @version $Id: WarFileTest.java,v 1.5 2002/05/20 06:14:46 dion Exp $
  + * @version $Id: WarFileTest.java,v 1.6 2002/05/29 04:13:34 dion Exp $
    */
   public class WarFileTest extends TestCase
   {
  @@ -260,6 +260,7 @@
       }
   
       /** test the error pages war contains 2 error pages
  +     * @throws Exception when there is an unexpected problem
        */
       public void testErrorPagesWar() throws Exception
       {
  @@ -274,6 +275,7 @@
       
       /** test the login pages war contains a form login config object with the
        * login and error pages set
  +     * @throws Exception when there is an unexpected problem
        */
       public void testLoginPagesWar() throws Exception
       {
  @@ -284,5 +286,18 @@
               "/login.html", instance.getFormLoginConfig().getLoginPage());
           assertEquals("Error page is not /error.jsp", 
               "/error.jsp", instance.getFormLoginConfig().getErrorPage());
  +    }
  +    
  +    /** test the servlet mappings comes back with the correct entries
  +     * @throws Exception when there is an unexpected problem
  +     */
  +    public void testServletMappings() throws Exception
  +    {
  +        instance = new WarFile(dummyWarFile);
  +        assertEquals("# of servlet mappings for dummy war file is wrong", 2, 
  +            instance.getServletMappings().size());
  +        instance = new WarFile(loginPagesWarFile);
  +        assertEquals("# of servlet mappings in login pages war is wrong", 0, 
  +            instance.getServletMappings().size());
       }
   }
  
  
  
  1.8       +25 -2     
jakarta-turbine-maven/src/java/org/apache/maven/j2ee/WarFile.java
  
  Index: WarFile.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-turbine-maven/src/java/org/apache/maven/j2ee/WarFile.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- WarFile.java      27 May 2002 12:30:12 -0000      1.7
  +++ WarFile.java      29 May 2002 04:13:34 -0000      1.8
  @@ -83,7 +83,7 @@
    * Represents a J2EE War File
    *
    * @author <a href="mailto:[EMAIL PROTECTED]";>dIon Gillard</a>
  - * @version $Id: WarFile.java,v 1.7 2002/05/27 12:30:12 dion Exp $
  + * @version $Id: WarFile.java,v 1.8 2002/05/29 04:13:34 dion Exp $
    */
   public class WarFile extends JarFile
   {
  @@ -246,7 +246,7 @@
        * @throws IOException if there are any issues reading the web.xml
        * or producing the xml document
        */
  -    private Document getWebXml() throws IOException
  +    protected Document getWebXml() throws IOException
       {
           if (getWebXmlEntry() == null)
           {
  @@ -396,5 +396,28 @@
               }
           }
           return config;
  +    }
  +    
  +    /** Get a map of servlet name -> url pattern for all defined servlets
  +     * @throws IOException if there are problems reading from the war
  +     */
  +    public Map getServletMappings() throws IOException
  +    {
  +        Map mappings = new HashMap();
  +        
  +        if (getWebXmlEntry() != null)
  +        {
  +            Document webXml = getWebXml();
  +            List nodes = webXml.selectNodes("/web-app/servlet-mapping");
  +            Node node = null;
  +            for (int nodeIndex = 0; nodeIndex < nodes.size(); nodeIndex++)
  +            {
  +                node = (Node) nodes.get(nodeIndex);
  +                String servletName = node.valueOf("./servlet-name");
  +                String urlPattern = node.valueOf("./url-pattern");
  +                mappings.put(servletName, urlPattern);
  +            }
  +        }
  +        return mappings;
       }
   }
  
  
  

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

Reply via email to