org.codehaus.cargo.module.webapp
Class WebXmlUtils

java.lang.Object
  extended by org.codehaus.cargo.module.webapp.WebXmlUtils

public final class WebXmlUtils
extends Object

Version:
$Id: WebXmlUtils.java 1705 2008-09-02 13:14:55Z adriana $

Method Summary
static void addContextParam(WebXml webXml, String name, String value)
          Adds a new context-param element to the descriptor.
static void addEjbRef(WebXml webXml, EjbRef ref)
          Add an EJB Reference.
static void addFilter(WebXml webXml, Filter filter)
           
static void addFilter(WebXml webXml, String filterName, String filterClass)
          Add a filter to the descriptor.
static void addFilterInitParam(WebXml webXml, String name, String paramName, String paramValue)
          Add an init param to a filter.
static void addFilterMapping(WebXml webXml, FilterMapping rhs)
           
static void addJspFile(WebXml webXml, String theServletName, String theJspFile)
          Add a JSP file.
static void addSecurityConstraint(WebXml webXml, String theWebResourceName, String theUrlPattern, List theRoles)
          Add a security constraint.
static void addSecurityRole(WebXml webXml, String theRoleName)
           
static void addServlet(WebXml webXml, Servlet element)
          Add a servlet to the web xml.
static void addServlet(WebXml webXml, String servletName, String servletClass)
          Add a servlet to the descriptor.
static void addServletInitParam(WebXml webXml, String theServletName, String name, String value)
          Add an init param to a servlet.
static void addServletMapping(WebXml webXml, String theServletName, String theUrlPattern)
           
static void addServletRunAsRoleName(WebXml webXml, String theServletName, String theRoleName)
           
static void addTagInitParam(WebXmlElement itemElement, String name, String value)
          Add an init-param to the web xml.
static org.jdom.Element getContextParam(WebXml webXml, String paramName)
          Returns the element that contains the definition of a specific context param, or null if a context param of the specified name is not defined in the descriptor.
static Filter getFilter(WebXml theWebXml, String filterName)
           
static String getFilterInitParam(WebXml theWebXml, String filterName, String paramName)
           
static Iterator getFilterInitParamNames(WebXml webXml, String name)
          Get the init parameter names for a filter.
static Iterator getFilterMappingElements(WebXml webXml, String theFilterName)
          Returns the filter mappings that the specified filter is mapped to in an ordered list.
static Iterator getFilterMappings(WebXml webXml, String theFilterName)
          Returns the URL-patterns that the specified filter is mapped to in an ordered list.
static Iterator getFilterNames(WebXml webXml)
           
static Iterator getFilterNamesForClass(WebXml webXml, String className)
          Returns a list of names of filters that are mapped to the specified class.
static String getLoginConfigAuthMethod(WebXml webXml)
          Get the login config authorization method.
static SecurityConstraint getSecurityConstraint(WebXml webXml, String theUrlPattern)
          Get a security constraint by URL.
static org.jdom.Element getSecurityRole(WebXml webXml, String theRoleName)
          Get the security role by name.
static Iterator getSecurityRoleNames(WebXml webXml)
          Get the security role names.
static Servlet getServlet(WebXml theWebXml, String servletName)
           
static String getServletInitParam(WebXml theWebXml, String servletName, String paramName)
           
static Iterator getServletInitParamNames(WebXml webXml, String theServletName)
          Get the names of all the servlet init parameters.
static Iterator getServletMappings(WebXml webXml, String theServletName)
          Get the servlet mappings to the named servlet.
static Iterator getServletNames(WebXml webXml)
          Get an iterator of the servlet names in the web xml.
static Iterator getServletNamesForClass(WebXml webXml, String className)
          Get the names that this servlet uses.
static Iterator getServletNamesForJspFile(WebXml webXml, String theJspFile)
          Returns a list of names of servlets that are mapped to the specified JSP file.
