1 |
| |
2 |
| |
3 |
| |
4 |
| |
5 |
| |
6 |
| |
7 |
| |
8 |
| |
9 |
| |
10 |
| |
11 |
| |
12 |
| |
13 |
| |
14 |
| |
15 |
| package org.apache.tapestry.record; |
16 |
| |
17 |
| import java.util.Collection; |
18 |
| import java.util.Collections; |
19 |
| import java.util.HashMap; |
20 |
| import java.util.Iterator; |
21 |
| import java.util.List; |
22 |
| import java.util.Map; |
23 |
| |
24 |
| import org.apache.hivemind.util.Defense; |
25 |
| import org.apache.tapestry.engine.ServiceEncoding; |
26 |
| import org.apache.tapestry.web.WebRequest; |
27 |
| |
28 |
| |
29 |
| |
30 |
| |
31 |
| |
32 |
| |
33 |
| |
34 |
| |
35 |
| |
36 |
| |
37 |
| |
38 |
| public class ClientPropertyPersistenceStrategy implements PropertyPersistenceStrategy |
39 |
| { |
40 |
| |
41 |
| |
42 |
| |
43 |
| |
44 |
| private final Map _data = new HashMap(); |
45 |
| |
46 |
| private PersistentPropertyDataEncoder _encoder; |
47 |
| |
48 |
| private WebRequest _request; |
49 |
| |
50 |
| private ClientPropertyPersistenceScope _scope; |
51 |
| |
52 |
| |
53 |
| |
54 |
| |
55 |
| |
56 |
| |
57 |
| |
58 |
| |
59 |
| |
60 |
247
| public void initializeService()
|
61 |
| { |
62 |
247
| List names = _request.getParameterNames();
|
63 |
247
| Iterator i = names.iterator();
|
64 |
247
| while (i.hasNext())
|
65 |
| { |
66 |
711
| String name = (String) i.next();
|
67 |
| |
68 |
711
| if (!_scope.isParameterForScope(name))
|
69 |
707
| continue;
|
70 |
| |
71 |
4
| String pageName = _scope.extractPageName(name);
|
72 |
| |
73 |
4
| String encoded = _request.getParameterValue(name);
|
74 |
| |
75 |
4
| PersistentPropertyData data = new PersistentPropertyData(_encoder);
|
76 |
4
| data.storeEncoded(encoded);
|
77 |
| |
78 |
4
| _data.put(pageName, data);
|
79 |
| } |
80 |
| } |
81 |
| |
82 |
1
| public void store(String pageName, String idPath, String propertyName, Object newValue)
|
83 |
| { |
84 |
1
| PersistentPropertyData data = (PersistentPropertyData) _data.get(pageName);
|
85 |
1
| if (data == null)
|
86 |
| { |
87 |
1
| data = new PersistentPropertyData(_encoder);
|
88 |
1
| _data.put(pageName, data);
|
89 |
| } |
90 |
| |
91 |
1
| data.store(idPath, propertyName, newValue);
|
92 |
| } |
93 |
| |
94 |
529
| public Collection getStoredChanges(String pageName)
|
95 |
| { |
96 |
529
| PersistentPropertyData data = (PersistentPropertyData) _data.get(pageName);
|
97 |
| |
98 |
529
| if (data == null)
|
99 |
527
| return Collections.EMPTY_LIST;
|
100 |
| |
101 |
2
| return data.getPageChanges();
|
102 |
| } |
103 |
| |
104 |
1
| public void discardStoredChanges(String pageName)
|
105 |
| { |
106 |
1
| _data.remove(pageName);
|
107 |
| } |
108 |
| |
109 |
341
| public void addParametersForPersistentProperties(ServiceEncoding encoding, boolean post)
|
110 |
| { |
111 |
341
| Defense.notNull(encoding, "encoding");
|
112 |
| |
113 |
341
| Iterator i = _data.entrySet().iterator();
|
114 |
341
| while (i.hasNext())
|
115 |
| { |
116 |
3
| Map.Entry e = (Map.Entry) i.next();
|
117 |
| |
118 |
3
| String pageName = (String) e.getKey();
|
119 |
3
| PersistentPropertyData data = (PersistentPropertyData) e.getValue();
|
120 |
| |
121 |
3
| ClientPropertyPersistenceScope scope = getScope();
|
122 |
| |
123 |
3
| if (scope.shouldEncodeState(encoding, pageName, data))
|
124 |
| { |
125 |
2
| String parameterName = _scope.constructParameterName(pageName);
|
126 |
2
| encoding.setParameterValue(parameterName, data.getEncoded());
|
127 |
| } |
128 |
| } |
129 |
| } |
130 |
| |
131 |
247
| public void setRequest(WebRequest request)
|
132 |
| { |
133 |
247
| _request = request;
|
134 |
| } |
135 |
| |
136 |
3
| public ClientPropertyPersistenceScope getScope()
|
137 |
| { |
138 |
3
| return _scope;
|
139 |
| } |
140 |
| |
141 |
247
| public void setScope(ClientPropertyPersistenceScope scope)
|
142 |
| { |
143 |
247
| _scope = scope;
|
144 |
| } |
145 |
| |
146 |
248
| public void setEncoder(PersistentPropertyDataEncoder encoder)
|
147 |
| { |
148 |
248
| _encoder = encoder;
|
149 |
| } |
150 |
| } |