1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34 package info.magnolia.jcr.wrapper;
35
36 import info.magnolia.jcr.decoration.ContentDecoratorNodeWrapper;
37 import info.magnolia.jcr.util.NodeTypes;
38 import info.magnolia.repository.RepositoryConstants;
39
40 import java.io.InputStream;
41 import java.math.BigDecimal;
42 import java.util.ArrayList;
43 import java.util.Calendar;
44 import java.util.List;
45
46 import javax.jcr.AccessDeniedException;
47 import javax.jcr.Binary;
48 import javax.jcr.InvalidItemStateException;
49 import javax.jcr.ItemExistsException;
50 import javax.jcr.ItemNotFoundException;
51 import javax.jcr.Node;
52 import javax.jcr.PathNotFoundException;
53 import javax.jcr.Property;
54 import javax.jcr.ReferentialIntegrityException;
55 import javax.jcr.RepositoryException;
56 import javax.jcr.UnsupportedRepositoryOperationException;
57 import javax.jcr.Value;
58 import javax.jcr.ValueFormatException;
59 import javax.jcr.lock.LockException;
60 import javax.jcr.nodetype.ConstraintViolationException;
61 import javax.jcr.nodetype.NoSuchNodeTypeException;
62 import javax.jcr.version.Version;
63 import javax.jcr.version.VersionException;
64
65 import org.apache.commons.lang.StringUtils;
66 import org.slf4j.Logger;
67 import org.slf4j.LoggerFactory;
68
69
70
71
72 public class LastUpdateNodeWrapper extends ContentDecoratorNodeWrapper<LastUpdateContentDecorator> {
73
74 private static Logger log = LoggerFactory.getLogger(LastUpdateNodeWrapper.class);
75
76 private List<String> saveOnSave = new ArrayList<String>();
77
78 public LastUpdateNodeWrapper(Node node, LastUpdateContentDecorator lastUpdateContentDecorator) {
79 super(node, lastUpdateContentDecorator);
80 }
81
82 @Override
83 public Property setProperty(String name, BigDecimal value) throws ValueFormatException, VersionException, LockException, ConstraintViolationException, RepositoryException {
84 final Property prop = super.setProperty(name, value);
85 this.updateLastModifiedProperty(name);
86 return prop;
87 }
88
89 @Override
90 public void setPrimaryType(String nodeTypeName) throws NoSuchNodeTypeException, VersionException, ConstraintViolationException, LockException, RepositoryException {
91 super.setPrimaryType(nodeTypeName);
92 this.updateLastModified();
93 }
94
95 @Override
96 public Property setProperty(String name, Binary value) throws ValueFormatException, VersionException, LockException, ConstraintViolationException, RepositoryException {
97 final Property prop = super.setProperty(name, value);
98 this.updateLastModifiedProperty(name);
99 return prop;
100 }
101
102 @Override
103 public Property setProperty(String name, boolean value) throws ValueFormatException, VersionException, LockException, ConstraintViolationException, RepositoryException {
104 final Property prop = super.setProperty(name, value);
105 this.updateLastModifiedProperty(name);
106 return prop;
107 }
108
109 @Override
110 public Property setProperty(String name, Calendar value) throws ValueFormatException, VersionException, LockException, ConstraintViolationException, RepositoryException {
111 final Property prop = super.setProperty(name, value);
112 this.updateLastModifiedProperty(name);
113 return prop;
114 }
115
116 @Override
117 public Property setProperty(String name, double value) throws ValueFormatException, VersionException, LockException, ConstraintViolationException, RepositoryException {
118 final Property prop = super.setProperty(name, value);
119 this.updateLastModifiedProperty(name);
120 return prop;
121 }
122
123 @Override
124 public Property setProperty(String name, InputStream value) throws ValueFormatException, VersionException, LockException, ConstraintViolationException, RepositoryException {
125 final Property prop = super.setProperty(name, value);
126 this.updateLastModifiedProperty(name);
127 return prop;
128 }
129
130 @Override
131 public Property setProperty(String name, long value) throws ValueFormatException, VersionException, LockException, ConstraintViolationException, RepositoryException {
132 final Property prop = super.setProperty(name, value);
133 this.updateLastModifiedProperty(name);
134 return prop;
135 }
136
137 @Override
138 public Property setProperty(String name, Node value) throws ValueFormatException, VersionException, LockException, ConstraintViolationException, RepositoryException {
139 final Property prop = super.setProperty(name, value);
140 this.updateLastModifiedProperty(name);
141 return prop;
142 }
143
144 @Override
145 public Property setProperty(String name, String value) throws ValueFormatException, VersionException, LockException, ConstraintViolationException, RepositoryException {
146 final Property prop = super.setProperty(name, value);
147 this.updateLastModifiedProperty(name);
148 return prop;
149 }
150
151 @Override
152 public Property setProperty(String name, String value, int type) throws ValueFormatException, VersionException, LockException, ConstraintViolationException, RepositoryException {
153 final Property prop = super.setProperty(name, value, type);
154 this.updateLastModifiedProperty(name);
155 return prop;
156 }
157
158 @Override
159 public Property setProperty(String name, String[] values) throws ValueFormatException, VersionException, LockException, ConstraintViolationException, RepositoryException {
160 final Property prop = super.setProperty(name, values);
161 this.updateLastModifiedProperty(name);
162 return prop;
163 }
164
165 @Override
166 public Property setProperty(String name, String[] values, int type) throws ValueFormatException, VersionException, LockException, ConstraintViolationException, RepositoryException {
167 final Property prop = super.setProperty(name, values, type);
168 this.updateLastModifiedProperty(name);
169 return prop;
170 }
171
172 @Override
173 public Property setProperty(String name, Value value) throws ValueFormatException, VersionException, LockException, ConstraintViolationException, RepositoryException {
174 final Property prop = super.setProperty(name, value);
175 this.updateLastModifiedProperty(name);
176 return prop;
177 }
178
179 @Override
180 public Property setProperty(String name, Value value, int type) throws ValueFormatException, VersionException, LockException, ConstraintViolationException, RepositoryException {
181 final Property prop = super.setProperty(name, value, type);
182 this.updateLastModifiedProperty(name);
183 return prop;
184 }
185
186 @Override
187 public Property setProperty(String name, Value[] values) throws ValueFormatException, VersionException, LockException, ConstraintViolationException, RepositoryException {
188 final Property prop = super.setProperty(name, values);
189 this.updateLastModifiedProperty(name);
190 return prop;
191 }
192
193 @Override
194 public Property setProperty(String name, Value[] values, int type) throws ValueFormatException, VersionException, LockException, ConstraintViolationException, RepositoryException {
195 final Property prop = super.setProperty(name, values, type);
196 this.updateLastModifiedProperty(name);
197 return prop;
198 }
199
200 @Override
201 public Node addNode(String relPath) throws ItemExistsException, PathNotFoundException, VersionException, ConstraintViolationException, LockException, RepositoryException {
202 Node node = super.addNode(relPath);
203 this.updateLastModified();
204 return node;
205 }
206
207 @Override
208 public Node addNode(String relPath, String primaryNodeTypeName) throws ItemExistsException, PathNotFoundException, NoSuchNodeTypeException, LockException, VersionException, ConstraintViolationException, RepositoryException {
209 Node node = super.addNode(relPath, primaryNodeTypeName);
210 if (RepositoryConstants.WEBSITE.equals(this.getSession().getWorkspace().getName()) && NodeTypes.Page.NAME.equals(primaryNodeTypeName)) {
211
212 } else {
213 this.updateLastModified();
214 }
215 return node;
216 }
217
218 @Override
219 public void orderBefore(String srcChildRelPath, String destChildRelPath) throws UnsupportedRepositoryOperationException, VersionException, ConstraintViolationException, ItemNotFoundException, LockException, RepositoryException {
220 super.orderBefore(srcChildRelPath, destChildRelPath);
221 String path = StringUtils.removeEnd(this.getPath(), "/") + "/" + srcChildRelPath;
222
223 updateLastModified(path, false);
224 this.saveOnSave.add(srcChildRelPath);
225 }
226
227 @Override
228 public void doneMerge(Version version) throws VersionException, InvalidItemStateException, UnsupportedRepositoryOperationException, RepositoryException {
229 super.doneMerge(version);
230 this.updateLastModified();
231 }
232
233 @Override
234 public void remove() throws VersionException, LockException, ConstraintViolationException, AccessDeniedException, RepositoryException {
235 Node parent = this.getParent();
236 super.remove();
237 String workspaceName = this.getSession().getWorkspace().getName();
238
239 if (RepositoryConstants.WEBSITE.equals(workspaceName)) {
240 getContentDecorator().updateLastModified(workspaceName, parent.getPath());
241 }
242 }
243
244 @Override
245 public void restore(String versionName, boolean removeExisting) throws VersionException, ItemExistsException, UnsupportedRepositoryOperationException, LockException, InvalidItemStateException, RepositoryException {
246 super.restore(versionName, removeExisting);
247 this.updateLastModified();
248 }
249
250 @Override
251 public void restore(Version version, boolean removeExisting) throws VersionException, ItemExistsException, InvalidItemStateException, UnsupportedRepositoryOperationException, LockException, RepositoryException {
252 super.restore(version, removeExisting);
253 this.updateLastModified();
254 }
255
256 @Override
257 public void restore(Version version, String relPath, boolean removeExisting) throws PathNotFoundException, ItemExistsException, VersionException, ConstraintViolationException, UnsupportedRepositoryOperationException, LockException, InvalidItemStateException, RepositoryException {
258 super.restore(version, relPath, removeExisting);
259 this.updateLastModified();
260 }
261
262 @Override
263 public void restoreByLabel(String versionLabel, boolean removeExisting) throws VersionException, ItemExistsException, UnsupportedRepositoryOperationException, LockException, InvalidItemStateException, RepositoryException {
264 super.restoreByLabel(versionLabel, removeExisting);
265 this.updateLastModified();
266 }
267
268 @Override
269 public void save() throws AccessDeniedException, ItemExistsException, ConstraintViolationException, InvalidItemStateException, ReferentialIntegrityException, VersionException, LockException, NoSuchNodeTypeException, RepositoryException {
270 super.save();
271
272 for (String child : saveOnSave) {
273 log.debug("forcing on child: " + this.getSession().toString() + "::" + child);
274 this.getNode(child).save();
275 }
276 saveOnSave.clear();
277 }
278
279 private void updateLastModified() throws PathNotFoundException, RepositoryException {
280 if (this.isNew()) {
281
282 return;
283 }
284 getContentDecorator().updateLastModified(this.getSession().getWorkspace().getName(), this.getPath());
285 }
286
287 private void updateLastModified(String path, boolean recursiveDown) throws PathNotFoundException, RepositoryException {
288 if (this.isNew()) {
289
290 return;
291 }
292 getContentDecorator().updateLastModified(this.getSession().getWorkspace().getName(), path, recursiveDown);
293 }
294
295 private void updateLastModifiedProperty(String name) throws PathNotFoundException, RepositoryException {
296 if (this.isNew()) {
297
298 return;
299 }
300 getContentDecorator().updateLastModifiedProperty(this.getSession().getWorkspace().getName(), name, this.getPath());
301 }
302 }