|
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 |
741
| public void initializeService()
|
|
61 |
| { |
|
62 |
741
| List names = _request.getParameterNames();
|
|
63 |
741
| Iterator i = names.iterator();
|
|
64 |
741
| while (i.hasNext())
|
|
65 |
| { |
|
66 |
2133
| String name = (String) i.next();
|
|
67 |
| |
|
68 |
2133
| if (!_scope.isParameterForScope(name))
|
|
69 |
2121
| continue;
|
|
70 |
| |
|
71 |
12
| String pageName = _scope.extractPageName(name);
|
|
72 |
| |
|
73 |
12
| String encoded = _request.getParameterValue(name);
|
|
74 |
| |
|
75 |
12
| PersistentPropertyData data = new PersistentPropertyData(_encoder);
|
|
76 |
12
| data.storeEncoded(encoded);
|
|
77 |
| |
|
78 |
12
| _data.put(pageName, data);
|
|
79 |
| } |
|
80 |
| } |
|
81 |
| |
|
82 |
3
| public void store(String pageName, String idPath, String propertyName, Object newValue)
|
|
83 |
| { |
|
84 |
3
| PersistentPropertyData data = (PersistentPropertyData) _data.get(pageName);
|
|
85 |
3
| if (data == null)
|
|
86 |
| { |
|
87 |
3
| data = new PersistentPropertyData(_encoder);
|
|
88 |
3
| _data.put(pageName, data);
|
|
89 |
| } |
|
90 |
| |
|
91 |
3
| data.store(idPath, propertyName, newValue);
|
|
92 |
| } |
|
93 |
| |
|
94 |
1587
| public Collection getStoredChanges(String pageName)
|
|
95 |
| { |
|
96 |
1587
| PersistentPropertyData data = (PersistentPropertyData) _data.get(pageName);
|
|
97 |
| |
|
98 |
1587
| if (data == null)
|
|
99 |
1581
| return Collections.EMPTY_LIST;
|
|
100 |
| |
|
101 |
6
| return data.getPageChanges();
|
|
102 |
| } |
|
103 |
| |
|
104 |
3
| public void discardStoredChanges(String pageName)
|
|
105 |
| { |
|
106 |
3
| _data.remove(pageName);
|
|
107 |
| } |
|
108 |
| |
|
109 |
1014
| public void addParametersForPersistentProperties(ServiceEncoding encoding, boolean post)
|
|
110 |
| { |
|
111 |
1014
| Defense.notNull(encoding, "encoding");
|
|
112 |
| |
|
113 |
1014
| Iterator i = _data.entrySet().iterator();
|
|
114 |
1014
| while (i.hasNext())
|
|
115 |
| { |
|
116 |
9
| Map.Entry e = (Map.Entry) i.next();
|
|
117 |
| |
|
118 |
9
| String pageName = (String) e.getKey();
|
|
119 |
9
| PersistentPropertyData data = (PersistentPropertyData) e.getValue();
|
|
120 |
| |
|
121 |
9
| ClientPropertyPersistenceScope scope = getScope();
|
|
122 |
| |
|
123 |
9
| if (scope.shouldEncodeState(encoding, pageName, data))
|
|
124 |
| { |
|
125 |
6
| String parameterName = _scope.constructParameterName(pageName);
|
|
126 |
6
| encoding.setParameterValue(parameterName, data.getEncoded());
|
|
127 |
| } |
|
128 |
| } |
|
129 |
| } |
|
130 |
| |
|
131 |
741
| public void setRequest(WebRequest request)
|
|
132 |
| { |
|
133 |
741
| _request = request;
|
|
134 |
| } |
|
135 |
| |
|
136 |
9
| public ClientPropertyPersistenceScope getScope()
|
|
137 |
| { |
|
138 |
9
| return _scope;
|
|
139 |
| } |
|
140 |
| |
|
141 |
741
| public void setScope(ClientPropertyPersistenceScope scope)
|
|
142 |
| { |
|
143 |
741
| _scope = scope;
|
|
144 |
| } |
|
145 |
| |
|
146 |
744
| public void setEncoder(PersistentPropertyDataEncoder encoder)
|
|
147 |
| { |
|
148 |
744
| _encoder = encoder;
|
|
149 |
| } |
|
150 |
| } |