Package org.codehaus.cargo.module.webapp
Class WebXmlUtils
- java.lang.Object
-
- org.codehaus.cargo.module.webapp.WebXmlUtils
-
public final class WebXmlUtils extends Object
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description 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, String filterName, String filterClass)
Add a filter to the descriptor.static void
addFilter(WebXml webXml, Filter filter)
static void
addFilterDispatcher(WebXml webXml, String theFilterName, String theDispatcher)
static void
addFilterInitParam(WebXml webXml, String name, String paramName, String paramValue)
Add an init param to a filter.static void
addFilterMapping(WebXml webXml, String theFilterName, String theUrlPattern)
static void
addJspFile(WebXml webXml, String theServletName, String theJspFile)
Add a JSP file.static void
addSecurityConstraint(WebXml webXml, String theWebResourceName, String theUrlPattern, List<String> theRoles)
Add a security constraint.static void
addSecurityRole(WebXml webXml, String theRoleName)
static void
addServlet(WebXml webXml, String servletName, String servletClass)
Add a servlet to the descriptor.static void
addServlet(WebXml webXml, Servlet element)
Add a servlet to the web xml.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.jdom2.Element
getContextParam(WebXml webXml, String paramName)
Returns the element that contains the definition of a specific context param, ornull
if a context param of the specified name is not defined in the descriptor.static Filter
getFilter(WebXml theWebXml, String filterName)
static List<String>
getFilterDispatchers(WebXml webXml, String theFilterName)
Returns the dispatchers that the specified filter is mapped to in an ordered list.static String
getFilterInitParam(WebXml theWebXml, String filterName, String paramName)
static List<String>
getFilterInitParamNames(WebXml webXml, String name)
Get the init parameter names for a filter.static List<FilterMapping>
getFilterMappingElements(WebXml webXml, String theFilterName)
Returns the filter mappings that the specified filter is mapped to in an ordered list.static List<String>
getFilterMappings(WebXml webXml, String theFilterName)
Returns the URL-patterns that the specified filter is mapped to in an ordered list.static List<String>
getFilterNames(WebXml webXml)
static List<String>
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.jdom2.Element
getSecurityRole(WebXml webXml, String theRoleName)
Get the security role by name.static List<String>
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 List<String>
getServletInitParamNames(WebXml webXml, String theServletName)
Get the names of all the servlet init parameters.static List<ServletMapping>
getServletMappingElements(WebXml webXml, String theServletName)
Returns the servlet mappings that the specified servlet is mapped to in an ordered list.static List<String>
getServletMappings(WebXml webXml, String theServletName)
Get the servlet mappings to the named servlet.static List<String>
getServletNames(WebXml webXml)
Get a list of the servlet names in the web xml.static List<String>
getServletNamesForClass(WebXml webXml, String className)
Get the names that this servlet uses.static List<String>
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.
-
-
-
Method Detail
-
getFilterNamesForClass
public static List<String> 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 useclassName
- The fully qualified name of the filter class- Returns:
- A list of the names of the filters mapped to the class
-
getFilterMappings
public static List<String> 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 empty list is returned.- Parameters:
webXml
- The webXml file to usetheFilterName
- The name of the servlet filter of which the mappings should be retrieved- Returns:
- An ordered list of the URL-patterns
-
getFilterDispatchers
public static List<String> getFilterDispatchers(WebXml webXml, String theFilterName)
Returns the dispatchers that the specified filter is mapped to in an ordered list. If there are no mappings for the specified filter, an empty list is returned.- Parameters:
webXml
- The webXml file to usetheFilterName
- The name of the servlet filter of which the mappings should be retrieved- Returns:
- An ordered list of the dispatchers
-
getFilterMappingElements
public static List<FilterMapping> 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 empty list is returned.- Parameters:
webXml
- The webXml file to usetheFilterName
- The name of the servlet filter of which the mappings should be retrieved- Returns:
- An ordered list of the 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 usetheParamName
- The name of the context param- Returns:
true
if the context param is defined,false
otherwise
-
getContextParam
public static org.jdom2.Element getContextParam(WebXml webXml, String paramName)
Returns the element that contains the definition of a specific context param, ornull
if a context param of the specified name is not defined in the descriptor.- Parameters:
webXml
- The webXml file to useparamName
- 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 usetheFilterName
- 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 usetheServletName
- 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 toname
- The name of the paramvalue
- The value for the param
-
getFilterInitParamNames
public static List<String> getFilterInitParamNames(WebXml webXml, String name)
Get the init parameter names for a filter.- Parameters:
webXml
- The webXml file to usename
- The name of the filter to use- Returns:
- a list of 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 usename
- The name of the filterparamName
- The name of the parameterparamValue
- 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 useservletName
- 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 useservletName
- The servlet nameservletClass
- The servlet class name
-
getServletNamesForClass
public static List<String> getServletNamesForClass(WebXml webXml, String className)
Get the names that this servlet uses.- Parameters:
webXml
- The webXml file to useclassName
- the name of the class- Returns:
- a list of the servlet names
-
getServletNamesForJspFile
public static List<String> 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 usetheJspFile
- The path to the JSP file, relative to the root of the web-application- Returns:
- A list of the names of the servlets mapped to the JSP file
-
getServletNames
public static List<String> getServletNames(WebXml webXml)
Get a list of the servlet names in the web xml.- Parameters:
webXml
- The webXml file to use- Returns:
- list of the servlet names in the web xml
-
getServletMappings
public static List<String> getServletMappings(WebXml webXml, String theServletName)
Get the servlet mappings to the named servlet.- Parameters:
webXml
- The webXml file to usetheServletName
- The name of the servlet- Returns:
- A list of the mappings
-
getServletMappingElements
public static List<ServletMapping> getServletMappingElements(WebXml webXml, String theServletName)
Returns the servlet mappings that the specified servlet is mapped to in an ordered list. If there are no mappings for the specified servlet, an empty list is returned.- Parameters:
webXml
- The webXml file to usetheServletName
- The name of the servlet of which the mappings should be retrieved- Returns:
- An ordered list of the servlet elements
-
addServlet
public static void addServlet(WebXml webXml, Servlet element)
Add a servlet to the web xml.- Parameters:
webXml
- The webXml file to useelement
- 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 usetheServletName
- The name of the servletname
- The name of the init paramvalue
- The value for the init param
-
getServletInitParamNames
public static List<String> getServletInitParamNames(WebXml webXml, String theServletName)
Get the names of all the servlet init parameters.- Parameters:
webXml
- The webXml file to usetheServletName
- The name of the servlet- Returns:
- A list of the parameter names
-
addSecurityConstraint
public static void addSecurityConstraint(WebXml webXml, String theWebResourceName, String theUrlPattern, List<String> theRoles)
Add a security constraint.- Parameters:
webXml
- The webXml file to usetheWebResourceName
- The name of the web resourcetheUrlPattern
- The URL PatterntheRoles
- the Roles to Allow
-
addJspFile
public static void addJspFile(WebXml webXml, String theServletName, String theJspFile)
Add a JSP file.- Parameters:
webXml
- The webXml file to usetheServletName
- The name of the servlettheJspFile
- The name of the JSP file
-
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 usetheUrlPattern
- 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 usetheAuthMethod
- The authorization methodtheRealmName
- 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 usetheUrlPattern
- 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 usetheRoleName
- The name of the role- Returns:
- boolean
-
getSecurityRoleNames
public static List<String> getSecurityRoleNames(WebXml webXml)
Get the security role names.- Parameters:
webXml
- The webXml file to use- Returns:
- a list of the role names
-
getSecurityRole
public static org.jdom2.Element getSecurityRole(WebXml webXml, String theRoleName)
Get the security role by name.- Parameters:
webXml
- The webXml file to usetheRoleName
- 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 useref
- the EJB Reference element to add
-
addSecurityRole
public static void addSecurityRole(WebXml webXml, String theRoleName)
- Parameters:
webXml
- The webXml file to usetheRoleName
- The role name to use
-
getServlet
public static Servlet getServlet(WebXml theWebXml, String servletName)
- Parameters:
theWebXml
- The webXml file to useservletName
- The name of the servlet to get- Returns:
- the servlet
-
getFilterNames
public static List<String> getFilterNames(WebXml webXml)
- Parameters:
webXml
- The webXml file to use- Returns:
- filter names
-
getFilter
public static Filter getFilter(WebXml theWebXml, String filterName)
- Parameters:
theWebXml
- The webXml file to usefilterName
- The name of the filter- Returns:
- Filter
-
addFilterMapping
public static void addFilterMapping(WebXml webXml, String theFilterName, String theUrlPattern)
- Parameters:
webXml
- The webXml file to usetheFilterName
- The name of the filtertheUrlPattern
- the URL Pattern to add
-
addFilterDispatcher
public static void addFilterDispatcher(WebXml webXml, String theFilterName, String theDispatcher)
- Parameters:
webXml
- The webXml file to usetheFilterName
- The name of the filtertheDispatcher
- the dispatcher to add
-
getServletInitParam
public static String getServletInitParam(WebXml theWebXml, String servletName, String paramName)
- Parameters:
theWebXml
- The webXml file to useservletName
- The servlet nameparamName
- 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 usetheServletName
- The name of the servlettheRoleName
- The role name to add
-
addServletMapping
public static void addServletMapping(WebXml webXml, String theServletName, String theUrlPattern)
- Parameters:
webXml
- The webXml file to usetheServletName
- The name of the servlettheUrlPattern
- the URL Pattern to add
-
getFilterInitParam
public static String getFilterInitParam(WebXml theWebXml, String filterName, String paramName)
- Parameters:
theWebXml
- The webXml file to usefilterName
- The name of the filterparamName
- 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 usefilter
- 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 usefilterName
- The servlet namefilterClass
- The servlet class name
-
-