tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ma...@apache.org
Subject svn commit: r833619 - in /tomcat/trunk/java/org/apache/catalina/startup: LocalStrings.properties WebXml.java
Date Sat, 07 Nov 2009 00:46:50 GMT
Author: markt
Date: Sat Nov  7 00:46:50 2009
New Revision: 833619

URL: http://svn.apache.org/viewvc?rev=833619&view=rev
Log:
More web.xml / fragment merge code

Modified:
    tomcat/trunk/java/org/apache/catalina/startup/LocalStrings.properties
    tomcat/trunk/java/org/apache/catalina/startup/WebXml.java

Modified: tomcat/trunk/java/org/apache/catalina/startup/LocalStrings.properties
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/startup/LocalStrings.properties?rev=833619&r1=833618&r2=833619&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/startup/LocalStrings.properties (original)
+++ tomcat/trunk/java/org/apache/catalina/startup/LocalStrings.properties Sat Nov  7 00:46:50
2009
@@ -114,11 +114,10 @@
 webXml.duplicateResourceEnvRef=Duplicate resource-env-ref name
 webXml.duplicateResourceRef=Duplicate resource-ref name
 webXml.reservedName=A web.xml file was detected using a reserved name [{0}]. The name element
will be ignored for this fragment.
-webXml.mergeConflictContextParam=Context parameter [{0}] was defined in multiple fragments
with different values including fragment with name [{1}] located at [{2}]
 webXml.mergeConflictDisplayName=The display name was defined in multiple fragments with different
values including fragment with name [{0}] located at [{1}]
-webXml.mergeConflictEjbLocalRef=The EjbLocalRef [{0}] was defined in multiple fragments including
fragment with name [{1}] located at [{2}]
-webXml.mergeConflictEjbRef=The EjbRef [{0}] was defined in multiple fragments including fragment
with name [{1}] located at [{2}]
-webXml.mergeConflictEnvEntry=The Environment entry [{0}] was defined in multiple fragments
including fragment with name [{1}] located at [{2}]
 webXml.mergeConflictErrorPage=The Error Page for [{0}] was defined in multiple fragments
including fragment with name [{1}] located at [{2}]
 webXml.mergeConflictListener=Listener [{0}] was defined in multiple fragments including fragment
with name [{1}] located at [{2}]
+webXml.mergeConflictLoginConfig=A LoginConfig was defined in multiple fragments including
fragment with name [{1}] located at [{2}]
+webXml.mergeConflictResource=The Resource [{0}] was defined in multiple fragments including
fragment with name [{1}] located at [{2}]
+webXml.mergeConflictString=The [{0}] with name [{1}] was defined in multiple fragments including
fragment with name [{2}] located at [{3}]
 webXml.multipleOther=Multiple others entries in ordering

Modified: tomcat/trunk/java/org/apache/catalina/startup/WebXml.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/startup/WebXml.java?rev=833619&r1=833618&r2=833619&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/startup/WebXml.java (original)
+++ tomcat/trunk/java/org/apache/catalina/startup/WebXml.java Sat Nov  7 00:46:50 2009
@@ -41,6 +41,7 @@
 import org.apache.catalina.deploy.LoginConfig;
 import org.apache.catalina.deploy.MessageDestination;
 import org.apache.catalina.deploy.MessageDestinationRef;
+import org.apache.catalina.deploy.ResourceBase;
 import org.apache.catalina.deploy.SecurityConstraint;
 import org.apache.catalina.deploy.SecurityRoleRef;
 import org.apache.catalina.deploy.ServletDef;
