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
81
82 public abstract class ContentWrapper extends AbstractContent {
83
84 private Content wrappedContent;
85
86
87
88
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 public void setWrappedContent(Content wrappedContent) {
104 this.wrappedContent = wrappedContent;
105 }
106
107
108
109
110
111 protected Content wrap(Content node) {
112 return node;
113 }
114
115
116
117
118 protected NodeData wrap(NodeData nodeData) {
119 return nodeData;
120 }
121
122
123
124
125
126 protected Collection<Content> wrapContentNodes(Collection<Content> collection) {
127 ArrayList<Content> wrapped = new ArrayList<Content>();
128 for (Content content : collection) {
129 wrapped.add(wrap(content));
130 }
131 return wrapped;
132 }
133
134
135
136
137
138 protected Collection<NodeData> wrapNodeDatas(Collection<NodeData> collection) {
139 ArrayList<NodeData> wrapped = new ArrayList<NodeData>();
140 for (NodeData nodeData : collection) {
141 wrapped.add(wrap(nodeData));
142 }
143 return wrapped;
144 }
145
146 public String toString() {
147 final StringBuilder buffer = new StringBuilder();
148 buffer.append(getClass().getSimpleName());
149 buffer.append(" for ");
150 buffer.append(super.toString());
151 return buffer.toString();
152 }
153
154 public Collection<Content> getChildren(ContentFilter filter, String namePattern, Comparator<Content> orderCriteria) {
155 Content content = getWrappedContent();
156 if(content instanceof AbstractContent){
157 return wrapContentNodes(((AbstractContent) content).getChildren(filter, namePattern, orderCriteria));
158 }
159 throw new IllegalStateException("This wrapper supports only wrapping AbstractContent objects by default. Please override this method.");
160 }
161
162 @Override
163 public NodeData newNodeDataInstance(String name, int type, boolean createIfNotExisting) throws AccessDeniedException, RepositoryException {
164 Content content = getWrappedContent();
165 if(content instanceof AbstractContent){
166 return wrap(((AbstractContent)content).newNodeDataInstance(name, type, createIfNotExisting));
167 }
168 throw new IllegalStateException("This wrapper supports only wrapping AbstractContent objects by default. Please override this method.");
169 }
170
171
172
173
174
175 public void addMixin(String type) throws RepositoryException {
176 this.getWrappedContent().addMixin(type);
177 }
178
179 public Version addVersion() throws RepositoryException {
180 return this.getWrappedContent().addVersion();
181 }
182
183 public Version addVersion(Rule rule) throws RepositoryException {
184 return this.getWrappedContent().addVersion(rule);
185 }
186
187 public Content createContent(String name, String contentType) throws RepositoryException {
188 return wrap(this.getWrappedContent().createContent(name, contentType));
189 }
190
191 public void delete() throws RepositoryException {
192 this.getWrappedContent().delete();
193 }
194
195 public void deleteNodeData(String name) throws RepositoryException {
196 this.getWrappedContent().deleteNodeData(name);
197 }
198
199 public VersionIterator getAllVersions() throws RepositoryException {
200 return this.getWrappedContent().getAllVersions();
201 }
202
203 public Content getAncestor(int level) throws RepositoryException {
204 return wrap(this.getWrappedContent().getAncestor(level));
205 }
206
207 public Collection<Content> getAncestors() throws RepositoryException {
208 return wrapContentNodes(this.getWrappedContent().getAncestors());
209 }
210
211 public ContentVersion getBaseVersion() throws RepositoryException {
212 return this.getWrappedContent().getBaseVersion();
213 }
214
215
216
217
218 public Content getChildByName(String namePattern) {
219 return wrap(this.getWrappedContent().getChildByName(namePattern));
220 }
221
222 public Content getContent(String name) throws RepositoryException {
223 return wrap(this.getWrappedContent().getContent(name));
224 }
225
226 public String getHandle() {
227 return this.getWrappedContent().getHandle();
228 }
229
230 public int getIndex() throws RepositoryException {
231 return this.getWrappedContent().getIndex();
232 }
233
234 public ItemType getItemType() throws RepositoryException {
235 return this.getWrappedContent().getItemType();
236 }
237
238 public Node getJCRNode() {
239 return this.getWrappedContent().getJCRNode();
240 }
241
242 public int getLevel() throws RepositoryException {
243 return this.getWrappedContent().getLevel();
244 }
245
246 public Lock getLock() throws RepositoryException {
247 return this.getWrappedContent().getLock();
248 }
249
250 public MetaData getMetaData() {
251 return this.getWrappedContent().getMetaData();
252 }
253
254 public NodeType[] getMixinNodeTypes() throws RepositoryException {
255 return this.getWrappedContent().getMixinNodeTypes();
256 }
257
258 public String getName() {
259 return this.getWrappedContent().getName();
260 }
261
262 public Collection<NodeData> getNodeDataCollection(String namePattern) {
263 return wrapNodeDatas(this.getWrappedContent().getNodeDataCollection(namePattern));
264 }
265
266 public NodeType getNodeType() throws RepositoryException {
267 return this.getWrappedContent().getNodeType();
268 }
269
270 public String getNodeTypeName() throws RepositoryException {
271 return this.getWrappedContent().getNodeTypeName();
272 }
273
274 public Content getParent() throws RepositoryException {
275 return wrap(this.getWrappedContent().getParent());
276 }
277
278 public String getTemplate() {
279 return this.getWrappedContent().getTemplate();
280 }
281
282 public String getTitle() {
283 return this.getWrappedContent().getTitle();
284 }
285
286 public String getUUID() {
287 return this.getWrappedContent().getUUID();
288 }
289
290 public ContentVersion getVersionedContent(String versionName) throws RepositoryException {
291 return this.getWrappedContent().getVersionedContent(versionName);
292 }
293
294 public ContentVersion getVersionedContent(Version version) throws RepositoryException {
295 return this.getWrappedContent().getVersionedContent(version);
296 }
297
298 public VersionHistory getVersionHistory() throws RepositoryException {
299 return this.getWrappedContent().getVersionHistory();
300 }
301
302 public Workspace getWorkspace() throws RepositoryException {
303 return this.getWrappedContent().getWorkspace();
304 }
305
306 public boolean hasContent(String name) throws RepositoryException {
307 return getWrappedContent().hasContent(name);
308 }
309
310 public boolean hasMetaData() {
311 return this.getWrappedContent().hasMetaData();
312 }
313
314 public boolean holdsLock() throws RepositoryException {
315 return this.getWrappedContent().holdsLock();
316 }
317
318 public boolean isGranted(long permissions) {
319 return this.getWrappedContent().isGranted(permissions);
320 }
321
322 public boolean isLocked() throws RepositoryException {
323 return this.getWrappedContent().isLocked();
324 }
325
326 public boolean isModified() {
327 return this.getWrappedContent().isModified();
328 }
329
330 public boolean isNodeData(String path) throws RepositoryException {
331 return this.getWrappedContent().isNodeData(path);
332 }
333
334 public boolean isNodeType(String type) {
335 return this.getWrappedContent().isNodeType(type);
336 }
337
338 public Lock lock(boolean isDeep, boolean isSessionScoped, long yieldFor) throws RepositoryException {
339 return this.getWrappedContent().lock(isDeep, isSessionScoped, yieldFor);
340 }
341
342 public Lock lock(boolean isDeep, boolean isSessionScoped) throws RepositoryException {
343 return this.getWrappedContent().lock(isDeep, isSessionScoped);
344 }
345
346 public void orderBefore(String srcName, String beforeName) throws RepositoryException {
347 this.getWrappedContent().orderBefore(srcName, beforeName);
348 }
349
350 public void refresh(boolean keepChanges) throws RepositoryException {
351 this.getWrappedContent().refresh(keepChanges);
352 }
353
354 public void removeMixin(String type) throws RepositoryException {
355 this.getWrappedContent().removeMixin(type);
356 }
357
358 public void removeVersionHistory() throws RepositoryException {
359 this.getWrappedContent().removeVersionHistory();
360 }
361
362 public void restore(String versionName, boolean removeExisting) throws RepositoryException {
363 this.getWrappedContent().restore(versionName, removeExisting);
364 }
365
366 public void restore(Version version, boolean removeExisting) throws RepositoryException {
367 this.getWrappedContent().restore(version, removeExisting);
368 }
369
370 public void restore(Version version, String relPath, boolean removeExisting) throws RepositoryException {
371 this.getWrappedContent().restore(version, relPath, removeExisting);
372 }
373
374 public void restoreByLabel(String versionLabel, boolean removeExisting) throws RepositoryException {
375 this.getWrappedContent().restoreByLabel(versionLabel, removeExisting);
376 }
377
378 public void save() throws RepositoryException {
379 this.getWrappedContent().save();
380 }
381
382 public void unlock() throws RepositoryException {
383 this.getWrappedContent().unlock();
384 }
385
386 public void updateMetaData() throws RepositoryException {
387 this.getWrappedContent().updateMetaData();
388 }
389
390 public HierarchyManager getHierarchyManager(){
391 return this.getWrappedContent().getHierarchyManager();
392 }
393
394 }