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.ui.datasource.jcr;
35
36 import static info.magnolia.ui.datasource.jcr.JcrSessionManager.TMP_DELETED_PROPERTY;
37
38 import info.magnolia.jcr.RuntimeRepositoryException;
39 import info.magnolia.jcr.decoration.ContentDecoratorPropertyWrapper;
40
41 import javax.jcr.Node;
42 import javax.jcr.Property;
43 import javax.jcr.RepositoryException;
44 import javax.jcr.Session;
45
46
47
48
49
50
51 public class JcrPropertyWrapper extends ContentDecoratorPropertyWrapper<JcrSessionManager> {
52
53 private String path;
54
55 JcrPropertyWrapper(Property property, JcrSessionManager decorator) {
56 super(property, decorator);
57 setWrappedProperty(property);
58 }
59
60 @Override
61 protected void setWrappedProperty(Property property) {
62 super.setWrappedProperty(property);
63 try {
64 this.path = property.getPath();
65 } catch (RepositoryException e) {
66 throw new RuntimeRepositoryException(e);
67 }
68 }
69
70 @Override
71 public Property getWrappedProperty() {
72 Property property = super.getWrappedProperty();
73 try {
74 if (!property.getSession().isLive()) {
75 Session session = getContentDecorator().getJCRSession().getWrappedSession();
76 property = session.propertyExists(path) ? session.getProperty(path) : getDeletedItem(session);
77 } else {
78 property = getContentDecorator().exists(property) ? property : getDeletedItem(super.getWrappedProperty().getSession());
79 }
80 } catch (RepositoryException e) {
81 throw new RuntimeRepositoryException(e);
82 }
83 return property;
84 }
85
86 @Override
87 public String getPath() throws RepositoryException {
88 return getContentDecorator().exists(this) ? super.getPath() : path;
89 }
90
91 @Override
92 public boolean equals(Object obj) {
93 return obj instanceof JcrPropertyWrapper && ((JcrPropertyWrapper) obj).path.equals(this.path);
94 }
95
96 @Override
97 public int hashCode() {
98 return path.hashCode();
99 }
100
101 private Property getDeletedItem(Session session) throws RepositoryException {
102 Node root = session.getRootNode();
103 return root.setProperty(TMP_DELETED_PROPERTY, TMP_DELETED_PROPERTY);
104 }
105 }
106