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 public ContentDecorator getContentDecorator() {
69 return contentDecorator;
70 }
71
72 @Override
73 public Session getSession() throws RepositoryException {
74 return wrapSession(super.getSession());
75 }
76
77 @Override
78 public Item getAncestor(int depth) throws ItemNotFoundException, AccessDeniedException, RepositoryException {
79 Item item = super.getAncestor(depth);
80 if (item.isNode()) {
81 return wrapNode((Node) item);
82 } else {
83 return wrapProperty((Property) item);
84 }
85 }
86
87 @Override
88 public Node getParent() throws ItemNotFoundException, AccessDeniedException, RepositoryException {
89 return wrapNode(super.getParent());
90 }
91
92 @Override
93 public Node addNode(String relPath) throws ItemExistsException, PathNotFoundException, VersionException, ConstraintViolationException, LockException, RepositoryException {
94 return wrapNode(super.addNode(relPath));
95 }
96
97 @Override
98 public Node addNode(String relPath, String primaryNodeTypeName) throws ItemExistsException, PathNotFoundException, NoSuchNodeTypeException, LockException, VersionException, ConstraintViolationException, RepositoryException {
99 return wrapNode(super.addNode(relPath, primaryNodeTypeName));
100 }
101
102 @Override
103 public Node getNode(String relPath) throws PathNotFoundException, RepositoryException {
104 Node node = super.getNode(relPath);
105 if (!contentDecorator.evaluateNode(node)) {
106 throw new PathNotFoundException(relPath);
107 }
108 return wrapNode(node);
109 }
110
111 @Override
112 public NodeIterator getNodes() throws RepositoryException {
113 return wrapNodeIterator(super.getNodes());
114 }
115
116 @Override
117 public NodeIterator getNodes(String namePattern) throws RepositoryException {
118 return wrapNodeIterator(super.getNodes(namePattern));
119 }
120
121 @Override
122 public NodeIterator getNodes(String[] nameGlobs) throws RepositoryException {
123 return wrapNodeIterator(super.getNodes(nameGlobs));
124 }
125
126 @Override
127 public boolean hasNode(String relPath) throws RepositoryException {
128 return super.hasNode(relPath) && contentDecorator.evaluateNode(super.getNode(relPath));
129 }
130
131 @Override
132 public boolean hasNodes() throws RepositoryException {
133 return getNodes().hasNext();
134 }
135
136 @Override
137 public PropertyIterator getProperties() throws RepositoryException {
138 return wrapPropertyIterator(super.getProperties());
139 }
140
141 @Override
142 public PropertyIterator getProperties(String namePattern) throws RepositoryException {
143 return wrapPropertyIterator(super.getProperties(namePattern));
144 }
145
146 @Override
147 public PropertyIterator getProperties(String[] nameGlobs) throws RepositoryException {
148 return wrapPropertyIterator(super.getProperties(nameGlobs));
149 }
150
151 @Override
152 public PropertyIterator getWeakReferences() throws RepositoryException {
153 return wrapPropertyIterator(super.getWeakReferences());
154 }
155
156 @Override
157 public Property getProperty(String relPath) throws PathNotFoundException, RepositoryException {
158 return wrapProperty(super.getProperty(relPath));
159 }
160
161 @Override
162 public PropertyIterator getReferences(String name) throws RepositoryException {
163 return wrapPropertyIterator(super.getReferences(name));
164 }
165
166 @Override
167 public PropertyIterator getWeakReferences(String name) throws RepositoryException {
168 return wrapPropertyIterator(super.getWeakReferences(name));
169 }
170
171 @Override
172 public PropertyIterator getReferences() throws RepositoryException {
173 return wrapPropertyIterator(super.getReferences());
174 }
175
176 protected Session wrapSession(Session session) {
177 return contentDecorator.wrapSession(session);
178 }
179
180 protected Node wrapNode(Node node) {
181 return contentDecorator.wrapNode(node);
182 }
183
184 protected NodeIterator wrapNodeIterator(NodeIterator nodeIterator) {
185 return contentDecorator.wrapNodeIterator(nodeIterator);
186 }
187
188 protected Property wrapProperty(Property property) {
189 return contentDecorator.wrapProperty(property);
190 }
191
192 protected PropertyIterator wrapPropertyIterator(PropertyIterator propertyIterator) {
193 return contentDecorator.wrapPropertyIterator(propertyIterator);
194 }
195 }