01: package org.xsocket.web.http.servlet;
02:
03: final class ServletMapping {
04:
05: private String servletname = null;
06: private String path = null;
07: private String pattern = null;
08: private boolean isWildcardPath = false;
09: private boolean isWildcardPathExt = false;
10:
11: ServletMapping(String servletname, String pattern) {
12: this .servletname = servletname;
13: this .pattern = pattern;
14: this .path = pattern;
15:
16: if (pattern.endsWith("/*")) {
17: isWildcardPath = true;
18: path = pattern.substring(0, pattern.indexOf("/*"));
19:
20: } else if (pattern.startsWith("*")) {
21: path = pattern.substring(1, pattern.length());
22: isWildcardPathExt = true;
23:
24: } else {
25: isWildcardPath = false;
26: path = pattern;
27: }
28: }
29:
30: boolean match(String requestedRessource) {
31:
32: if (isWildcardPath) {
33: return requestedRessource.startsWith(path)
34: || requestedRessource.equals(path);
35:
36: } else if (isWildcardPathExt) {
37: return requestedRessource.endsWith(path);
38:
39: } else {
40: return requestedRessource.equals(path);
41: }
42: }
43:
44: String getServletname() {
45: return servletname;
46: }
47:
48: String getPath() {
49: if (isWildcardPathExt) {
50: return "";
51: } else {
52: return path;
53: }
54: }
55:
56: String getPattern() {
57: return pattern;
58: }
59: }
|