Index: Mapper.java =================================================================== --- Mapper.java (revision 1718) +++ Mapper.java (working copy) @@ -196,7 +196,7 @@ newHost.defaultContexts = defaultContexts; newHost.defaultContextPaths = defaultContextPaths; // END GlassFish 1024 - Host oldElem = (Host) insertMap(hosts, newHosts, newHost); + Host oldElem = (Host) insertMapIgnoreCase(hosts, newHosts, newHost); if (oldElem == null) { hosts = newHosts; } else if (allowReplacement) { @@ -214,7 +214,7 @@ newHost.defaultContextPaths = defaultContextPaths; // END GlassFish 1024 newHost.object = host; - if (insertMap(hosts, newHosts, newHost) == null) { + if (insertMapIgnoreCase(hosts, newHosts, newHost) == null) { hosts = newHosts; } } @@ -233,20 +233,20 @@ */ public synchronized void removeHost(String name) { // Find and remove the old host - int pos = find(hosts, name); + int pos = findIgnoreCase(hosts, name); if (pos < 0) { return; } Object host = hosts[pos].object; Host[] newHosts = new Host[hosts.length - 1]; - if (removeMap(hosts, newHosts, name)) { + if (removeMapIgnoreCase(hosts, newHosts, name)) { hosts = newHosts; } // Remove all aliases (they will map to the same host object) for (int i = 0; i < newHosts.length; i++) { if (newHosts[i].object == host) { Host[] newHosts2 = new Host[hosts.length - 1]; - if (removeMap(hosts, newHosts2, newHosts[i].name)) { + if (removeMapIgnoreCase(hosts, newHosts2, newHosts[i].name)) { hosts = newHosts2; } } @@ -294,17 +294,17 @@ String[] welcomeResources, javax.naming.Context resources) { Host[] hosts = this.hosts; - int pos = find(hosts, hostName); + int pos = findIgnoreCase(hosts, hostName); if( pos <0 ) { addHost(hostName, new String[0], ""); hosts = this.hosts; - pos = find(hosts, hostName); + pos = findIgnoreCase(hosts, hostName); } if (pos < 0) { logger.severe("No host found: " + hostName); } Host host = hosts[pos]; - if (host.name.equals(hostName)) { + if (host.name.equalsIgnoreCase(hostName)) { int slashCount = slashCount(path); synchronized (host) { Context[] contexts = host.contextList.contexts; @@ -344,12 +344,12 @@ */ public void removeContext(String hostName, String path) { Host[] hosts = this.hosts; - int pos = find(hosts, hostName); + int pos = findIgnoreCase(hosts, hostName); if (pos < 0) { return; } Host host = hosts[pos]; - if (host.name.equals(hostName)) { + if (host.name.equalsIgnoreCase(hostName)) { synchronized (host) { Context[] contexts = host.contextList.contexts; if( contexts.length == 0 ){ @@ -408,12 +408,12 @@ public void addWrapper(String hostName, String contextPath, String path, Object wrapper, boolean jspWildCard) { Host[] hosts = this.hosts; - int pos = find(hosts, hostName); + int pos = findIgnoreCase(hosts, hostName); if (pos < 0) { return; } Host host = hosts[pos]; - if (host.name.equals(hostName)) { + if (host.name.equalsIgnoreCase(hostName)) { Context[] contexts = host.contextList.contexts; int pos2 = find(contexts, contextPath); if( pos2<0 ) { @@ -538,12 +538,12 @@ public void removeWrapper (String hostName, String contextPath, String path) { Host[] hosts = this.hosts; - int pos = find(hosts, hostName); + int pos = findIgnoreCase(hosts, hostName); if (pos < 0) { return; } Host host = hosts[pos]; - if (host.name.equals(hostName)) { + if (host.name.equalsIgnoreCase(hostName)) { Context[] contexts = host.contextList.contexts; int pos2 = find(contexts, contextPath); if (pos2 < 0) { @@ -657,7 +657,7 @@ defaultContextPathsMap.put(hostName, defaultContextPath); } - int pos = find(hosts, hostName); + int pos = findIgnoreCase(hosts, hostName); if (pos < 0) { return; } @@ -781,8 +781,8 @@ if (defaultHostName == null) { return; } - pos = find(hosts, defaultHostName); - if ((pos != -1) && (defaultHostName.equals(hosts[pos].name))) { + pos = findIgnoreCase(hosts, defaultHostName); + if ((pos != -1) && (defaultHostName.equalsIgnoreCase(hosts[pos].name))) { mappingData.host = hosts[pos].object; hostPos = pos; contexts = hosts[pos].contextList.contexts; @@ -1061,7 +1061,6 @@ path.setOffset(pathOffset); path.setEnd(pathEnd); - } @@ -1229,11 +1228,25 @@ } + /** - * Find a map elemnt given its name in a sorted array of map elements. + * Find a map element given its name in a sorted array of map elements. * This will return the index for the closest inferior or equal item in the * given array. */ + private static final int findIgnoreCase(MapElement[] map, String name) { + CharChunk cc = new CharChunk(); + char[] chars = name.toCharArray(); + cc.setChars(chars, 0, chars.length); + return findIgnoreCase(map, cc); + } + + + /** + * Find a map element given its name in a sorted array of map elements. + * This will return the index for the closest inferior or equal item in the + * given array. + */ private static final int findIgnoreCase(MapElement[] map, CharChunk name) { return findIgnoreCase(map, name, name.getStart(), name.getEnd()); } @@ -1472,8 +1485,36 @@ /** - * Insert into the right place in a sorted MapElement array. + * Inserts the given MapElement at the appropriate place in the given, + * lexicograhically sorted, MapElement array, avoiding duplicates. + * + * Name comparisons are performed in a case-insensitive manner. + * + * @return old MapElement with matching name (this is an indication that + * newElement has not been inserted), or null if oldMap did not contain + * any MapElement with matching name (this is an indication that + * newElement has been inserted) */ + private static final MapElement insertMapIgnoreCase + (MapElement[] oldMap, MapElement[] newMap, MapElement newElement) { + CharChunk cc = new CharChunk(); + char[] chars = newElement.name.toCharArray(); + cc.setChars(chars, 0, chars.length); + int pos = findIgnoreCase(oldMap, cc); + if ((pos != -1) && (newElement.name.equalsIgnoreCase(oldMap[pos].name))) { + return oldMap[pos]; + } + System.arraycopy(oldMap, 0, newMap, 0, pos + 1); + newMap[pos + 1] = newElement; + System.arraycopy + (oldMap, pos + 1, newMap, pos + 2, oldMap.length - pos - 1); + return null; + } + + + /** + * Removes from a sorted MapElement array. + */ private static final boolean removeMap (MapElement[] oldMap, MapElement[] newMap, String name) { int pos = find(oldMap, name); @@ -1487,6 +1528,28 @@ } + /** + * Removes the MapElement with the given name from the given, + * lexicographically sorted, MapElement array. + * + * Name comparisons are performed in a case-insensitive manner. + */ + private static final boolean removeMapIgnoreCase + (MapElement[] oldMap, MapElement[] newMap, String name) { + CharChunk cc = new CharChunk(); + char[] chars = name.toCharArray(); + cc.setChars(chars, 0, chars.length); + int pos = findIgnoreCase(oldMap, cc); + if ((pos != -1) && (name.equalsIgnoreCase(oldMap[pos].name))) { + System.arraycopy(oldMap, 0, newMap, 0, pos); + System.arraycopy(oldMap, pos + 1, newMap, pos, + oldMap.length - pos - 1); + return true; + } + return false; + } + + // ------------------------------------------------- MapElement Inner Class