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