RevisionImpl.java
5.8 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
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.adobe.granite.asset.api.AssetException
* com.adobe.granite.asset.api.AssetVersion
* com.adobe.granite.asset.api.Rendition
* com.day.cq.dam.api.Revision
* javax.jcr.Node
* javax.jcr.RepositoryException
* javax.jcr.version.Version
* org.apache.commons.lang.StringUtils
* org.apache.sling.api.resource.Resource
* org.apache.sling.api.resource.ResourceResolver
* org.apache.sling.api.resource.ResourceUtil
* org.apache.sling.api.resource.ValueMap
* org.apache.sling.jcr.resource.JcrPropertyMap
* org.slf4j.Logger
* org.slf4j.LoggerFactory
*/
package com.day.cq.dam.core.impl;
import com.adobe.granite.asset.api.AssetException;
import com.adobe.granite.asset.api.AssetVersion;
import com.adobe.granite.asset.api.Rendition;
import com.day.cq.dam.api.Revision;
import java.util.Calendar;
import java.util.Iterator;
import javax.jcr.Node;
import javax.jcr.RepositoryException;
import javax.jcr.version.Version;
import org.apache.commons.lang.StringUtils;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.api.resource.ResourceUtil;
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 AssetVersion assetVersion;
private final Version version;
private final String label;
private final boolean deleted;
private ValueMap metadataProps;
public RevisionImpl(AssetVersion assetVersion, Version version, ResourceResolver resolver, boolean deleted) throws RepositoryException {
String[] labels;
this.assetVersion = assetVersion;
this.version = version;
Resource contentResource = resolver.getResource(assetVersion.getPath() + "/" + "jcr:frozenNode" + "/" + "jcr:content");
Resource metadataResource = resolver.getResource(contentResource, "metadata");
if (metadataResource != null) {
this.metadataProps = ResourceUtil.getValueMap((Resource)metadataResource);
}
if ((labels = assetVersion.getLabels()) == null || labels.length == 0) {
this.label = assetVersion.getName();
} else {
StringBuffer buf = new StringBuffer(labels[0]);
for (int i = 1; i < labels.length; ++i) {
buf.append(", ");
buf.append(labels[i]);
}
this.label = buf.toString();
}
this.deleted = deleted;
}
public RevisionImpl(AssetVersion assetVersion, Version version, ResourceResolver resolver) throws RepositoryException {
this(assetVersion, version, resolver, false);
}
public Version getVersion() {
return this.version;
}
public ValueMap getProperties() {
return (ValueMap)this.assetVersion.adaptTo(ValueMap.class);
}
public ValueMap getMetadataProperties() {
return this.metadataProps;
}
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("getProperties(relPath): repository error while accessing content for version [{}]: ", (Object)this.getVersionDetails(), (Object)e);
}
return null;
}
public String getId() {
return this.assetVersion.getId();
}
public String getLabel() {
return this.label;
}
public boolean isDeleted() {
return this.deleted;
}
public String getName() {
return this.get("cq:name");
}
public String getParentPath() {
return this.get("cq:parentPath");
}
public String getTitle() {
return this.getMetadata("dc:title");
}
public String getDescription() {
return this.getMetadata("dc:description");
}
public Calendar getCreated() {
return this.assetVersion.getCreated();
}
public String getComment() {
return this.get("cq:versionComment");
}
public String getRenditionPath(String renditionName) {
if (StringUtils.isEmpty((String)renditionName)) {
Iterator it = this.assetVersion.listRenditions();
if (it.hasNext()) {
Rendition r = (Rendition)it.next();
return r.getParent().getPath();
}
return this.assetVersion.getPath() + "/" + "renditions";
}
try {
Rendition r = this.assetVersion.getRendition(renditionName);
if (r != null) {
return r.getPath();
}
}
catch (AssetException e) {
log.warn("getRenditionPath: repository error while accessing content for version [{}]: ", (Object)this.getVersionDetails(), (Object)e);
}
return null;
}
private String getVersionDetails() {
return "version[id=" + this.assetVersion.getId() + ", name=" + this.assetVersion.getName() + ", assetPath=" + this.assetVersion.getAssetPath() + "]";
}
private String get(String name) {
if (this.getProperties() != null) {
return (String)this.getProperties().get(name, String.class);
}
return null;
}
private String getMetadata(String name) {
if (this.getMetadataProperties() != null) {
return (String)this.getMetadataProperties().get(name, String.class);
}
return null;
}
}