You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cactus-dev@jakarta.apache.org by cm...@apache.org on 2003/04/23 17:44:29 UTC

cvs commit: jakarta-cactus/integration/ant/src/java/org/apache/cactus/integration/ant/webxml WebXml.java

cmlenz      2003/04/23 08:44:29

  Modified:    integration/ant/src/test/org/apache/cactus/integration/ant/webxml
                        TestWebXml.java
               integration/ant/src/java/org/apache/cactus/integration/ant/webxml
                        WebXml.java
  Log:
  Add new methods to retrieve a servlet/filter by specifying the class or JSP file that implements it
  
  Revision  Changes    Path
  1.7       +162 -1    jakarta-cactus/integration/ant/src/test/org/apache/cactus/integration/ant/webxml/TestWebXml.java
  
  Index: TestWebXml.java
  ===================================================================
  RCS file: /home/cvs/jakarta-cactus/integration/ant/src/test/org/apache/cactus/integration/ant/webxml/TestWebXml.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- TestWebXml.java	21 Apr 2003 21:30:51 -0000	1.6
  +++ TestWebXml.java	23 Apr 2003 15:44:29 -0000	1.7
  @@ -338,6 +338,59 @@
       }
       
       /**
  +     * Tests whether a retrieving a filter name by the name of the class
  +     * implementing the filter works correctly for a descriptor with a single
  +     * filter definition.
  +     * 
  +     * @throws Exception If an unexpected error occurs
  +     */
  +    public void testGetFilterNamesForClassWithSingleFilter() throws Exception
  +    {
  +        String xml = "<web-app>"
  +            + "  <filter>"
  +            + "    <filter-name>f1</filter-name>"
  +            + "    <filter-class>f1class</filter-class>"
  +            + "  </filter>"
  +            + "</web-app>";
  +        Document doc = builder.parse(new ByteArrayInputStream(xml.getBytes()));
  +        WebXml webXml = new WebXml(doc);
  +        Iterator filterNames = webXml.getFilterNamesForClass("f1class");
  +        assertEquals("f1", filterNames.next());
  +        assertTrue(!filterNames.hasNext());
  +    }
  +    
  +    /**
  +     * Tests whether a retrieving the filter names by the name of the class
  +     * implementing the filter works correctly for a descriptor with multiple
  +     * filter definitions.
  +     * 
  +     * @throws Exception If an unexpected error occurs
  +     */
  +    public void testGetFilterNamesForClassWithMultipleFilters() throws Exception
  +    {
  +        String xml = "<web-app>"
  +            + "  <filter>"
  +            + "    <filter-name>f1</filter-name>"
  +            + "    <filter-class>f1class</filter-class>"
  +            + "  </filter>"
  +            + "  <filter>"
  +            + "    <filter-name>f2</filter-name>"
  +            + "    <filter-class>f2class</filter-class>"
  +            + "  </filter>"
  +            + "  <filter>"
  +            + "    <filter-name>f3</filter-name>"
  +            + "    <filter-class>f1class</filter-class>"
  +            + "  </filter>"
  +            + "</web-app>";
  +        Document doc = builder.parse(new ByteArrayInputStream(xml.getBytes()));
  +        WebXml webXml = new WebXml(doc);
  +        Iterator filterNames = webXml.getFilterNamesForClass("f1class");
  +        assertEquals("f1", filterNames.next());
  +        assertEquals("f3", filterNames.next());
  +        assertTrue(!filterNames.hasNext());
  +    }
  +    
  +    /**
        * Tests whether a filter-mapping is correctly retrieved from a descriptor.
        * 
        * @throws Exception If an unexpected error occurs
  @@ -659,6 +712,114 @@
           assertTrue(!servletNames.hasNext());
       }
   
  +    /**
  +     * Tests whether a retrieving a servlet name by the name of the class
  +     * implementing the servlet works correctly for a descriptor with a single
  +     * servlet definition.
  +     * 
  +     * @throws Exception If an unexpected error occurs
  +     */
  +    public void testGetServletNamesForClassWithSingleServlet() throws Exception
  +    {
  +        String xml = "<web-app>"
  +            + "  <servlet>"
  +            + "    <servlet-name>s1</servlet-name>"
  +            + "    <servlet-class>s1class</servlet-class>"
  +            + "  </servlet>"
  +            + "</web-app>";
  +        Document doc = builder.parse(new ByteArrayInputStream(xml.getBytes()));
  +        WebXml webXml = new WebXml(doc);
  +        Iterator servletNames = webXml.getServletNamesForClass("s1class");
  +        assertEquals("s1", servletNames.next());
  +        assertTrue(!servletNames.hasNext());
  +    }
  +    
  +    /**
  +     * Tests whether a retrieving the servlet names by the name of the class
  +     * implementing the servlet works correctly for a descriptor with multiple
  +     * servlet definitions.
  +     * 
  +     * @throws Exception If an unexpected error occurs
  +     */
  +    public void testGetServletNamesForClassWithMultipleServlets()
  +        throws Exception
  +    {
  +        String xml = "<web-app>"
  +            + "  <servlet>"
  +            + "    <servlet-name>s1</servlet-name>"
  +            + "    <servlet-class>sclass1</servlet-class>"
  +            + "  </servlet>"
  +            + "  <servlet>"
  +            + "    <servlet-name>s2</servlet-name>"
  +            + "    <servlet-class>sclass2</servlet-class>"
  +            + "  </servlet>"
  +            + "  <servlet>"
  +            + "    <servlet-name>s3</servlet-name>"
  +            + "    <servlet-class>sclass1</servlet-class>"
  +            + "  </servlet>"
  +            + "</web-app>";
  +        Document doc = builder.parse(new ByteArrayInputStream(xml.getBytes()));
  +        WebXml webXml = new WebXml(doc);
  +        Iterator servletNames = webXml.getServletNamesForClass("sclass1");
  +        assertEquals("s1", servletNames.next());
  +        assertEquals("s3", servletNames.next());
  +        assertTrue(!servletNames.hasNext());
  +    }
  +    
  +    /**
  +     * Tests whether a retrieving a servlet name by the path of the JSP file
  +     * implementing the servlet works correctly for a descriptor with a single
  +     * servlet definition.
  +     * 
  +     * @throws Exception If an unexpected error occurs
  +     */
  +    public void testGetServletNamesForJspFileWithSingleServlet()
  +        throws Exception
  +    {
  +        String xml = "<web-app>"
  +            + "  <servlet>"
  +            + "    <servlet-name>s1</servlet-name>"
  +            + "    <jsp-file>/s1.jsp</jsp-file>"
  +            + "  </servlet>"
  +            + "</web-app>";
  +        Document doc = builder.parse(new ByteArrayInputStream(xml.getBytes()));
  +        WebXml webXml = new WebXml(doc);
  +        Iterator servletNames = webXml.getServletNamesForJspFile("/s1.jsp");
  +        assertEquals("s1", servletNames.next());
  +        assertTrue(!servletNames.hasNext());
  +    }
  +    
  +    /**
  +     * Tests whether a retrieving the servlet names by the path of the JSP file
  +     * implementing the servlet works correctly for a descriptor with multiple
  +     * servlet definitions.
  +     * 
  +     * @throws Exception If an unexpected error occurs
  +     */
  +    public void testGetServletNamesForJspFileWithMultipleServlets()
  +        throws Exception
  +    {
  +        String xml = "<web-app>"
  +            + "  <servlet>"
  +            + "    <servlet-name>s1</servlet-name>"
  +            + "    <jsp-file>/s1.jsp</jsp-file>"
  +            + "  </servlet>"
  +            + "  <servlet>"
  +            + "    <servlet-name>s2</servlet-name>"
  +            + "    <servlet-class>sclass2</servlet-class>"
  +            + "  </servlet>"
  +            + "  <servlet>"
  +            + "    <servlet-name>s3</servlet-name>"
  +            + "    <jsp-file>/s3.jsp</jsp-file>"
  +            + "  </servlet>"
  +            + "</web-app>";
  +        Document doc = builder.parse(new ByteArrayInputStream(xml.getBytes()));
  +        WebXml webXml = new WebXml(doc);
  +        Iterator servletNames = webXml.getServletNamesForJspFile("/s3.jsp");
  +        assertEquals("s3", servletNames.next());
  +        assertTrue(!servletNames.hasNext());
  +    }
  +    
       /**
        * Tests whether a single serrvlet-mapping is correctly retrieved from a
        * descriptor.
  
  
  
  1.16      +86 -1     jakarta-cactus/integration/ant/src/java/org/apache/cactus/integration/ant/webxml/WebXml.java
  
  Index: WebXml.java
  ===================================================================
  RCS file: /home/cvs/jakarta-cactus/integration/ant/src/java/org/apache/cactus/integration/ant/webxml/WebXml.java,v
  retrieving revision 1.15
  retrieving revision 1.16
  diff -u -r1.15 -r1.16
  --- WebXml.java	9 Apr 2003 20:09:17 -0000	1.15
  +++ WebXml.java	23 Apr 2003 15:44:29 -0000	1.16
  @@ -288,6 +288,34 @@
       }
       
       /**
  +     * Returns a list of names of filters that are mapped to the specified
  +     * class.
  +     * 
  +     * @param theClassName The fully qualified name of the filter class
  +     * @return An iterator over the names of the filters mapped to the class
  +     */
  +    public final Iterator getFilterNamesForClass(String theClassName)
  +    {
  +        if (theClassName == null)
  +        {
  +            throw new NullPointerException();
  +        }
  +        Iterator filterElements = getElements(WebXmlTag.FILTER);
  +        List filterNames = new ArrayList();
  +        while (filterElements.hasNext())
  +        {
  +            Element filterElement = (Element) filterElements.next();
  +            if (theClassName.equals(getNestedText(
  +                filterElement, WebXmlTag.FILTER_CLASS)))
  +            {
  +                filterNames.add(getNestedText(
  +                    filterElement, WebXmlTag.FILTER_NAME));
  +            }
  +        }
  +        return filterNames.iterator();
  +    }
  +    
  +    /**
        * Returns the value of an initialization parameter of the specified filter.
        * 
        * @param theFilterName The name of the servlet filter
  @@ -555,6 +583,63 @@
               if (servletName != null)
               {
                   servletNames.add(servletName);
  +            }
  +        }
  +        return servletNames.iterator();
  +    }
  +    
  +    /**
  +     * Returns a list of names of servlets that are mapped to the specified
  +     * class.
  +     * 
  +     * @param theClassName The fully qualified name of the servlet class
  +     * @return An iterator over the names of the servlets mapped to the class
  +     */
  +    public final Iterator getServletNamesForClass(String theClassName)
  +    {
  +        if (theClassName == null)
  +        {
  +            throw new NullPointerException();
  +        }
  +        Iterator servletElements = getElements(WebXmlTag.SERVLET);
  +        List servletNames = new ArrayList();
  +        while (servletElements.hasNext())
  +        {
  +            Element servletElement = (Element) servletElements.next();
  +            if (theClassName.equals(getNestedText(
  +                servletElement, WebXmlTag.SERVLET_CLASS)))
  +            {
  +                servletNames.add(getNestedText(
  +                    servletElement, WebXmlTag.SERVLET_NAME));
  +            }
  +        }
  +        return servletNames.iterator();
  +    }
  +    
  +    /**
  +     * Returns a list of names of servlets that are mapped to the specified
  +     * JSP file.
  +     * 
  +     * @param theJspFile The path to the JSP file, relative to the root of the
  +     *        web-application
  +     * @return An iterator over the names of the servlets mapped to the JSP file
  +     */
  +    public final Iterator getServletNamesForJspFile(String theJspFile)
  +    {
  +        if (theJspFile == null)
  +        {
  +            throw new NullPointerException();
  +        }
  +        Iterator servletElements = getElements(WebXmlTag.SERVLET);
  +        List servletNames = new ArrayList();
  +        while (servletElements.hasNext())
  +        {
  +            Element servletElement = (Element) servletElements.next();
  +            if (theJspFile.equals(getNestedText(
  +                servletElement, WebXmlTag.JSP_FILE)))
  +            {
  +                servletNames.add(getNestedText(
  +                    servletElement, WebXmlTag.SERVLET_NAME));
               }
           }
           return servletNames.iterator();
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: cactus-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: cactus-dev-help@jakarta.apache.org