static String getServletRunAsRoleName(WebXml webXml, String theServletName)
          For a named servlet, return the run-as role name.
static boolean hasContextParam(WebXml webXml, String theParamName)
          Returns whether a context param by the specified name is defined in the deployment descriptor.
static boolean hasFilter(WebXml webXml, String theFilterName)
          Returns whether a servlet filter by the specified name is defined in the deployment descriptor.
static boolean hasLoginConfig(WebXml webXml)
          Does the descriptor have a login config?
static boolean hasSecurityConstraint(WebXml webXml, String theUrlPattern)
          Does the descriptor have a security constraint for a URL?
static boolean hasSecurityRole(WebXml webXml, String theRoleName)
          Does the role have a security definition?
static boolean hasServlet(WebXml webXml, String servletName)
          Does the web xml have a named servlet.
static void setLoginConfig(WebXml webXml, String theAuthMethod, String theRealmName)
          Set the login config.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getFilterNamesForClass

public static Iterator getFilterNamesForClass(WebXml webXml,
                                              String className)
Returns a list of names of filters that are mapped to the specified class.

Parameters:
webXml - The webXml file to use
className - The fully qualified name of the filter class
Returns:
An iterator over the names of the filters mapped to the class

getFilterMappings

public static Iterator getFilterMappings(WebXml webXml,
                                         String theFilterName)
Returns the URL-patterns that the specified filter is mapped to in an ordered list. If there are no mappings for the specified filter, an iterator over an empty list is returned.

Parameters:
webXml - The webXml file to use
theFilterName - The name of the servlet filter of which the mappings should be retrieved
Returns:
An iterator over the ordered list of URL-patterns

getFilterMappingElements

public static Iterator getFilterMappingElements(WebXml webXml,
                                                String theFilterName)
Returns the filter mappings that the specified filter is mapped to in an ordered list. If there are no mappings for the specified filter, an iterator over an empty list is returned.

Parameters:
webXml - The webXml file to use
theFilterName - The name of the servlet filter of which the mappings should be retrieved
Returns:
An iterator over the ordered list of filter elements

hasContextParam

public static boolean hasContextParam(WebXml webXml,
                                      String theParamName)
Returns whether a context param by the specified name is defined in the deployment descriptor.

Parameters:
webXml - The webXml file to use
theParamName - The name of the context param
Returns:
true if the context param is defined, false otherwise

getContextParam

public static org.jdom.Element getContextParam(WebXml webXml,
                                               String paramName)
Returns the element that contains the definition of a specific context param, or null if a context param of the specified name is not defined in the descriptor.

Parameters:
webXml - The webXml file to use
paramName - The context param name
Returns:
The DOM element representing the context param definition

hasFilter

public static boolean hasFilter(WebXml webXml,
                                String theFilterName)
Returns whether a servlet filter by the specified name is defined in the deployment descriptor.

Parameters:
webXml - The webXml file to use
theFilterName - The name of the filter
Returns:
true if the filter is defined, false otherwise

getServletRunAsRoleName

public static String getServletRunAsRoleName(WebXml webXml,
                                             String theServletName)
For a named servlet, return the run-as role name.

Parameters:
webXml - The webXml file to use
theServletName - the name of the servlet
Returns:
the run-as role name

addTagInitParam

public static void addTagInitParam(WebXmlElement itemElement,
                                   String name,
                                   String value)
Add an init-param to the web xml.

Parameters:
itemElement - The the parent element to add to
name - The name of the param
value - The value for the param

getFilterInitParamNames

public static Iterator getFilterInitParamNames(WebXml webXml,
                                               String name)
Get the init parameter names for a filter.

Parameters:
webXml - The webXml file to use
name - The name of the filter to use
Returns:
an iterator over the param names

addFilterInitParam

public static void addFilterInitParam(WebXml webXml,
                                      String name,
                                      String paramName,
                                      String paramValue)
Add an init param to a filter.

