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.decoration;
35
36 import javax.jcr.AccessDeniedException;
37 import javax.jcr.Item;
38 import javax.jcr.ItemExistsException;
39 import javax.jcr.ItemNotFoundException;
40 import javax.jcr.Node;
41 import javax.jcr.NodeIterator;
42 import javax.jcr.PathNotFoundException;
43 import javax.jcr.Property;
44 import javax.jcr.PropertyIterator;
45 import javax.jcr.RepositoryException;
46 import javax.jcr.Session;
47 import javax.jcr.lock.LockException;
48 import javax.jcr.nodetype.ConstraintViolationException;
49 import javax.jcr.nodetype.NoSuchNodeTypeException;
50 import javax.jcr.version.VersionException;
51
52 import info.magnolia.jcr.wrapper.DelegateNodeWrapper;
53
54
55
56
57
58
59 public class ContentDecoratorNodeWrapper extends DelegateNodeWrapper {
60
61 private final ContentDecorator contentDecorator;
62
63 public ContentDecoratorNodeWrapper(Node node, ContentDecorator contentDecorator) {
64 super(node);
65 this.contentDecorator = contentDecorator;
66 }
67
68 @Override
69 public Session getSession() throws RepositoryException {
70 return wrapSession(super.getSession());
71 }
72
73 @Override
74 public Item getAncestor(int depth) throws ItemNotFoundException, AccessDeniedException, RepositoryException {
75 Item item = super.getAncestor(depth);
76 if (item.isNode()) {
77 return wrapNode((Node) item);
78 } else {
79 return wrapProperty((Property) item);
80 }
81 }
82
83 @Override
84 public Node getParent() throws ItemNotFoundException, AccessDeniedException, RepositoryException {
85 return wrapNode(super.getParent());
86 }
87
88 @Override
89 public Node addNode(String relPath) throws ItemExistsException, PathNotFoundException, VersionException, ConstraintViolationException, LockException, RepositoryException {
90 return wrapNode(super.addNode(relPath));
91 }
92
93 @Override
94 public Node addNode(String relPath, String primaryNodeTypeName) throws ItemExistsException, PathNotFoundException, NoSuchNodeTypeException, LockException, VersionException, ConstraintViolationException, RepositoryException {
95 return wrapNode(super.addNode(relPath, primaryNodeTypeName));
96 }
97
98 @Override
99 public Node getNode(String relPath) throws PathNotFoundException, RepositoryException {
100 Node node = super.getNode(relPath);
101 if (!contentDecorator.evaluateNode(node)) {
102 throw new PathNotFoundException(relPath);
103 }
104 return wrapNode(node);
105 }
106
107 @Override
108 public NodeIterator getNodes() throws RepositoryException {
109 return wrapNodeIterator(super.getNodes());
110 }
111
112 @Override
113 public NodeIterator getNodes(String namePattern) throws RepositoryException {
114 return wrapNodeIterator(super.getNodes(namePattern));
115 }
116
117 @Override
118 public NodeIterator getNodes(String[] nameGlobs) throws RepositoryException {
119 return wrapNodeIterator(super.getNodes(nameGlobs));
120 }
121
122 @Override
123 public boolean hasNode(String relPath) throws RepositoryException {
124 return super.hasNode(relPath) && contentDecorator.evaluateNode(super.getNode(relPath));
125 }
126
127 @Override
128 public boolean hasNodes() throws RepositoryException {
129 return getNodes().hasNext();
130 }
131
132 @Override
133 public PropertyIterator getProperties() throws RepositoryException {
134 return wrapPropertyIterator(super.getProperties());
135 }
136
137 @Override
138 public PropertyIterator getProperties(String namePattern) throws RepositoryException {
139 return wrapPropertyIterator(super.getProperties(namePattern));
140 }
141
142 @Override
143 public PropertyIterator getProperties(String[] nameGlobs) throws RepositoryException {
144 return wrapPropertyIterator(super.getProperties(nameGlobs));
145 }
146
147 @Override
148 public PropertyIterator getWeakReferences() throws RepositoryException {
149 return wrapPropertyIterator(super.getWeakReferences());
150 }
151
152 @Override
153 public Property getProperty(String relPath) throws PathNotFoundException, RepositoryException {
154 return wrapProperty(super.getProperty(relPath));
155 }
156
157 @Override
158 public PropertyIterator getReferences(String name) throws RepositoryException {
159 return wrapPropertyIterator(super.getReferences(name));
160 }
161
162 @Override
163 public PropertyIterator getWeakReferences(String name) throws RepositoryException {
164 return wrapPropertyIterator(super.getWeakReferences(name));
165 }
166
167 @Override
168 public PropertyIterator getReferences() throws RepositoryException {
169 return wrapPropertyIterator(super.getReferences());
170 }
171
172 protected Session wrapSession(Session session) {
173 return contentDecorator.wrapSession(session);
174 }
175
176 protected Node wrapNode(Node node) {
177 return contentDecorator.wrapNode(node);
178 }
179
180 protected NodeIterator wrapNodeIterator(NodeIterator nodeIterator) {
181 return contentDecorator.wrapNodeIterator(nodeIterator);
182 }
183
184 protected Property wrapProperty(Property property) {
185 return contentDecorator.wrapProperty(property);
186 }
187
188 protected PropertyIterator wrapPropertyIterator(PropertyIterator propertyIterator) {
189 return contentDecorator.wrapPropertyIterator(propertyIterator);
190 }
191 }