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 MgnlPropertySettingNodeWrapper extends ContentDecoratorNodeWrapper<MgnlPropertySettingContentDecorator> {
73
74 private static Logger log = LoggerFactory.getLogger(MgnlPropertySettingNodeWrapper.class);
75
76 private List<String> saveOnSave = new ArrayList<String>();
77
78 public MgnlPropertySettingNodeWrapper(Node node, MgnlPropertySettingContentDecorator decorator) {
79 super(node, decorator);
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 setCreatedProperty(node.getPath());
205 return node;
206 }
207
208 @Override
209 public Node addNode(String relPath, String primaryNodeTypeName) throws ItemExistsException, PathNotFoundException, NoSuchNodeTypeException, LockException, VersionException, ConstraintViolationException, RepositoryException {
210 Node node = super.addNode(relPath, primaryNodeTypeName);
211 if (RepositoryConstants.WEBSITE.equals(this.getSession().getWorkspace().getName()) && NodeTypes.Page.NAME.equals(primaryNodeTypeName)) {
212
213 } else {
214 this.updateLastModified();
215 }
216 setCreatedProperty(node.getPath());
217 return node;
218 }
219
220 @Override
221 public void orderBefore(String srcChildRelPath, String destChildRelPath) throws UnsupportedRepositoryOperationException, VersionException, ConstraintViolationException, ItemNotFoundException, LockException, RepositoryException {
222 super.orderBefore(srcChildRelPath, destChildRelPath);
223 String path = StringUtils.removeEnd(this.getPath(), "/") + "/" + srcChildRelPath;
224
225 updateLastModified(path, false);
226 this.saveOnSave.add(srcChildRelPath);
227 }
228
229 @Override
230 public void doneMerge(Version version) throws VersionException, InvalidItemStateException, UnsupportedRepositoryOperationException, RepositoryException {
231 super.doneMerge(version);
232 this.updateLastModified();
233 }
234
235 @Override
236 public void remove() throws VersionException, LockException, ConstraintViolationException, AccessDeniedException, RepositoryException {
237 Node parent = this.getParent();
238 super.remove();
239 String workspaceName = this.getSession().getWorkspace().getName();
240
241 if (RepositoryConstants.WEBSITE.equals(workspaceName)) {
242 getContentDecorator().updateLastModified(workspaceName, parent.getPath());
243 }
244 }
245
246 @Override
247 public void save() throws AccessDeniedException, ItemExistsException, ConstraintViolationException, InvalidItemStateException, ReferentialIntegrityException, VersionException, LockException, NoSuchNodeTypeException, RepositoryException {
248 super.save();
249
250 for (String child : saveOnSave) {
251 log.debug("forcing on child: " + this.getSession().toString() + "::" + child);
252 this.getNode(child).save();
253 }
254 saveOnSave.clear();
255 }
256
257 private void updateLastModified() throws PathNotFoundException, RepositoryException {
258 if (this.isNew()) {
259
260 return;
261 }
262 getContentDecorator().updateLastModified(this.getSession().getWorkspace().getName(), this.getPath());
263 }
264
265 private void updateLastModified(String path, boolean recursiveDown) throws PathNotFoundException, RepositoryException {
266 if (this.isNew()) {
267
268 return;
269 }
270 getContentDecorator().updateLastModified(this.getSession().getWorkspace().getName(), path, recursiveDown);
271 }
272
273 private void updateLastModifiedProperty(String name) throws PathNotFoundException, RepositoryException {
274 if (this.isNew()) {
275
276 return;
277 }
278 getContentDecorator().updateLastModifiedProperty(this.getSession().getWorkspace().getName(), name, this.getPath());
279 }
280
281 private void setCreatedProperty(final String path) throws RepositoryException {
282 getContentDecorator().setCreatedDate(this.getSession().getWorkspace().getName(), path);
283 }
284 }