Parameters:
webXml - The webXml file to use
name - The name of the filter
paramName - The name of the parameter
paramValue - The value of the parameter

hasServlet

public static boolean hasServlet(WebXml webXml,
                                 String servletName)
Does the web xml have a named servlet.

Parameters:
webXml - The webXml file to use
servletName - The name of the servlet
Returns:
true if it does, false if not.

addServlet

public static void addServlet(WebXml webXml,
                              String servletName,
                              String servletClass)
Add a servlet to the descriptor.

Parameters:
webXml - The webXml file to use
servletName - The servlet name
servletClass - The servlet class name

getServletNamesForClass

public static Iterator getServletNamesForClass(WebXml webXml,
                                               String className)
Get the names that this servlet uses.

Parameters:
webXml - The webXml file to use
className - the name of the class
Returns:
Iterator

getServletNamesForJspFile

public static Iterator getServletNamesForJspFile(WebXml webXml,
                                                 String theJspFile)
Returns a list of names of servlets that are mapped to the specified JSP file.

Parameters:
webXml - The webXml file to use
theJspFile - The path to the JSP file, relative to the root of the web-application
Returns:
An iterator over the names of the servlets mapped to the JSP file

getServletNames

public static Iterator getServletNames(WebXml webXml)
Get an iterator of the servlet names in the web xml.

Parameters:
webXml - The webXml file to use
Returns:
Iterator

getServletMappings

public static Iterator getServletMappings(WebXml webXml,
                                          String theServletName)
Get the servlet mappings to the named servlet.

Parameters:
webXml - The webXml file to use
theServletName - The name of the servlet
Returns:
An iterator over the mappings

addServlet

public static void addServlet(WebXml webXml,
                              Servlet element)
Add a servlet to the web xml.

Parameters:
webXml - The webXml file to use
element - The servlet element

addServletInitParam

public static void addServletInitParam(WebXml webXml,
                                       String theServletName,
                                       String name,
                                       String value)
Add an init param to a servlet.

Parameters:
webXml - The webXml file to use
theServletName - The name of the servlet
name - The name of the init param
value - The value for the init param

getServletInitParamNames

public static Iterator getServletInitParamNames(WebXml webXml,
                                                String theServletName)
Get the names of all the servlet init parameters.

Parameters:
webXml - The webXml file to use
theServletName - The name of the servlet
Returns:
An iterator over the parameter names

addSecurityConstraint

public static void addSecurityConstraint(WebXml webXml,
                                         String theWebResourceName,
                                         String theUrlPattern,
                                         List theRoles)
Add a security constraint.

Parameters:
webXml - The webXml file to use
theWebResourceName - The name of the web resource
theUrlPattern - The URL Pattern
theRoles - the Roles to Allow
Throws:
InvocationTargetException
IllegalAccessException
InstantiationException
NoSuchMethodException
IllegalArgumentException
SecurityException

addJspFile

public static void addJspFile(WebXml webXml,
                              String theServletName,
                              String theJspFile)
Add a JSP file.

Parameters:
webXml - The webXml file to use
theServletName - The name of the servlet
theJspFile - The name of the JSP file
Throws:
InvocationTargetException
IllegalAccessException
InstantiationException
NoSuchMethodException
IllegalArgumentException
SecurityException

hasSecurityConstraint

public static boolean hasSecurityConstraint(WebXml webXml,
                                            String theUrlPattern)
Does the descriptor have a security constraint for a URL?

Parameters:
webXml - The webXml file to use
theUrlPattern - The URL pattern to query
Returns:
boolean

hasLoginConfig

public static boolean hasLoginConfig(WebXml webXml)
Does the descriptor have a login config?

Parameters:
webXml - The webXml file to use
Returns:
boolean

setLoginConfig

public static void setLoginConfig(WebXml webXml,
                                  String theAuthMethod,
                                  String theRealmName)
Set the login config.

Parameters:
webXml - The webXml file to use
theAuthMethod - The authorization method
theRealmName - The realm name

