01: /*
02: * Copyright © 2002-2005tagtraum industries
03: */
04: package com.tagtraum.jo;
05:
06: import com.tagtraum.framework.http.URI;
07:
08: import java.util.Map;
09: import java.util.HashMap;
10: import java.util.Set;
11:
12: /**
13: *
14: * @author <a href="mailto:hs@tagtraum.com">Hendrik Schreiber</a>
15: * @version 1.1beta1 ($Revision: 1.2 $)
16: */
17: public class ModelMatch {
18:
19: private I_JoServletModel model;
20: private String servletPath;
21: private String contextPath;
22: private String pathInfo;
23: private String queryString;
24: private String requestURI;
25: private URI uri;
26: private Map attributes;
27:
28: public ModelMatch(URI uri, I_JoServletModel model,
29: String servletPath) {
30: this .attributes = new HashMap();
31: this .model = model;
32: this .servletPath = servletPath;
33: this .contextPath = model.getServletContextPeer()
34: .getContextPath();
35: this .uri = uri;
36: // compute other paths
37: this .queryString = uri.getQuery();
38: try {
39: this .pathInfo = com.tagtraum.framework.util.URLDecoder
40: .decode(uri.getPath())
41: .substring(
42: servletPath.length() + contextPath.length());
43: } catch (Exception e) {
44: e.printStackTrace();
45: }
46: if (pathInfo != null && pathInfo.length() == 0)
47: pathInfo = null;
48: requestURI = uri.getPath();
49: // add values to map
50: attributes.put(C_Jo.C_Request_Attribute_RequestURI, requestURI);
51: attributes.put(C_Jo.C_Request_Attribute_ContextPath,
52: contextPath);
53: attributes.put(C_Jo.C_Request_Attribute_ServletPath,
54: servletPath);
55: if (pathInfo != null)
56: attributes.put(C_Jo.C_Request_Attribute_PathInfo, pathInfo);
57: if (queryString != null)
58: attributes.put(C_Jo.C_Request_Attribute_QueryString,
59: queryString);
60: }
61:
62: public Object getAttribute(String name) {
63: return attributes.get(name);
64: }
65:
66: public Set getAttributeNames() {
67: return attributes.keySet();
68: }
69:
70: public I_JoServletModel getModel() {
71: return model;
72: }
73:
74: public String getServletPath() {
75: return servletPath;
76: }
77:
78: public String getContextPath() {
79: return contextPath;
80: }
81:
82: public String getPathInfo() {
83: return pathInfo;
84: }
85:
86: public String getQueryString() {
87: return queryString;
88: }
89:
90: public String getRequestURI() {
91: return requestURI;
92: }
93:
94: public URI getUri() {
95: return uri;
96: }
97: }
|