01: package com.jat.presentation.controller.navigation;
02:
03: import com.jat.business.BusinessObjectProperties;
04: import javax.servlet.http.HttpServletRequest;
05: import java.util.Enumeration;
06: import java.util.Hashtable;
07: import com.jat.presentation.controller.Action;
08:
09: /**
10: * <p>Title: JAT</p>
11: * <p>Description: </p>
12: * <p>Copyright: Copyright (c) 2004 -2005 Stefano Fratini (stefano.fratini@gmail.com)</p>
13: * <p>Distributed under the terms of the GNU Lesser General Public License, v2.1 or later</p>
14: * @author stf
15: * @version 1.0
16: * @since 1.2
17: */
18:
19: public class NavigationAction extends BusinessObjectProperties {
20:
21: protected NavigationAction(HttpServletRequest request) {
22: for (Enumeration e = request.getParameterNames(); e
23: .hasMoreElements();) {
24: String key = (String) e.nextElement();
25: if (!key.equalsIgnoreCase(Navigation.BACK)
26: && !key.equalsIgnoreCase(Navigation.FORWARD)) {
27: String value = request.getParameter(key);
28: this .properties.put(key, value);
29: }
30: }
31: this .uri = request.getRequestURI();
32: this .method = request.getMethod();
33: }
34:
35: protected NavigationAction(HttpServletRequest request, Action action) {
36: this .uri = request.getContextPath() + action.getNextPage();
37: this .method = (String) action.getMethods().firstElement();
38: }
39:
40: public Enumeration keys() {
41: return this .properties.keys();
42: }
43:
44: public String getValue(String key) {
45: return (String) this .properties.get(key);
46: }
47:
48: public String getMethod() {
49: return this .method;
50: }
51:
52: public String getURI() {
53: return this .uri;
54: }
55:
56: public boolean equals(Object other) {
57: if (other == this )
58: return true;
59: if (other == null)
60: return false;
61: if (getClass() != other.getClass())
62: return false;
63: NavigationAction action = (NavigationAction) other;
64: if (action == null)
65: return false;
66: if (!this .getURI().equalsIgnoreCase(action.getURI()))
67: return false;
68: if (!this .getMethod().equalsIgnoreCase(action.getMethod()))
69: return false;
70: if (this .properties.size() != action.properties.size())
71: return false;
72: for (Enumeration e = this .keys(); e.hasMoreElements();) {
73: String key = (String) e.nextElement();
74: if (!this .getValue(key).equalsIgnoreCase(
75: action.getValue(key)))
76: return false;
77: }
78: return true;
79: }
80:
81: public String toString() {
82: String ret = this .getClass().getName() + "=[";
83: ret += this .properties;
84: ret += ", URI=" + this .getURI();
85: ret += ", Method=" + this .getMethod();
86: return ret + "]";
87: }
88:
89: private String uri;
90: private String method;
91: private Hashtable properties = new Hashtable();
92: }
|