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 info.magnolia.jcr.wrapper.DelegateSessionWrapper;
37
38 import javax.jcr.AccessDeniedException;
39 import javax.jcr.Item;
40 import javax.jcr.ItemExistsException;
41 import javax.jcr.ItemNotFoundException;
42 import javax.jcr.Node;
43 import javax.jcr.PathNotFoundException;
44 import javax.jcr.Property;
45 import javax.jcr.RepositoryException;
46 import javax.jcr.Session;
47 import javax.jcr.Workspace;
48 import javax.jcr.lock.LockException;
49 import javax.jcr.nodetype.ConstraintViolationException;
50 import javax.jcr.version.VersionException;
51
52
53
54
55
56
57 public class ContentDecoratorSessionWrapper<D extends ContentDecorator> extends DelegateSessionWrapper {
58
59 private final D contentDecorator;
60
61 public ContentDecoratorSessionWrapper(Session session, D contentDecorator) {
62 super(session);
63 this.contentDecorator = contentDecorator;
64 }
65
66 public D getContentDecorator() {
67 return contentDecorator;
68 }
69
70 @Override
71 public boolean itemExists(String absPath) throws RepositoryException {
72 boolean exists = super.itemExists(absPath);
73 if (!exists) {
74 return false;
75 }
76 Item item = super.getItem(absPath);
77 if (item.isNode()) {
78 return contentDecorator.evaluateNode((Node) item);
79 } else {
80 return contentDecorator.evaluateProperty((Property) item);
81 }
82 }
83
84 @Override
85 public Item getItem(String absPath) throws PathNotFoundException, RepositoryException {
86 Item item = super.getItem(absPath);
87 if (item.isNode()) {
88 if (!contentDecorator.evaluateNode((Node) item)) {
89 throw new PathNotFoundException(absPath);
90 }
91 return wrapNode((Node) item);
92 } else {
93 if (!contentDecorator.evaluateProperty((Property) item)) {
94 throw new PathNotFoundException(absPath);
95 }
96 return wrapProperty((Property) item);
97 }
98 }
99
100 @Override
101 public void removeItem(String absPath) throws VersionException, LockException, ConstraintViolationException, AccessDeniedException, RepositoryException {
102 if (!itemExists(absPath)) {
103 throw new PathNotFoundException(absPath);
104 }
105 super.removeItem(absPath);
106 }
107
108 @Override
109 public Node getRootNode() throws RepositoryException {
110 return wrapNode(super.getRootNode());
111 }
112
113 @Override
114 public boolean nodeExists(String absPath) throws RepositoryException {
115 return super.nodeExists(absPath) && contentDecorator.evaluateNode(super.getNode(absPath));
116 }
117
118 @Override
119 public Node getNode(String absPath) throws PathNotFoundException, RepositoryException {
120 Node node = super.getNode(absPath);
121 if (!contentDecorator.evaluateNode(node)) {
122 throw new PathNotFoundException(absPath);
123 }
124 return wrapNode(node);
125 }
126
127 @Override
128 public Node getNodeByIdentifier(String id) throws ItemNotFoundException, RepositoryException {
129 Node node = super.getNodeByIdentifier(id);
130 if (!contentDecorator.evaluateNode(node)) {
131 throw new ItemNotFoundException(id);
132 }
133 return wrapNode(node);
134 }
135
136 @Override
137 public Node getNodeByUUID(String uuid) throws ItemNotFoundException, RepositoryException {
138 Node node = super.getNodeByUUID(uuid);
139 if (!contentDecorator.evaluateNode(node)) {
140 throw new ItemNotFoundException(uuid);
141 }
142 return wrapNode(node);
143 }
144
145 @Override
146 public boolean propertyExists(String absPath) throws RepositoryException {
147 return super.propertyExists(absPath) && contentDecorator.evaluateProperty(super.getProperty(absPath));
148 }
149
150 @Override
151 public Property getProperty(String absPath) throws PathNotFoundException, RepositoryException {
152 Property property = super.getProperty(absPath);
153 if (!contentDecorator.evaluateProperty(property)) {
154 throw new PathNotFoundException(absPath);
155 }
156 return wrapProperty(property);
157 }
158
159 @Override
160 public void move(String srcAbsPath, String destAbsPath) throws ItemExistsException, PathNotFoundException, VersionException, ConstraintViolationException, LockException, RepositoryException {
161 if (!nodeExists(srcAbsPath)) {
162 throw new PathNotFoundException(srcAbsPath);
163 }
164 super.move(srcAbsPath, destAbsPath);
165 }
166
167 @Override
168 public Workspace getWorkspace() {
169 return wrapWorkspace(super.getWorkspace());
170 }
171
172 protected Workspace wrapWorkspace(Workspace workspace) {
173 return contentDecorator.wrapWorkspace(workspace);
174 }
175
176 protected Node wrapNode(Node node) {
177 return contentDecorator.wrapNode(node);
178 }
179
180 protected Property wrapProperty(Property property) {
181 return contentDecorator.wrapProperty(property);
182 }
183 }