getLoginConfigAuthMethod

public static String getLoginConfigAuthMethod(WebXml webXml)
Get the login config authorization method.

Parameters:
webXml - The webXml file to use
Returns:
the auth method

getSecurityConstraint

public static SecurityConstraint getSecurityConstraint(WebXml webXml,
                                                       String theUrlPattern)
Get a security constraint by URL.

Parameters:
webXml - The webXml file to use
theUrlPattern - The URL Pattern
Returns:
Security Constraint

hasSecurityRole

public static boolean hasSecurityRole(WebXml webXml,
                                      String theRoleName)
Does the role have a security definition?

Parameters:
webXml - The webXml file to use
theRoleName - The name of the role
Returns:
boolean

getSecurityRoleNames

public static Iterator getSecurityRoleNames(WebXml webXml)
Get the security role names.

Parameters:
webXml - The webXml file to use
Returns:
an iterator over the role names

getSecurityRole

public static org.jdom.Element getSecurityRole(WebXml webXml,
                                               String theRoleName)
Get the security role by name.

Parameters:
webXml - The webXml file to use
theRoleName - The name of the role
Returns:
Element containing the security role

addEjbRef

public static void addEjbRef(WebXml webXml,
                             EjbRef ref)
Add an EJB Reference.

Parameters:
webXml - The webXml file to use
ref - the EJB Reference element to add

addSecurityRole

public static void addSecurityRole(WebXml webXml,
                                   String theRoleName)
Parameters:
webXml - The webXml file to use
theRoleName - The role name to use

getServlet

public static Servlet getServlet(WebXml theWebXml,
                                 String servletName)
Parameters:
theWebXml - The webXml file to use
servletName - The name of the servlet to get
Returns:
the servlet

getFilterNames

public static Iterator getFilterNames(WebXml webXml)
Parameters:
webXml - The webXml file to use
Returns:
Iterator

getFilter

public static Filter getFilter(WebXml theWebXml,
                               String filterName)
Parameters:
theWebXml - The webXml file to use
filterName - The name of the filter
Returns:
Filter

addFilterMapping

public static void addFilterMapping(WebXml webXml,
                                    FilterMapping rhs)
Parameters:
webXml - The webXml file to use
rhs - The mapping to add

getServletInitParam

public static String getServletInitParam(WebXml theWebXml,
                                         String servletName,
                                         String paramName)
Parameters:
theWebXml - The webXml file to use
servletName - The servlet name
paramName - The parameter Name
Returns:
The value of the init param

addServletRunAsRoleName

public static void addServletRunAsRoleName(WebXml webXml,
                                           String theServletName,
                                           String theRoleName)
Parameters:
webXml - The webXml file to use
theServletName - The name of the servlet
theRoleName - The role name to add

addServletMapping

public static void addServletMapping(WebXml webXml,
                                     String theServletName,
                                     String theUrlPattern)
Parameters:
webXml - The webXml file to use
theServletName - The name of the servlet
theUrlPattern - the URL PAttern to add

getFilterInitParam

public static String getFilterInitParam(WebXml theWebXml,
                                        String filterName,
                                        String paramName)
Parameters:
theWebXml - The webXml file to use
filterName - The name of the filter
paramName - The name of the parameter
Returns:
the init parameter value

addFilter

public static void addFilter(WebXml webXml,
                             Filter filter)
Parameters:
webXml - The webXml file to use
filter - The filter to add

addFilter

public static void addFilter(WebXml webXml,
                             String filterName,
                             String filterClass)
Add a filter to the descriptor.

Parameters:
webXml - The webXml file to use
filterName - The servlet name
filterClass - The servlet class name

addContextParam

public static void addContextParam(WebXml webXml,
                                   String name,
                                   String value)
Adds a new context-param element to the descriptor.

Parameters:
webXml - The webXml containing the descriptor
name - The context name
value - The context value


Copyright © 2004-2012 Codehaus. All Rights Reserved.