Helper class that can merge two web deployment descriptors.
| Method from org.apache.cactus.integration.ant.deployment.webapp.WebXmlMerger Detail: |
protected final void checkServletVersions(WebXml theWebXml) {
if ((this.webXml.getVersion() != null)
&& (this.webXml.getVersion().compareTo(theWebXml.getVersion()) < 0))
{
this.log.warn(
"Merging elements from a version " + theWebXml.getVersion()
+ " descriptor into a version " + this.webXml.getVersion()
+ ", some elements may be skipped");
}
}
Checks the versions of the servlet API in each descriptor, and logs
a warning if a mismatch might result in the loss of definitions. |
public final void merge(WebXml theMergeWebXml) {
checkServletVersions(theMergeWebXml);
mergeContextParams(theMergeWebXml);
if (WebXmlVersion.V2_3.compareTo(this.webXml.getVersion()) < = 0)
{
mergeFilters(theMergeWebXml);
}
mergeServlets(theMergeWebXml);
if (WebXmlVersion.V2_3.compareTo(this.webXml.getVersion()) < = 0)
{
mergeResourceEnvironmentReferences(theMergeWebXml);
}
mergeResourceReferences(theMergeWebXml);
mergeSecurityConstraints(theMergeWebXml);
mergeLoginConfig(theMergeWebXml);
mergeSecurityRoles(theMergeWebXml);
mergeEnvironmentEntries(theMergeWebXml);
mergeEjbRefs(theMergeWebXml);
if (WebXmlVersion.V2_3.compareTo(this.webXml.getVersion()) < = 0)
{
mergeEjbLocalRefs(theMergeWebXml);
}
}
Merges the merge descriptor with the original descriptor. |
protected final void mergeContextParams(WebXml theWebXml) {
Iterator contextParams = theWebXml.getElements(WebXmlTag.CONTEXT_PARAM);
int count = 0;
while (contextParams.hasNext())
{
String paramName = theWebXml.getContextParamName(
(Element) contextParams.next());
if (!webXml.hasContextParam(paramName))
{
webXml.addContextParam(theWebXml.getContextParam(paramName));
}
count++;
}
this.log.trace("Merged " + count + " context-param definition"
+ (count != 1 ? "s " : " ") + "into the descriptor");
}
Merges the context-param definitions from the specified descriptor into
the original descriptor. |
protected final void mergeEjbLocalRefs(WebXml theWebXml) {
int count = insertElements(theWebXml, WebXmlTag.EJB_LOCAL_REF);
if (count > 0)
{
this.log.trace("Merged " + count + " EJB local reference"
+ (count != 1 ? "s " : "y ") + "into the descriptor");
}
}
Merges the EJB local references from the provided descriptor into the
original descriptor. |
protected final void mergeEjbRefs(WebXml theWebXml) {
int count = insertElements(theWebXml, WebXmlTag.EJB_REF);
if (count > 0)
{
this.log.trace("Merged " + count + " EJB reference"
+ (count != 1 ? "s " : "y ") + "into the descriptor");
}
}
Merges the EJB references from the provided descriptor into the original
descriptor. |
protected final void mergeEnvironmentEntries(WebXml theWebXml) {
int count = insertElements(theWebXml, WebXmlTag.ENV_ENTRY);
if (count > 0)
{
this.log.trace("Merged " + count + " environment entr"
+ (count != 1 ? "ies " : "y ") + "into the descriptor");
}
}
Merges the environment entries from the provided descriptor into the
original descriptor. |
protected final void mergeFilters(WebXml theWebXml) {
Iterator filterNames = theWebXml.getFilterNames();
int count = 0;
while (filterNames.hasNext())
{
String filterName = (String) filterNames.next();
if (!webXml.hasFilter(filterName))
{
webXml.addFilter(theWebXml.getFilter(filterName));
}
else
{
// merge the parameters
Iterator filterInitParamNames =
theWebXml.getFilterInitParamNames(filterName);
while (filterInitParamNames.hasNext())
{
String paramName = (String) filterInitParamNames.next();
String paramValue =
theWebXml.getFilterInitParam(filterName, paramName);
webXml.addFilterInitParam(
filterName, paramName, paramValue);
}
}
// merge the mappings
Iterator filterMappings = theWebXml.getFilterMappings(filterName);
while (filterMappings.hasNext())
{
String urlPattern = (String) filterMappings.next();
webXml.addFilterMapping(filterName, urlPattern);
}
count++;
}
this.log.trace("Merged " + count + " filter definition"
+ (count != 1 ? "s " : " ") + "into the descriptor");
}
Merges the servlet definitions from the specified descriptor into the
original descriptor. |
protected final void mergeLoginConfig(WebXml theWebXml) {
boolean replaced = replaceElement(theWebXml, WebXmlTag.LOGIN_CONFIG);
if (replaced)
{
this.log.trace(
"Merged the login configuration into the descriptor");
}
}
Merges the login configuration from the provided descriptor into the
original descriptor, thereby eventually replacing the existing login
config. |
protected final void mergeResourceEnvironmentReferences(WebXml theWebXml) {
int count = insertElements(theWebXml, WebXmlTag.RESOURCE_ENV_REF);
if (count > 0)
{
this.log.trace("Merged " + count + " resource environment "
+ "reference" + (count != 1 ? "s " : " ") + "into the "
+ "descriptor");
}
}
Merges the resource environment references from the provided descriptor
into the original descriptor. |
protected final void mergeResourceReferences(WebXml theWebXml) {
int count = insertElements(theWebXml, WebXmlTag.RESOURCE_REF);
if (count > 0)
{
this.log.trace("Merged " + count + " resource reference"
+ (count != 1 ? "s " : " ") + "into the descriptor");
}
}
Merges the resource references from the provided descriptor into the
original descriptor. |
protected final void mergeSecurityConstraints(WebXml theWebXml) {
int count = insertElements(theWebXml, WebXmlTag.SECURITY_CONSTRAINT);
if (count > 0)
{
this.log.trace("Merged " + count + " security constraint"
+ (count != 1 ? "s " : " ") + "into the descriptor");
}
}
|
protected final void mergeSecurityRoles(WebXml theWebXml) {
Iterator securityRoleNames = theWebXml.getSecurityRoleNames();
int count = 0;
while (securityRoleNames.hasNext())
{
String securityRoleName = (String) securityRoleNames.next();
if (!this.webXml.hasSecurityRole(securityRoleName))
{
this.webXml.addSecurityRole(securityRoleName);
}
}
if (count > 0)
{
this.log.trace("Merged " + count + " security role"
+ (count != 1 ? "s " : " ") + "into the descriptor");
}
}
Merges the security roles from the provided descriptor into the original
descriptor. |
protected final void mergeServlets(WebXml theWebXml) {
Iterator servletNames = theWebXml.getServletNames();
int count = 0;
while (servletNames.hasNext())
{
String servletName = (String) servletNames.next();
if (!webXml.hasServlet(servletName))
{
webXml.addServlet(theWebXml.getServlet(servletName));
}
else
{
// merge the parameters
Iterator servletInitParamNames =
theWebXml.getServletInitParamNames(servletName);
while (servletInitParamNames.hasNext())
{
String paramName = (String) servletInitParamNames.next();
String paramValue =
theWebXml.getServletInitParam(servletName, paramName);
webXml.addServletInitParam(
servletName, paramName, paramValue);
}
String roleName =
theWebXml.getServletRunAsRoleName(servletName);
if (roleName != null)
{
webXml.addServletRunAsRoleName(servletName, roleName);
}
}
// merge the mappings
Iterator servletMappings =
theWebXml.getServletMappings(servletName);
while (servletMappings.hasNext())
{
String urlPattern = (String) servletMappings.next();
webXml.addServletMapping(servletName, urlPattern);
}
count++;
}
this.log.trace("Merged " + count + " servlet definition"
+ (count != 1 ? "s " : " ") + "into the descriptor");
}
Merges the servlet definitions from the specified descriptor into the
original descriptor. |
public final void setLog(Log theLog) {
this.log = theLog;
}
Sets the log to which events should be written. This method must be
called before any of the other methods, because the class will rely on
being able to log. |