1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.seasar.cubby.filter; |
17 | |
|
18 | |
import static org.seasar.cubby.CubbyConstants.ATTR_ACTION; |
19 | |
import static org.seasar.cubby.CubbyConstants.ATTR_CONTEXT_PATH; |
20 | |
import static org.seasar.cubby.CubbyConstants.ATTR_MESSAGES; |
21 | |
|
22 | |
import java.util.ArrayList; |
23 | |
import java.util.Enumeration; |
24 | |
import java.util.List; |
25 | |
|
26 | |
import javax.servlet.http.HttpServletRequest; |
27 | |
import javax.servlet.http.HttpServletRequestWrapper; |
28 | |
|
29 | |
import org.seasar.cubby.CubbyConstants; |
30 | |
import org.seasar.cubby.action.Action; |
31 | |
import org.seasar.cubby.controller.ThreadContext; |
32 | |
import org.seasar.cubby.util.IteratorEnumeration; |
33 | |
import org.seasar.framework.beans.BeanDesc; |
34 | |
import org.seasar.framework.beans.PropertyDesc; |
35 | |
import org.seasar.framework.beans.factory.BeanDescFactory; |
36 | |
|
37 | |
|
38 | |
|
39 | |
|
40 | |
|
41 | |
|
42 | |
|
43 | |
|
44 | |
|
45 | |
|
46 | |
|
47 | |
|
48 | |
|
49 | |
|
50 | |
|
51 | |
|
52 | |
|
53 | |
|
54 | |
|
55 | |
|
56 | |
|
57 | |
|
58 | |
|
59 | |
|
60 | |
|
61 | |
|
62 | |
|
63 | |
|
64 | |
|
65 | |
|
66 | |
|
67 | |
|
68 | |
|
69 | |
|
70 | |
|
71 | |
|
72 | |
|
73 | |
class CubbyHttpServletRequestWrapper extends HttpServletRequestWrapper { |
74 | |
|
75 | |
|
76 | |
|
77 | |
|
78 | |
|
79 | |
|
80 | |
|
81 | |
public CubbyHttpServletRequestWrapper(final HttpServletRequest request) { |
82 | 1 | super(request); |
83 | 1 | } |
84 | |
|
85 | |
|
86 | |
|
87 | |
|
88 | |
|
89 | |
|
90 | |
|
91 | |
@Override |
92 | |
public Object getAttribute(final String name) { |
93 | |
final Object attribute; |
94 | 0 | if (ATTR_CONTEXT_PATH.equals(name)) { |
95 | 0 | attribute = this.getContextPath(); |
96 | 0 | } else if (ATTR_MESSAGES.equals(name)) { |
97 | 0 | attribute = ThreadContext.getMessagesMap(); |
98 | |
} else { |
99 | 0 | final Action action = (Action) super.getAttribute(ATTR_ACTION); |
100 | 0 | if (action != null) { |
101 | 0 | final BeanDesc beanDesc = BeanDescFactory.getBeanDesc(action |
102 | |
.getClass()); |
103 | 0 | if (beanDesc.hasPropertyDesc(name)) { |
104 | 0 | final PropertyDesc propertyDesc = beanDesc |
105 | |
.getPropertyDesc(name); |
106 | 0 | if (propertyDesc.isReadable()) { |
107 | 0 | attribute = propertyDesc.getValue(action); |
108 | |
} else { |
109 | 0 | attribute = super.getAttribute(name); |
110 | |
} |
111 | 0 | } else { |
112 | 0 | attribute = super.getAttribute(name); |
113 | |
} |
114 | 0 | } else { |
115 | 0 | attribute = super.getAttribute(name); |
116 | |
} |
117 | |
} |
118 | 0 | return attribute; |
119 | |
} |
120 | |
|
121 | |
|
122 | |
|
123 | |
|
124 | |
|
125 | |
|
126 | |
@SuppressWarnings("unchecked") |
127 | |
@Override |
128 | |
public Enumeration getAttributeNames() { |
129 | 1 | final List attributeNames = new ArrayList(); |
130 | |
|
131 | 1 | attributeNames.add(ATTR_CONTEXT_PATH); |
132 | 1 | attributeNames.add(ATTR_ACTION); |
133 | 1 | attributeNames.add(ATTR_MESSAGES); |
134 | |
|
135 | 1 | final Action action = (Action) super.getAttribute(ATTR_ACTION); |
136 | 1 | if (action != null) { |
137 | 1 | final BeanDesc beanDesc = BeanDescFactory.getBeanDesc(action |
138 | |
.getClass()); |
139 | 3 | for (int i = 0; i < beanDesc.getPropertyDescSize(); i++) { |
140 | 2 | final PropertyDesc propertyDesc = beanDesc.getPropertyDesc(i); |
141 | 2 | if (propertyDesc.isReadable()) { |
142 | 2 | attributeNames.add(propertyDesc.getPropertyName()); |
143 | |
} |
144 | |
} |
145 | |
} |
146 | |
|
147 | 1 | final Enumeration defaultAttributeNames = super.getAttributeNames(); |
148 | 3 | while (defaultAttributeNames.hasMoreElements()) { |
149 | 2 | attributeNames.add(defaultAttributeNames.nextElement()); |
150 | |
} |
151 | 1 | return new IteratorEnumeration(attributeNames.iterator()); |
152 | |
} |
153 | |
|
154 | |
} |