@@ -582,25 +583,9 @@
             new HashMap<String, Boolean>();
 
         for (WebXml fragment : fragments) {
-            for (String contextParam : fragment.getContextParams().keySet()) {
-                if (!contextParams.containsKey(contextParam)) {
-                    // Not defined in main web.xml
-                    String value =
-                        fragment.getContextParams().get(contextParam);
-                    if (temp.getContextParams().containsKey(contextParam)) {
-                        if (value != null && !value.equals(
-                                temp.getContextParams().get(contextParam))) {
-                            log.error(sm.getString(
-                                    "webXml.mergeConflictContextParam",
-                                    contextParam,
-                                    fragment.getName(),
-                                    fragment.getURL()));
-                            return false;
-                        }
-                    } else {
-                        temp.addContextParam(contextParam, value);
-                    }
-                }
+            if (!mergeMap(fragment.getContextParams(), contextParams,
+                    temp.getContextParams(), fragment, "Context Parameter")) {
+                return false;
             }
         }
         contextParams.putAll(temp.getContextParams());
@@ -633,175 +618,214 @@
         }
 
         for (WebXml fragment : fragments) {
-            for (ContextLocalEjb ejbLocalRef :
-                    fragment.getEjbLocalRefs().values()) {
-                String name = ejbLocalRef.getName();
-                boolean mergeInjectionFlag = false;
-                if (ejbLocalRefs.containsKey(name)) {
-                    if (mergeInjectionFlags.containsKey(name)) {
-                        mergeInjectionFlag =
-                            mergeInjectionFlags.get(name).booleanValue(); 
-                    } else {
-                        if (ejbLocalRefs.get(
-                                name).getInjectionTargets().size() == 0) {
-                            mergeInjectionFlag = true;
-                        }
-                        mergeInjectionFlags.put(name,
-                                Boolean.valueOf(mergeInjectionFlag));
-                    }
-                    if (mergeInjectionFlag) {
-                        ejbLocalRefs.get(name).getInjectionTargets().addAll(
-                                ejbLocalRef.getInjectionTargets());
-                    }
-                } else {
-                    // Not defined in main web.xml
-                    if (temp.getEjbLocalRefs().containsKey(name)) {
-                        log.error(sm.getString(
-                                "webXml.mergeConflictEjbLocalRef",
-                                name,
-                                fragment.getName(),
-                                fragment.getURL()));
-                        return false;
-                    } else {
-                        temp.getEjbLocalRefs().put(name, ejbLocalRef);
-                    }
-                }
+            if (!mergeResourceMap(fragment.getEjbLocalRefs(), ejbLocalRefs,
+                    temp.getEjbLocalRefs(), mergeInjectionFlags, fragment)) {
+                return false;
             }
         }
         ejbLocalRefs.putAll(temp.getEjbLocalRefs());
         mergeInjectionFlags.clear();
 
         for (WebXml fragment : fragments) {
-            for (ContextEjb ejbRef : fragment.getEjbRefs().values()) {
-                String name = ejbRef.getName();
-                boolean mergeInjectionFlag = false;
-                if (ejbRefs.containsKey(name)) {
-                    if (mergeInjectionFlags.containsKey(name)) {
-                        mergeInjectionFlag =
-                            mergeInjectionFlags.get(name).booleanValue(); 
-                    } else {
-                        if (ejbRefs.get(
-                                name).getInjectionTargets().size() == 0) {
-                            mergeInjectionFlag = true;
-                        }
-                        mergeInjectionFlags.put(name,
-                                Boolean.valueOf(mergeInjectionFlag));
-                    }
-                    if (mergeInjectionFlag) {
-                        ejbRefs.get(name).getInjectionTargets().addAll(
-                                ejbRef.getInjectionTargets());
-                    }
-                } else {
-                    // Not defined in main web.xml
-                    if (temp.getEjbRefs().containsKey(name)) {
-                        log.error(sm.getString(
-                                "webXml.mergeConflictEjbRef",
-                                name,
-                                fragment.getName(),
-                                fragment.getURL()));
-                        return false;
-                    } else {
-                        temp.getEjbRefs().put(name, ejbRef);
-                    }
-                }
+            if (!mergeResourceMap(fragment.getEjbRefs(), ejbRefs,
+                    temp.getEjbRefs(), mergeInjectionFlags, fragment)) {
+                return false;
             }
         }
         ejbRefs.putAll(temp.getEjbRefs());
         mergeInjectionFlags.clear();
 
         for (WebXml fragment : fragments) {
-            for (ContextEnvironment envEntry :
-                    fragment.getEnvEntries().values()) {
-                String name = envEntry.getName();
-                boolean mergeInjectionFlag = false;
-                if (envEntries.containsKey(name)) {
-                    if (mergeInjectionFlags.containsKey(name)) {
-                        mergeInjectionFlag =
-                            mergeInjectionFlags.get(name).booleanValue(); 
+            if (!mergeResourceMap(fragment.getEnvEntries(), envEntries,
+                    temp.getEnvEntries(), mergeInjectionFlags, fragment)) {
+                return false;
+            }
+        }
+        envEntries.putAll(temp.getEnvEntries());
+        mergeInjectionFlags.clear();
+
+        for (WebXml fragment : fragments) {
+            if (!mergeMap(fragment.getErrorPages(), errorPages,
+                    temp.getErrorPages(), fragment, "Error Page")) {
+                return false;
+            }
+        }
+        errorPages.putAll(temp.getErrorPages());
+
+        for (WebXml fragment : fragments) {
+            for (FilterMap filterMap : fragment.getFilterMappings()) {
+                // Always additive
+                addFilterMapping(filterMap);
+            }
+        }
+
+        for (WebXml fragment : fragments) {
+            for (JspPropertyGroup jspPropertyGroup : fragment.getJspPropertyGroups()) {
+                // Always additive
+                addJspPropertyGroup(jspPropertyGroup);
+            }
+        }
+
+        for (WebXml fragment : fragments) {
+            for (String listener : fragment.getListeners()) {
+                // Always additive
+                addListener(listener);
+            }
+        }
+
+        for (WebXml fragment : fragments) {
+            if (!mergeMap(fragment.getLocalEncodingMappings(),
+                    localeEncodingMappings, temp.getLocalEncodingMappings(),
+                    fragment, "Locale Encoding Mapping")) {
+                return false;
+            }
+        }
+        errorPages.putAll(temp.getErrorPages());
+
+        if (getLoginConfig() == null) {
+            LoginConfig tempLoginConfig = null;
+            for (WebXml fragment : fragments) {
+                LoginConfig loginConfig = fragment.loginConfig;
+                if (loginConfig != null) {
+                    if (tempLoginConfig == null || loginConfig.equals(tempLoginConfig)) {
+                        tempLoginConfig = loginConfig;
                     } else {
-                        if (envEntries.get(
-                                name).getInjectionTargets().size() == 0) {
-                            mergeInjectionFlag = true;
-                        }
-                        mergeInjectionFlags.put(name,
-                                Boolean.valueOf(mergeInjectionFlag));
-                    }
-                    if (mergeInjectionFlag) {
-                        envEntries.get(name).getInjectionTargets().addAll(
-                                envEntry.getInjectionTargets());
-                    }
-                } else {
-                    // Not defined in main web.xml
-                    if (temp.getEnvEntries().containsKey(name)) {
                         log.error(sm.getString(
-                                "webXml.mergeConflictEnvEntry",
-                                name,
+                                "webXml.mergeConflictLoginConfig",
                                 fragment.getName(),
                                 fragment.getURL()));
-                        return false;
-                    } else {
-                        temp.getEnvEntries().put(name, envEntry);
                     }
                 }
             }
         }
-        envEntries.putAll(temp.getEnvEntries());
+
+
+        for (WebXml fragment : fragments) {
+            if (!mergeResourceMap(fragment.getMessageDestinationRefs(), messageDestinationRefs,
+                    temp.getMessageDestinationRefs(), mergeInjectionFlags, fragment)) {
+                return false;
+            }
+        }
+        messageDestinationRefs.putAll(temp.getMessageDestinationRefs());
         mergeInjectionFlags.clear();
 
         for (WebXml fragment : fragments) {
-            for (String errorPageKey : fragment.getErrorPages().keySet()) {
-                if (!errorPages.containsKey(errorPageKey)) {
-                    // Not defined in main web.xml
-                    ErrorPage errorPage =
-                        fragment.getErrorPages().get(errorPageKey);
-                    if (temp.getErrorPages().containsKey(errorPageKey)) {
-                        if (!errorPage.getLocation().equals(
-                                temp.getErrorPages().get(
-                                        errorPageKey).getLocation())) {
-                            log.error(sm.getString(
-                                    "webXml.mergeConflictErrorPage",
-                                    errorPageKey,
-                                    fragment.getName(),
-                                    fragment.getURL()));
-                            return false;
-                        }
-                    } else {
-                        temp.addErrorPage(errorPage);
-                    }
-                }
+            if (!mergeResourceMap(fragment.getMessageDestinations(), messageDestinations,
+                    temp.getMessageDestinations(), mergeInjectionFlags, fragment)) {
+                return false;
             }
         }
-        errorPages.putAll(temp.getErrorPages());
+        messageDestinations.putAll(temp.getMessageDestinations());
+        mergeInjectionFlags.clear();
 
         for (WebXml fragment : fragments) {
-            for (FilterMap filterMap : fragment.getFilterMappings()) {
+            if (!mergeMap(fragment.getMimeMappings(), mimeMappings,
+                    temp.getMimeMappings(), fragment, "Mime Mapping")) {
+                return false;
+            }
+        }
+
+        for (WebXml fragment : fragments) {
+            if (!mergeResourceMap(fragment.getResourceEnvRefs(), resourceEnvRefs,
+                    temp.getResourceEnvRefs(), mergeInjectionFlags, fragment)) {
+                return false;
+            }
+        }
+        resourceEnvRefs.putAll(temp.getResourceEnvRefs());
+        mergeInjectionFlags.clear();
+
+        for (WebXml fragment : fragments) {
+            if (!mergeResourceMap(fragment.getResourceRefs(), resourceRefs,
+                    temp.getResourceRefs(), mergeInjectionFlags, fragment)) {
+                return false;
+            }
+        }
+        resourceRefs.putAll(temp.getResourceRefs());
+        mergeInjectionFlags.clear();
+
+        for (WebXml fragment : fragments) {
+            for (SecurityConstraint constraint : fragment.getSecurityConstraints()) {
                 // Always additive
-                addFilterMapping(filterMap);
+                addSecurityConstraint(constraint);
+            }
+        }
+
+        for (WebXml fragment : fragments) {
+            for (String role : fragment.getSecurityRoles()) {
+                // Always additive
+                addSecurityRole(role);
             }
         }
 
         
         // TODO SERVLET3 - Merge remaining elements
 
-        for (WebXml fragment : fragments) {
-            for (String listener : fragment.getListeners()) {
-                if (!listeners.contains(listener)) {
-                    // Not defined in main web.xml
-                    if (temp.getListeners().contains(listener)) {
+        return true;
+    }
+    
+    private <T extends ResourceBase> boolean mergeResourceMap(
+            Map<String, T> fragmentResources, Map<String, T> mainResources,
+            Map<String, T> tempResources,
+            Map<String,Boolean> mergeInjectionFlags, WebXml fragment) {
+        for (T resource : fragmentResources.values()) {
+            String name = resource.getName();
+            boolean mergeInjectionFlag = false;
+            if (mainResources.containsKey(name)) {
+                if (mergeInjectionFlags.containsKey(name)) {
+                    mergeInjectionFlag =
+                        mergeInjectionFlags.get(name).booleanValue(); 
+                } else {
+                    if (mainResources.get(
+                            name).getInjectionTargets().size() == 0) {
+                        mergeInjectionFlag = true;
+                    }
+                    mergeInjectionFlags.put(name,
+                            Boolean.valueOf(mergeInjectionFlag));
+                }
+                if (mergeInjectionFlag) {
+                    mainResources.get(name).getInjectionTargets().addAll(
+                            resource.getInjectionTargets());
+                }
+            } else {
+                // Not defined in main web.xml
+                if (tempResources.containsKey(name)) {
+                    log.error(sm.getString(
+                            "webXml.mergeConflictResource",
+                            name,
+                            fragment.getName(),
+                            fragment.getURL()));
+                    return false;
+                } else {
+                    tempResources.put(name, resource);
+                }
+            }
+        }
+        return true;
+    }
+    
+    private <T> boolean mergeMap(Map<String,T> fragmentMap,
+            Map<String,T> mainMap, Map<String,T> tempMap, WebXml fragment,
+            String mapName) {
+        for (String key : fragmentMap.keySet()) {
+            if (!mainMap.containsKey(key)) {
+                // Not defined in main web.xml
+                T value =fragmentMap.get(key);
+                if (tempMap.containsKey(key)) {
+                    if (value != null && !value.equals(
+                            tempMap.get(key))) {
                         log.error(sm.getString(
-                                "webXml.mergeConflictListener",
-                                listener,
+                                "webXml.mergeConflictString",
+                                mapName,
+                                key,
                                 fragment.getName(),
                                 fragment.getURL()));
                         return false;
-                    } else {
-                        temp.addListener(listener);
                     }
+                } else {
+                    tempMap.put(key, value);
                 }
             }
         }
-        listeners.addAll(temp.getListeners());
-
         return true;
     }
 }



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


Mime
View raw message