Revision: 866
http://stripes.svn.sourceforge.net/stripes/?rev=866&view=rev
Author: bengunter
Date: 2008-02-26 19:45:22 -0800 (Tue, 26 Feb 2008)
Log Message:
-----------
Better prefix matching when searching for a binding prototype for a URI. If the
URI does not exactly match an ActionBean's path then it will match URIs that
start with the path followed by a slash or the first component, if the first
component is a string literal. (In most cases, that first component will be a
slash anyway.) E.g., given @UrlBinding("/foo,{bar}"), valid URIs will be of the
form /foo (exact match), /foo/* (slash) or /foo,* (literal string as first
component). Before this change, anything starting with /foo (/foobar,
/foo-fighters) would have matched.
Modified Paths:
--------------
trunk/stripes/src/net/sourceforge/stripes/controller/UrlBindingFactory.java
Modified:
trunk/stripes/src/net/sourceforge/stripes/controller/UrlBindingFactory.java
===================================================================
--- trunk/stripes/src/net/sourceforge/stripes/controller/UrlBindingFactory.java
2008-02-27 01:22:35 UTC (rev 865)
+++ trunk/stripes/src/net/sourceforge/stripes/controller/UrlBindingFactory.java
2008-02-27 03:45:22 UTC (rev 866)
@@ -22,8 +22,7 @@
import java.util.Iterator;
import java.util.List;
import java.util.Map;
-import java.util.Set;
-import java.util.TreeSet;
+import java.util.TreeMap;
import java.util.Map.Entry;
import javax.servlet.http.HttpServletRequest;
@@ -70,12 +69,13 @@
private final Map<String, UrlBinding> pathCache = new HashMap<String,
UrlBinding>();
/** Holds the set of paths that are cached, sorted from longest to
shortest */
- private final Set<String> pathSet = new TreeSet<String>(new
Comparator<String>() {
- public int compare(String a, String b) {
- int cmp = b.length() - a.length();
- return cmp == 0 ? a.compareTo(b) : cmp;
- }
- });
+ private final Map<String, UrlBinding> prefixCache = new TreeMap<String,
UrlBinding>(
+ new Comparator<String>() {
+ public int compare(String a, String b) {
+ int cmp = b.length() - a.length();
+ return cmp == 0 ? a.compareTo(b) : cmp;
+ }
+ });
/** Don't want the constructor to be public */
protected UrlBindingFactory() {
@@ -117,15 +117,15 @@
* @return a binding prototype, or null if the URI does not match
*/
public UrlBinding getBindingPrototype(String uri) {
- // look up as a path first
+ // Look for an exact match to the URI first
UrlBinding prototype = pathCache.get(uri);
if (prototype != null)
return prototype;
- // if not found, then find longest matching path
- for (String path : pathSet) {
- if (uri.startsWith(path)) {
- prototype = pathCache.get(path);
+ // Then look for a matching prefix
+ for (Entry<String, UrlBinding> entry : prefixCache.entrySet()) {
+ if (uri.startsWith(entry.getKey())) {
+ prototype = entry.getValue();
break;
}
}
@@ -262,7 +262,10 @@
*/
public void addBinding(Class<? extends ActionBean> beanType, UrlBinding
binding) {
pathCache.put(binding.getPath(), binding);
- pathSet.add(binding.getPath());
+ prefixCache.put(binding.getPath() + '/', binding);
+ List<Object> components = binding.getComponents();
+ if (components != null && !components.isEmpty() && components.get(0)
instanceof String)
+ prefixCache.put(binding.getPath() + components.get(0), binding);
classCache.put(beanType, binding);
}
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Stripes-development mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/stripes-development