RevisionImpl.java
6.3 KB
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.day.cq.wcm.api.Revision
* javax.jcr.Item
* javax.jcr.Node
* javax.jcr.RepositoryException
* javax.jcr.Session
* javax.jcr.version.Version
* javax.jcr.version.VersionHistory
* org.apache.sling.api.resource.ValueMap
* org.apache.sling.jcr.resource.JcrPropertyMap
* org.slf4j.Logger
* org.slf4j.LoggerFactory
*/
package com.day.cq.wcm.core.impl;
import com.day.cq.wcm.api.Revision;
import java.util.Calendar;
import javax.jcr.Item;
import javax.jcr.Node;
import javax.jcr.RepositoryException;
import javax.jcr.Session;
import javax.jcr.version.Version;
import javax.jcr.version.VersionHistory;
import org.apache.sling.api.resource.ValueMap;
import org.apache.sling.jcr.resource.JcrPropertyMap;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class RevisionImpl
implements Revision {
private static final Logger log = LoggerFactory.getLogger(RevisionImpl.class);
private final Version version;
private final String id;
private final String label;
private final String existingPath;
private JcrPropertyMap contentProps;
public RevisionImpl(Version version) throws RepositoryException {
this(version, RevisionImpl.getPagePath(version));
}
private static String getPagePath(Version version) {
try {
String uuid = version.getContainingHistory().getVersionableIdentifier();
Node existing = version.getSession().getNodeByIdentifier(uuid);
return existing.getParent().getPath();
}
catch (RepositoryException e) {
log.warn("Error while evaluating 'isBaseVersion'", (Throwable)e);
return null;
}
}
public RevisionImpl(Version version, String existingPath) throws RepositoryException {
this.version = version;
this.id = version.getIdentifier();
this.existingPath = existingPath;
String[] labels = version.getContainingHistory().getVersionLabels(version);
if (labels == null || labels.length == 0) {
this.label = version.getName();
} else {
StringBuilder buf = new StringBuilder(labels[0]);
for (int i = 1; i < labels.length; ++i) {
buf.append(", ");
buf.append(labels[i]);
}
this.label = buf.toString();
}
}
public Version getVersion() {
return this.version;
}
public ValueMap getProperties() {
if (this.contentProps == null) {
Node contentNode = null;
try {
if (this.version.hasNode("jcr:frozenNode")) {
contentNode = this.version.getNode("jcr:frozenNode");
}
}
catch (RepositoryException e) {
log.warn("Repository error while accessing content.");
}
this.contentProps = new JcrPropertyMap(contentNode);
}
return this.contentProps;
}
public ValueMap getProperties(String relPath) {
if (relPath.startsWith("/")) {
throw new IllegalArgumentException("Absolute paths not allowed");
}
relPath = "jcr:frozenNode/" + relPath;
try {
if (this.version.hasNode(relPath)) {
return new JcrPropertyMap(this.version.getNode(relPath));
}
}
catch (RepositoryException e) {
log.warn("Repository error while accessing content.");
}
return null;
}
public String getId() {
return this.id;
}
public String getLabel() {
return this.label;
}
public boolean isDeleted() {
return this.existingPath == null;
}
public String getExistingPagePath() {
return this.existingPath;
}
public boolean isBaseVersion() {
if (this.existingPath == null) {
return false;
}
try {
String uuid = this.version.getContainingHistory().getVersionableIdentifier();
Node existing = this.version.getSession().getNodeByIdentifier(uuid);
return existing.getBaseVersion().isSame((Item)this.version);
}
catch (RepositoryException e) {
log.warn("Error while evaluating 'isBaseVersion'", (Throwable)e);
return false;
}
}
public String getName() {
return (String)this.getProperties().get("cq:name", String.class);
}
public String getParentPath() {
return (String)this.getProperties().get("cq:parentPath", String.class);
}
public String getTitle() {
return (String)this.getProperties().get("jcr:title", String.class);
}
public String getDescription() {
return (String)this.getProperties().get("jcr:description", String.class);
}
public String getPageTitle() {
return (String)this.getProperties().get("pageTitle", String.class);
}
public String getNavigationTitle() {
return (String)this.getProperties().get("navTitle", String.class);
}
public boolean isHideInNav() {
return (Boolean)this.getProperties().get("hideInNav", (Object)Boolean.FALSE);
}
public boolean hasContent() {
try {
return this.version.hasNode("jcr:frozenNode") && !this.getName().startsWith("jcr:");
}
catch (RepositoryException e) {
log.warn("Repository error while accessing content.");
return false;
}
}
public String getVanityUrl() {
return (String)this.getProperties().get("vanityUrl", this.getProperties().get("sling:vanityPath", String.class));
}
public Calendar getCreated() {
try {
return this.version.getCreated();
}
catch (RepositoryException e) {
log.warn("Unable to access created date.");
return null;
}
}
public String getComment() {
return (String)this.getProperties().get("cq:versionComment", String.class);
}
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("RevisionImpl");
sb.append("{id='").append(this.id).append('\'');
sb.append(", label='").append(this.label).append('\'');
sb.append(", existingPath='").append(this.existingPath).append('\'');
sb.append('}');
return sb.toString();
}
}