Methods Summary |
---|
public java.lang.Object | lookup(java.lang.String requestURI)
if (requestURI == null) {
throw new IllegalArgumentException("Request URI may not be null");
}
//Strip away the query part part if found
int index = requestURI.indexOf("?");
if (index != -1) {
requestURI = requestURI.substring(0, index);
}
// direct match?
Object handler = this.handlerMap.get(requestURI);
if (handler == null) {
// pattern match?
String bestMatch = null;
for (Iterator it = this.handlerMap.keySet().iterator(); it.hasNext();) {
String pattern = (String) it.next();
if (matchUriRequestPattern(pattern, requestURI)) {
// we have a match. is it any better?
if (bestMatch == null
|| (bestMatch.length() < pattern.length())
|| (bestMatch.length() == pattern.length() && pattern.endsWith("*"))) {
handler = this.handlerMap.get(pattern);
bestMatch = pattern;
}
}
}
}
return handler;
|
protected boolean | matchUriRequestPattern(java.lang.String pattern, java.lang.String requestUri)
if (pattern.equals("*")) {
return true;
} else {
return
(pattern.endsWith("*") && requestUri.startsWith(pattern.substring(0, pattern.length() - 1))) ||
(pattern.startsWith("*") && requestUri.endsWith(pattern.substring(1, pattern.length())));
}
|
public void | register(java.lang.String pattern, java.lang.Object handler)
if (pattern == null) {
throw new IllegalArgumentException("URI request pattern may not be null");
}
if (handler == null) {
throw new IllegalArgumentException("HTTP request handelr may not be null");
}
this.handlerMap.put(pattern, handler);
|
public void | setHandlers(java.util.Map map)
if (map == null) {
throw new IllegalArgumentException("Map of handlers may not be null");
}
this.handlerMap.clear();
this.handlerMap.putAll(map);
|
public void | unregister(java.lang.String pattern)
if (pattern == null) {
return;
}
this.handlerMap.remove(pattern);
|