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/25 00:12:07 UTC

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

cmlenz      2003/04/24 15:12:07

  Modified:    integration/ant/src/java/org/apache/cactus/integration/ant/webxml
                        WebXml.java
               integration/ant/src/test/org/apache/cactus/integration/ant/webxml
                        TestWebXml.java
  Log:
  Added methods to add a servlet, filter or a mapped JSP file without having to create a DOM element first
  
  Revision  Changes    Path
  1.17      +80 -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.16
  retrieving revision 1.17
  diff -u -r1.16 -r1.17
  --- WebXml.java	23 Apr 2003 15:44:29 -0000	1.16
  +++ WebXml.java	24 Apr 2003 22:12:06 -0000	1.17
  @@ -200,6 +200,32 @@
       /**
        * Adds a new servlet filter to the descriptor.
        * 
  +     * @param theFilterName The name of the filter to add
  +     * @param theFilterClass The name of the class implementing the filter
  +     */
  +    public final void addFilter(String theFilterName, String theFilterClass)
  +    {
  +        if (theFilterName == null)
  +        {
  +            throw new NullPointerException();
  +        }
  +        if (hasFilter(theFilterName))
  +        {
  +            throw new IllegalStateException("Filter '" + theFilterName
  +                + "' already defined");
  +        }
  +        Element filterElement =
  +            this.document.createElement(WebXmlTag.FILTER.getTagName());
  +        filterElement.appendChild(
  +            createNestedText(WebXmlTag.FILTER_NAME, theFilterName));
  +        filterElement.appendChild(
  +            createNestedText(WebXmlTag.FILTER_CLASS, theFilterClass));
  +        addElement(WebXmlTag.FILTER, filterElement);
  +    }
  +    
  +    /**
  +     * Adds a new servlet filter to the descriptor.
  +     * 
        * @param theFilter The element representing the filter definition
        */
       public final void addFilter(Element theFilter)
  @@ -410,6 +436,59 @@
       public final boolean hasFilter(String theFilterName)
       {
           return (getFilter(theFilterName) != null);
  +    }
  +    
  +    /**
  +     * Adds a mapped JSP file to the descriptor.
  +     * 
  +     * @param theServletName The name of the servlet to add
  +     * @param theJspFile The path to the JSP file relative to the root of the
  +     *        web application
  +     */
  +    public final void addJspFile(String theServletName, String theJspFile)
  +    {
  +        if (theServletName == null)
  +        {
  +            throw new NullPointerException();
  +        }
  +        if (hasFilter(theServletName))
  +        {
  +            throw new IllegalStateException("Servlet '" + theServletName
  +                + "' already defined");
  +        }
  +        Element servletElement =
  +            this.document.createElement(WebXmlTag.SERVLET.getTagName());
  +        servletElement.appendChild(
  +            createNestedText(WebXmlTag.SERVLET_NAME, theServletName));
  +        servletElement.appendChild(
  +            createNestedText(WebXmlTag.JSP_FILE, theJspFile));
  +        addElement(WebXmlTag.SERVLET, servletElement);
  +    }
  +    
  +    /**
  +     * Adds a new servlet to the descriptor.
  +     * 
  +     * @param theServletName The name of the servlet to add
  +     * @param theServletClass The name of the class implementing the servlet
  +     */
  +    public final void addServlet(String theServletName, String theServletClass)
  +    {
  +        if (theServletName == null)
  +        {
  +            throw new NullPointerException();
  +        }
  +        if (hasFilter(theServletName))
  +        {
  +            throw new IllegalStateException("Servlet '" + theServletName
  +                + "' already defined");
  +        }
  +        Element servletElement =
  +            this.document.createElement(WebXmlTag.SERVLET.getTagName());
  +        servletElement.appendChild(
  +            createNestedText(WebXmlTag.SERVLET_NAME, theServletName));
  +        servletElement.appendChild(
  +            createNestedText(WebXmlTag.SERVLET_CLASS, theServletClass));
  +        addElement(WebXmlTag.SERVLET, servletElement);
       }
       
       /**
  
  
  
  1.8       +49 -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.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- TestWebXml.java	23 Apr 2003 15:44:29 -0000	1.7
  +++ TestWebXml.java	24 Apr 2003 22:12:06 -0000	1.8
  @@ -580,6 +580,22 @@
       }
   
       /**
  +     * Tests whether a single filter can be added using the method that takes 
  +     * a string for the filter name and a string for the filter class.
  +     * 
  +     * @throws Exception If an unexpected error occurs
  +     */
  +    public void testAddFilterWithNameAndClass() throws Exception
  +    {
  +        String xml = "<web-app>"
  +            + "</web-app>";
  +        Document doc = builder.parse(new ByteArrayInputStream(xml.getBytes()));
  +        WebXml webXml = new WebXml(doc);
  +        webXml.addServlet("f1", "f1class");
  +        assertTrue(webXml.hasServlet("f1"));
  +    }
  +
  +    /**
        * Tests whether calling {@link WebXml#hasServlet} with a <code>null</code> 
        * parameter as servlet name throws a <code>NullPointerException</code>.  
        * 
  @@ -980,6 +996,38 @@
           assertEquals("s1param2", initParams.next());
           assertEquals("s1param3", initParams.next());
           assertTrue(!initParams.hasNext());
  +    }
  +
  +    /**
  +     * Tests whether a single servlet can be added using the method that takes 
  +     * a string for the servlet name and a string for the servlet class.
  +     * 
  +     * @throws Exception If an unexpected error occurs
  +     */
  +    public void testAddServletWithNameAndClass() throws Exception
  +    {
  +        String xml = "<web-app>"
  +            + "</web-app>";
  +        Document doc = builder.parse(new ByteArrayInputStream(xml.getBytes()));
  +        WebXml webXml = new WebXml(doc);
  +        webXml.addServlet("s1", "s1class");
  +        assertTrue(webXml.hasServlet("s1"));
  +    }
  +
  +    /**
  +     * Tests whether a single servlet can be added using the method that takes 
  +     * a string for the servlet name and a string for the JSP file.
  +     * 
  +     * @throws Exception If an unexpected error occurs
  +     */
  +    public void testAddServletWithNameAndJspFile() throws Exception
  +    {
  +        String xml = "<web-app>"
  +            + "</web-app>";
  +        Document doc = builder.parse(new ByteArrayInputStream(xml.getBytes()));
  +        WebXml webXml = new WebXml(doc);
  +        webXml.addJspFile("s1", "s1.jsp");
  +        assertTrue(webXml.hasServlet("s1"));
       }
   
       /**
  
  
  

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