org.codehaus.cargo.module.webapp
Class WebXml

java.lang.Object
  extended byorg.codehaus.cargo.module.AbstractDescriptor
      extended byorg.codehaus.cargo.module.webapp.WebXml
All Implemented Interfaces:
Descriptor, J2eeDescriptor

public class WebXml
extends AbstractDescriptor
implements J2eeDescriptor

Encapsulates the DOM representation of a web deployment descriptor web.xml to provide convenience methods for easy access and manipulation.

Version:
$Id: WebXml.java 1283 2007-02-01 12:05:49Z grimsell $

Constructor Summary
WebXml(org.w3c.dom.Document document)
          Constructor.
 
Method Summary
 void addContextParam(org.w3c.dom.Element contextParam)
          Adds a new context-param element to the descriptor.
 void addEjbRef(EjbRef ref)
          Adds an ejb-ref.
 void addFilter(org.w3c.dom.Element filter)
          Adds a new servlet filter to the descriptor.
 void addFilter(java.lang.String filterName, java.lang.String filterClass)
          Adds a new servlet filter to the descriptor.
 void addFilterInitParam(java.lang.String filterName, java.lang.String paramName, java.lang.String paramValue)
          Adds an initialization parameter to the specified filter.
 void addFilterMapping(java.lang.String filterName, java.lang.String urlPattern)
          Adds a filter mapping to the descriptor.
 void addJspFile(java.lang.String theServletName, java.lang.String theJspFile)
          Adds a mapped JSP file to the descriptor.
 void addRootElement(DescriptorTag tag, org.w3c.dom.Element element)
          Adds an element of the specified tag to root of the descriptor.
 void addSecurityConstraint(java.lang.String theWebResourceName, java.lang.String theUrlPattern, java.util.List theRoles)
          Creates and adds a security-constraint to the descriptor.
 void addSecurityRole(java.lang.String theRoleName)
          Adds a new security role to the descriptor.
 void addServlet(org.w3c.dom.Element theServlet)
          Adds a new servlet to the descriptor.
 void addServlet(java.lang.String theServletName, java.lang.String theServletClass)
          Adds a new servlet to the descriptor.
 void addServletInitParam(java.lang.String theServletName, java.lang.String theParamName, java.lang.String theParamValue)
          Adds an initialization parameter to the specified servlet.
 void addServletMapping(java.lang.String theServletName, java.lang.String theUrlPattern)
          Adds a servlet mapping to the descriptor.
 void addServletRunAsRoleName(java.lang.String theServletName, java.lang.String theRoleName)
          Adds a run-as declaration to the specified servlet.
 void addVendorDescriptor(VendorWebAppDescriptor descr)
          Associates a vendor specific descriptor with this web.xml.
 org.w3c.dom.Element getContextParam(java.lang.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.
 java.lang.String getContextParamName(org.w3c.dom.Element contextParam)
           
 AbstractNodeList getContextParams()
          Get the context parameters.
 java.lang.String getFileName()
          Returns the file name of this descriptor. For example "web.xml", "weblogic.xml", etc.
 org.w3c.dom.Element getFilter(java.lang.String filterName)
          Returns the element that contains the definition of a specific servlet filter, or null if a filter of the specified name is not defined in the descriptor.
 java.lang.String getFilterInitParam(java.lang.String filterName, java.lang.String paramName)
          Returns the value of an initialization parameter of the specified filter.
 java.util.Iterator getFilterInitParamNames(java.lang.String theFilterName)
          Returns the names of the initialization parameters of the specified servlet filter.
 java.util.Iterator getFilterMappings(java.lang.String theFilterName)
          Returns the URL-patterns that the specified filter is mapped to in an ordered list.
 java.util.Iterator getFilterNames()
          Returns the names of all filters defined in the deployment descriptor.
 java.util.Iterator getFilterNamesForClass(java.lang.String className)
          Returns a list of names of filters that are mapped to the specified class.
 AbstractNodeList getListeners()
          Returns a list of nodes that are of web listeners.
 org.w3c.dom.Element getLoginConfig()
          Returns whether the descriptor has a login configuration.
 java.lang.String getLoginConfigAuthMethod()
          Returns the authorization method defined by the login configuration.
 org.w3c.dom.Element getSecurityConstraint(java.lang.String theUrlPattern)
          Returns the element that contains the security constraint defined for the specified URL pattern.
 org.w3c.dom.Element getSecurityRole(java.lang.String theRoleName)
          Returns the element that contains the specified security role, or null if the role is not defined in the descriptor.
 java.util.Iterator getSecurityRoleNames()
          Returns a list of the security role names defined in the deployment descriptor.
 org.w3c.dom.Element getServlet(java.lang.String theServletName)
          Returns the element that contains the definition of a specific servlet, or null if a servlet of the specified name is not defined in the descriptor.
 java.lang.String getServletInitParam(java.lang.String theServletName, java.lang.String theParamName)
          Returns the value of an initialization parameter of the specified servlet.
 java.util.Iterator getServletInitParamNames(java.lang.String theServletName)
          Returns the names of the initialization parameters of the specified servlet.
 java.util.Iterator getServletMappings(java.lang.String theServletName)
          Returns the URL-patterns that the specified servlet is mapped to in an ordered list.
 java.util.Iterator getServletNames()
          Returns the names of all servlets defined in the deployment descriptor.
 java.util.Iterator getServletNamesForClass(java.lang.String theClassName)
          Returns a list of names of servlets that are mapped to the specified class.
 java.util.Iterator getServletNamesForJspFile(java.lang.String theJspFile)
          Returns a list of names of servlets that are mapped to the specified JSP file.
 java.lang.String getServletRunAsRoleName(java.lang.String theServletName)
          Returns the role name that the servlet is running as.
 java.util.Iterator getVendorDescriptors()
          Returns all vendor descriptors associated with this web.xml.
 WebXmlVersion getVersion()
          Returns the servlet API version.
 boolean hasContextParam(java.lang.String theParamName)
          Returns whether a context param by the specified name is defined in the deployment descriptor.
 boolean hasFilter(java.lang.String theFilterName)
          Returns whether a servlet filter by the specified name is defined in the deployment descriptor.
 boolean hasLoginConfig()
          Returns whether the descriptor has a login configuration.
 boolean hasSecurityConstraint(java.lang.String theUrlPattern)
          Returns whether a security constraint has been mapped to the specified URL pattern.
 boolean hasSecurityRole(java.lang.String theRoleName)
          Returns whether a specific security role has been defined.
 boolean hasServlet(java.lang.String theServletName)
          Returns whether a servlet by the specified name is defined in the deployment descriptor.
 void replaceRootElement(DescriptorTag tag, org.w3c.dom.Element element)
          Replaces all elements of the specified tag with the provided element.
 void setLoginConfig(java.lang.String theAuthMethod, java.lang.String theRealmName)
          Sets the login configuration.
 
Methods inherited from class org.codehaus.cargo.module.AbstractDescriptor
addElement, checkElement, createNestedText, getChildText, getDocument, getElements, getImmediateChild, getInsertionPointFor, getNestedElements, getNestedText, getRootElement, getText, replaceElement
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.codehaus.cargo.module.Descriptor
getDocument
 

Constructor Detail

WebXml

public WebXml(org.w3c.dom.Document document)
Constructor.

Parameters:
document - The DOM document representing the parsed deployment descriptor
Method Detail

getFileName

public java.lang.String getFileName()
Returns the file name of this descriptor. For example "web.xml", "weblogic.xml", etc.

Specified by:
getFileName in interface Descriptor
Returns:
the file name
See Also:
Descriptor.getFileName()

getContextParams

public AbstractNodeList getContextParams()
Get the context parameters.

Returns:
the context parameters

addVendorDescriptor

public void addVendorDescriptor(VendorWebAppDescriptor descr)
Associates a vendor specific descriptor with this web.xml.

Parameters:
descr - the vendor specific dexcriptor to associate

getVendorDescriptors

public java.util.Iterator getVendorDescriptors()
Returns all vendor descriptors associated with this web.xml.

Specified by:
getVendorDescriptors in interface J2eeDescriptor
Returns:
Iterator containing VendorDescriptors

getVersion

public final WebXmlVersion getVersion()
Returns the servlet API version.

Returns:
The version

addFilter

public final void addFilter(java.lang.String filterName,
                            java.lang.String filterClass)
Adds a new servlet filter to the descriptor.

Parameters:
filterName - The name of the filter to add
filterClass - The name of the class implementing the filter

addContextParam

public final void addContextParam(org.w3c.dom.Element contextParam)
Adds a new context-param element to the descriptor.

Parameters:
contextParam - The element representing the context-param definition

addFilter

public final void addFilter(org.w3c.dom.Element filter)
Adds a new servlet filter to the descriptor.

Parameters:
filter - The element representing the filter definition

addFilterInitParam

public final void addFilterInitParam(java.lang.String filterName,
                                     java.lang.String paramName,
                                     java.lang.String paramValue)
Adds an initialization parameter to the specified filter.

Parameters:
filterName - The name of the filter
paramName - The name of the parameter
paramValue - The parameter value

addFilterMapping

public final void addFilterMapping(java.lang.String filterName,
                                   java.lang.String urlPattern)
Adds a filter mapping to the descriptor.

Parameters:
filterName - The name of the filter
urlPattern - The URL pattern the filter should be mapped to

getFilter

public final org.w3c.dom.Element getFilter(java.lang.String filterName)
Returns the element that contains the definition of a specific servlet filter, or null if a filter of the specified name is not defined in the descriptor.

Parameters:
filterName - The name of the servlet filter
Returns:
The DOM element representing the filter definition

getContextParam

public final org.w3c.dom.Element getContextParam(java.lang.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:
paramName - The context param name
Returns:
The DOM element representing the context param definition

getContextParamName

public final java.lang.String getContextParamName(org.w3c.dom.Element contextParam)
Parameters:
contextParam - the context param element from which to extractthe name
Returns:
the name of the passed context param element

getFilterNamesForClass

public final java.util.Iterator getFilterNamesForClass(java.lang.String className)
Returns a list of names of filters that are mapped to the specified class.

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

getFilterInitParam

public final java.lang.String getFilterInitParam(java.lang.String filterName,
                                                 java.lang.String paramName)
Returns the value of an initialization parameter of the specified filter.

Parameters:
filterName - The name of the servlet filter
paramName - The name of the initialization parameter
Returns:
The parameter value

getFilterInitParamNames

public final java.util.Iterator getFilterInitParamNames(java.lang.String theFilterName)
Returns the names of the initialization parameters of the specified servlet filter.

Parameters:
theFilterName - The name of the servlet filter of which the parameter names should be retrieved
Returns:
An iterator over the ordered list of parameter names

getFilterMappings

public final java.util.Iterator getFilterMappings(java.lang.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:
theFilterName - The name of the servlet filter of which the mappings should be retrieved
Returns:
An iterator over the ordered list of URL-patterns

getFilterNames

public final java.util.Iterator getFilterNames()
Returns the names of all filters defined in the deployment descriptor. The names are returned as an iterator over an ordered list.

Returns:
The filter names

hasContextParam

public final boolean hasContextParam(java.lang.String theParamName)
Returns whether a context param by the specified name is defined in the deployment descriptor.

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

hasFilter

public final boolean hasFilter(java.lang.String theFilterName)
Returns whether a servlet filter by the specified name is defined in the deployment descriptor.

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

addJspFile

public final void addJspFile(java.lang.String theServletName,
                             java.lang.String theJspFile)
Adds a mapped JSP file to the descriptor.

Parameters:
theServletName - The name of the servlet to add
theJspFile - The path to the JSP file relative to the root of the web application

addServlet

public final void addServlet(java.lang.String theServletName,
                             java.lang.String theServletClass)
Adds a new servlet to the descriptor.

Parameters:
theServletName - The name of the servlet to add
theServletClass - The name of the class implementing the servlet

addServlet

public final void addServlet(org.w3c.dom.Element theServlet)
Adds a new servlet to the descriptor.

Parameters:
theServlet - The element representing the servlet definition

addServletInitParam

public final void addServletInitParam(java.lang.String theServletName,
                                      java.lang.String theParamName,
                                      java.lang.String theParamValue)
Adds an initialization parameter to the specified servlet.

Parameters:
theServletName - The name of the filter
theParamName - The name of the parameter
theParamValue - The parameter value

addServletRunAsRoleName

public final void addServletRunAsRoleName(java.lang.String theServletName,
                                          java.lang.String theRoleName)
Adds a run-as declaration to the specified servlet.

Parameters:
theServletName - the name of the servlet to manipulate
theRoleName - the role name that the servlet should be running as

addServletMapping

public final void addServletMapping(java.lang.String theServletName,
                                    java.lang.String theUrlPattern)
Adds a servlet mapping to the descriptor.

Parameters:
theServletName - The name of the servlet
theUrlPattern - The URL pattern the servlet should be mapped to

getServlet

public final org.w3c.dom.Element getServlet(java.lang.String theServletName)
Returns the element that contains the definition of a specific servlet, or null if a servlet of the specified name is not defined in the descriptor.

Parameters:
theServletName - The name of the servlet
Returns:
The DOM element representing the servlet definition

getServletInitParam

public final java.lang.String getServletInitParam(java.lang.String theServletName,
                                                  java.lang.String theParamName)
Returns the value of an initialization parameter of the specified servlet.

Parameters:
theServletName - The name of the servlet
theParamName - The name of the initialization parameter
Returns:
The parameter value

getServletInitParamNames

public final java.util.Iterator getServletInitParamNames(java.lang.String theServletName)
Returns the names of the initialization parameters of the specified servlet.

Parameters:
theServletName - The name of the servlet of which the parameter names should be retrieved
Returns:
An iterator over the ordered list of parameter names

getServletRunAsRoleName

public final java.lang.String getServletRunAsRoleName(java.lang.String theServletName)
Returns the role name that the servlet is running as.

Parameters:
theServletName - The name of the servlet of which the role name should be retrieved
Returns:
the roleName or null if non is specified

getServletMappings

public final java.util.Iterator getServletMappings(java.lang.String theServletName)
Returns the URL-patterns that the specified servlet is mapped to in an ordered list. If there are no mappings for the specified servlet, an iterator over an empty list is returned.

Parameters:
theServletName - The name of the servlet of which the mappings should be retrieved
Returns:
An iterator over the ordered list of URL-patterns

getServletNames

public final java.util.Iterator getServletNames()
Returns the names of all servlets defined in the deployment descriptor. The names are returned as an iterator over an ordered list.

Returns:
The servlet names

getServletNamesForClass

public final java.util.Iterator getServletNamesForClass(java.lang.String theClassName)
Returns a list of names of servlets that are mapped to the specified class.

Parameters:
theClassName - The fully qualified name of the servlet class
Returns:
An iterator over the names of the servlets mapped to the class

getServletNamesForJspFile

public final java.util.Iterator getServletNamesForJspFile(java.lang.String theJspFile)
Returns a list of names of servlets that are mapped to the specified JSP file.

Parameters:
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

hasServlet

public final boolean hasServlet(java.lang.String theServletName)
Returns whether a servlet by the specified name is defined in the deployment descriptor.

Parameters:
theServletName - The name of the servlet
Returns:
true if the servlet is defined, false otherwise

addSecurityConstraint

public final void addSecurityConstraint(java.lang.String theWebResourceName,
                                        java.lang.String theUrlPattern,
                                        java.util.List theRoles)
Creates and adds a security-constraint to the descriptor.

Parameters:
theWebResourceName - The name of the web resource collection to protect
theUrlPattern - The URL pattern to apply the constraint to
theRoles - The list of authorized roles

getSecurityConstraint

public final org.w3c.dom.Element getSecurityConstraint(java.lang.String theUrlPattern)
Returns the element that contains the security constraint defined for the specified URL pattern.

Parameters:
theUrlPattern - The URL pattern
Returns:
The DOM element representing the security constraint

hasSecurityConstraint

public final boolean hasSecurityConstraint(java.lang.String theUrlPattern)
Returns whether a security constraint has been mapped to the specified URL pattern.

Parameters:
theUrlPattern - The URL patterm
Returns:
true if a security constraint is defined, false otherwise

hasLoginConfig

public final boolean hasLoginConfig()
Returns whether the descriptor has a login configuration.

Returns:
true if a login config is defined, false otherwise

getLoginConfig

public final org.w3c.dom.Element getLoginConfig()
Returns whether the descriptor has a login configuration.

Returns:
true if a login config is defined, false otherwise

getLoginConfigAuthMethod

public final java.lang.String getLoginConfigAuthMethod()
Returns the authorization method defined by the login configuration.

Returns:
The authorization method

setLoginConfig

public final void setLoginConfig(java.lang.String theAuthMethod,
                                 java.lang.String theRealmName)
Sets the login configuration.

Parameters:
theAuthMethod - The authentication method (for example, BASIC)
theRealmName - The name of the realm

addSecurityRole

public final void addSecurityRole(java.lang.String theRoleName)
Adds a new security role to the descriptor.

Parameters:
theRoleName - The name of the role to add

getSecurityRole

public final org.w3c.dom.Element getSecurityRole(java.lang.String theRoleName)
Returns the element that contains the specified security role, or null if the role is not defined in the descriptor.

Parameters:
theRoleName - The name of the role
Returns:
The DOM element representing the security role

getSecurityRoleNames

public final java.util.Iterator getSecurityRoleNames()
Returns a list of the security role names defined in the deployment descriptor.

Returns:
An iterator over the list of security role names, or an empty iterator if no security roles are defined in the descriptor

hasSecurityRole

public final boolean hasSecurityRole(java.lang.String theRoleName)
Returns whether a specific security role has been defined.

Parameters:
theRoleName - The name of the role
Returns:
true if the security role is defined, false otherwise

addRootElement

public final void addRootElement(DescriptorTag tag,
                                 org.w3c.dom.Element element)
Adds an element of the specified tag to root of the descriptor.

Parameters:
tag - The descriptor tag
element - The element to add

replaceRootElement

public final void replaceRootElement(DescriptorTag tag,
                                     org.w3c.dom.Element element)
Replaces all elements of the specified tag with the provided element. This method only works on tags directly under the root tag.

Parameters:
tag - The descriptor tag
element - The element to replace the current elements with

addEjbRef

public void addEjbRef(EjbRef ref)
Adds an ejb-ref.

Parameters:
ref - the ejb-ref

getListeners

public AbstractNodeList getListeners()
Returns a list of nodes that are of web listeners.

Returns:
a list of listener nodes


Copyright © 2004-2007 Codehaus. All Rights Reserved.