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.cms.util;
35
36 import info.magnolia.cms.core.AbstractContent;
37 import info.magnolia.cms.core.Content;
38 import info.magnolia.cms.core.HierarchyManager;
39 import info.magnolia.cms.core.ItemType;
40 import info.magnolia.cms.core.MetaData;
41 import info.magnolia.cms.core.NodeData;
42 import info.magnolia.cms.core.version.ContentVersion;
43 import info.magnolia.cms.security.AccessDeniedException;
44
45 import java.util.ArrayList;
46 import java.util.Collection;
47 import java.util.Comparator;
48
49 import javax.jcr.Node;
50 import javax.jcr.RepositoryException;
51 import javax.jcr.Workspace;
52 import javax.jcr.lock.Lock;
53 import javax.jcr.nodetype.NodeType;
54 import javax.jcr.version.Version;
55 import javax.jcr.version.VersionHistory;
56 import javax.jcr.version.VersionIterator;
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80 @Deprecated
81 public abstract class ContentWrapper extends AbstractContent {
82
83 private Content wrappedContent;
84
85
86
87
88 @Deprecated
89 public ContentWrapper() {
90 }
91
92 public ContentWrapper(Content wrappedContent) {
93 this.wrappedContent = wrappedContent;
94 }
95
96 public Content getWrappedContent() {
97 return this.wrappedContent;
98 }
99
100
101
102
103 @Deprecated
104 public void setWrappedContent(Content wrappedContent) {
105 this.wrappedContent = wrappedContent;
106 }
107
108
109
110
111
112 protected Content wrap(Content node) {
113 return node;
114 }
115
116
117
118
119 protected NodeData wrap(NodeData nodeData) {
120 return nodeData;
121 }
122
123
124
125
126
127 protected Collection<Content> wrapContentNodes(Collection<Content> collection) {
128 ArrayList<Content> wrapped = new ArrayList<Content>();
129 for (Content content : collection) {
130 wrapped.add(wrap(content));
131 }
132 return wrapped;
133 }
134
135
136
137
138
139 protected Collection<NodeData> wrapNodeDatas(Collection<NodeData> collection) {
140 ArrayList<NodeData> wrapped = new ArrayList<NodeData>();
141 for (NodeData nodeData : collection) {
142 wrapped.add(wrap(nodeData));
143 }
144 return wrapped;
145 }
146
147 @Override
148 public String toString() {
149 final StringBuilder buffer = new StringBuilder();
150 buffer.append(getClass().getSimpleName());
151 buffer.append(" for ");
152 buffer.append(super.toString());
153 return buffer.toString();
154 }
155
156 @Override
157 public Collection<Content> getChildren(ContentFilter filter, String namePattern, Comparator<Content> orderCriteria) {
158 Content content = getWrappedContent();
159 if (content instanceof AbstractContent) {
160
161 Collection<Content> children = ((AbstractContent) content).getChildren(ContentUtil.ALL_NODES_CONTENT_FILTER, namePattern, orderCriteria);
162
163 Collection<Content> wrappedChildren = wrapContentNodes(children);
164
165 Collection<Content> filteredChildren = new ArrayList<Content>();
166 for (Content wrappedChild : wrappedChildren) {
167 if (filter.accept(wrappedChild)) {
168 filteredChildren.add(wrappedChild);
169 }
170 }
171 return filteredChildren;
172 }
173 throw new IllegalStateException("This wrapper supports only wrapping AbstractContent objects by default. Please override this method.");
174 }
175
176 @Override
177 public NodeData newNodeDataInstance(String name, int type, boolean createIfNotExisting) throws AccessDeniedException, RepositoryException {
178 Content content = getWrappedContent();
179 if (content instanceof AbstractContent) {
180 return wrap(((AbstractContent) content).newNodeDataInstance(name, type, createIfNotExisting));
181 }
182 throw new IllegalStateException("This wrapper supports only wrapping AbstractContent objects by default. Please override this method.");
183 }
184
185
186
187
188
189 @Override
190 public void addMixin(String type) throws RepositoryException {
191 this.getWrappedContent().addMixin(type);
192 }
193
194 @Override
195 public Version addVersion() throws RepositoryException {
196 return this.getWrappedContent().addVersion();
197 }
198
199 @Override
200 public Version addVersion(Rule rule) throws RepositoryException {
201 return this.getWrappedContent().addVersion(rule);
202 }
203
204 @Override
205 public Content createContent(String name, String contentType) throws RepositoryException {
206 return wrap(this.getWrappedContent().createContent(name, contentType));
207 }
208
209 @Override
210 public void delete() throws RepositoryException {
211 this.getWrappedContent().delete();
212 }
213
214 @Override
215 public void deleteNodeData(String name) throws RepositoryException {
216 this.getWrappedContent().deleteNodeData(name);
217 }
218
219 @Override
220 public VersionIterator getAllVersions() throws RepositoryException {
221 return this.getWrappedContent().getAllVersions();
222 }
223
224 @Override
225 public Content getAncestor(int level) throws RepositoryException {
226 return wrap(this.getWrappedContent().getAncestor(level));
227 }
228
229 @Override
230 public Collection<Content> getAncestors() throws RepositoryException {
231 return wrapContentNodes(this.getWrappedContent().getAncestors());
232 }
233
234 @Override
235 public ContentVersion getBaseVersion() throws RepositoryException {
236 return this.getWrappedContent().getBaseVersion();
237 }
238
239
240
241
242 @Deprecated
243 @Override
244 public Content getChildByName(String namePattern) {
245 return wrap(this.getWrappedContent().getChildByName(namePattern));
246 }
247
248 @Override
249 public Content getContent(String name) throws RepositoryException {
250 return wrap(this.getWrappedContent().getContent(name));
251 }
252
253 @Override
254 public String getHandle() {
255 return this.getWrappedContent().getHandle();
256 }
257
258 @Override
259 public int getIndex() throws RepositoryException {
260 return this.getWrappedContent().getIndex();
261 }
262
263 @Override
264 public ItemType getItemType() throws RepositoryException {
265 return this.getWrappedContent().getItemType();
266 }
267
268 @Override
269 public Node getJCRNode() {
270 return this.getWrappedContent().getJCRNode();
271 }
272
273 @Override
274 public int getLevel() throws RepositoryException {
275 return this.getWrappedContent().getLevel();
276 }
277
278 @Override
279 public Lock getLock() throws RepositoryException {
280 return this.getWrappedContent().getLock();
281 }
282
283 @Override
284 public MetaData getMetaData() {
285 return this.getWrappedContent().getMetaData();
286 }
287
288 @Override
289 public NodeType[] getMixinNodeTypes() throws RepositoryException {
290 return this.getWrappedContent().getMixinNodeTypes();
291 }
292
293 @Override
294 public String getName() {
295 return this.getWrappedContent().getName();
296 }
297
298 @Override
299 public Collection<NodeData> getNodeDataCollection(String namePattern) {
300 return wrapNodeDatas(this.getWrappedContent().getNodeDataCollection(namePattern));
301 }
302
303 @Override
304 public NodeType getNodeType() throws RepositoryException {
305 return this.getWrappedContent().getNodeType();
306 }
307
308 @Override
309 public String getNodeTypeName() throws RepositoryException {
310 return this.getWrappedContent().getNodeTypeName();
311 }
312
313 @Override
314 public Content getParent() throws RepositoryException {
315 return wrap(this.getWrappedContent().getParent());
316 }
317
318 @Override
319 public String getTemplate() {
320 return this.getWrappedContent().getTemplate();
321 }
322
323 @Override
324 public String getTitle() {
325 return this.getWrappedContent().getTitle();
326 }
327
328 @Override
329 public String getUUID() {
330 return this.getWrappedContent().getUUID();
331 }
332
333 @Override
334 public ContentVersion getVersionedContent(String versionName) throws RepositoryException {
335 return this.getWrappedContent().getVersionedContent(versionName);
336 }
337
338 @Override
339 public ContentVersion getVersionedContent(Version version) throws RepositoryException {
340 return this.getWrappedContent().getVersionedContent(version);
341 }
342
343 @Override
344 public VersionHistory getVersionHistory() throws RepositoryException {
345 return this.getWrappedContent().getVersionHistory();
346 }
347
348 @Override
349 public Workspace getWorkspace() throws RepositoryException {
350 return this.getWrappedContent().getWorkspace();
351 }
352
353 @Override
354 public boolean hasContent(String name) throws RepositoryException {
355 return getWrappedContent().hasContent(name);
356 }
357
358 @Override
359 public boolean hasMetaData() {
360 return this.getWrappedContent().hasMetaData();
361 }
362
363 @Override
364 public boolean holdsLock() throws RepositoryException {
365 return this.getWrappedContent().holdsLock();
366 }
367
368 @Override
369 public boolean isGranted(long permissions) {
370 return this.getWrappedContent().isGranted(permissions);
371 }
372
373 @Override
374 public boolean isLocked() throws RepositoryException {
375 return this.getWrappedContent().isLocked();
376 }
377
378 @Override
379 public boolean isModified() {
380 return this.getWrappedContent().isModified();
381 }
382
383 @Override
384 public boolean isNodeData(String path) throws RepositoryException {
385 return this.getWrappedContent().isNodeData(path);
386 }
387
388 @Override
389 public boolean isNodeType(String type) {
390 return this.getWrappedContent().isNodeType(type);
391 }
392
393 @Override
394 public Lock lock(boolean isDeep, boolean isSessionScoped, long yieldFor) throws RepositoryException {
395 return this.getWrappedContent().lock(isDeep, isSessionScoped, yieldFor);
396 }
397
398 @Override
399 public Lock lock(boolean isDeep, boolean isSessionScoped) throws RepositoryException {
400 return this.getWrappedContent().lock(isDeep, isSessionScoped);
401 }
402
403 @Override
404 public void orderBefore(String srcName, String beforeName) throws RepositoryException {
405 this.getWrappedContent().orderBefore(srcName, beforeName);
406 }
407
408 @Override
409 public void refresh(boolean keepChanges) throws RepositoryException {
410 this.getWrappedContent().refresh(keepChanges);
411 }
412
413 @Override
414 public void removeMixin(String type) throws RepositoryException {
415 this.getWrappedContent().removeMixin(type);
416 }
417
418 @Override
419 public void removeVersionHistory() throws RepositoryException {
420 this.getWrappedContent().removeVersionHistory();
421 }
422
423 @Override
424 public void restore(String versionName, boolean removeExisting) throws RepositoryException {
425 this.getWrappedContent().restore(versionName, removeExisting);
426 }
427
428 @Override
429 public void restore(Version version, boolean removeExisting) throws RepositoryException {
430 this.getWrappedContent().restore(version, removeExisting);
431 }
432
433 @Override
434 public void restore(Version version, String relPath, boolean removeExisting) throws RepositoryException {
435 this.getWrappedContent().restore(version, relPath, removeExisting);
436 }
437
438 @Override
439 public void restoreByLabel(String versionLabel, boolean removeExisting) throws RepositoryException {
440 this.getWrappedContent().restoreByLabel(versionLabel, removeExisting);
441 }
442
443 @Override
444 public void save() throws RepositoryException {
445 this.getWrappedContent().save();
446 }
447
448 @Override
449 public void unlock() throws RepositoryException {
450 this.getWrappedContent().unlock();
451 }
452
453 @Override
454 public void updateMetaData() throws RepositoryException {
455 this.getWrappedContent().updateMetaData();
456 }
457
458 @Override
459 public HierarchyManager getHierarchyManager() {
460 return this.getWrappedContent().getHierarchyManager();
461 }
462
463 @Override
464 public boolean hasMixin(String mixinName) throws RepositoryException {
465 return this.getWrappedContent().hasMixin(mixinName);
466 }
467 }