AssetVersionImpl.java
3.71 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
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.adobe.granite.asset.api.Asset
* com.adobe.granite.asset.api.AssetRelation
* com.adobe.granite.asset.api.AssetVersion
* com.adobe.granite.asset.api.Rendition
* javax.jcr.Node
* javax.jcr.RepositoryException
* javax.jcr.Session
* javax.jcr.version.Version
* javax.jcr.version.VersionHistory
* org.apache.sling.api.adapter.Adaptable
* org.apache.sling.api.resource.Resource
* org.apache.sling.api.resource.ResourceResolver
* org.apache.sling.api.resource.ResourceUtil
* org.apache.sling.api.resource.ValueMap
*/
package com.adobe.granite.asset.core.impl;
import com.adobe.granite.asset.api.Asset;
import com.adobe.granite.asset.api.AssetRelation;
import com.adobe.granite.asset.api.AssetVersion;
import com.adobe.granite.asset.api.Rendition;
import com.adobe.granite.asset.core.impl.AssetWrapper;
import java.util.Calendar;
import java.util.Iterator;
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.adapter.Adaptable;
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;
/*
* This class specifies class file version 49.0 but uses Java 6 signatures. Assumed Java 6.
*/
public class AssetVersionImpl
implements AssetVersion,
Adaptable {
private final String id;
private final String[] labels;
private final String versionName;
private String path;
private final AssetWrapper assetWrapper;
private ValueMap contentProperties;
private final String assetPath;
private Calendar created;
public AssetVersionImpl(Version version, ResourceResolver resolver) throws RepositoryException {
Session session = (Session)resolver.adaptTo(Session.class);
Resource resource = resolver.getResource(version.getNode("jcr:frozenNode").getPath());
this.assetWrapper = new AssetWrapper(resource);
Resource contentResource = resolver.getResource(resource, "jcr:content");
this.contentProperties = ResourceUtil.getValueMap((Resource)contentResource);
this.id = version.getIdentifier();
this.versionName = version.getName();
this.created = version.getCreated();
VersionHistory versionHistory = version.getContainingHistory();
this.path = version.getPath();
this.labels = versionHistory.getVersionLabels(version);
this.assetPath = session.getNodeByIdentifier(versionHistory.getVersionableIdentifier()).getPath();
}
public <AdapterType> AdapterType adaptTo(Class<AdapterType> type) {
if (ValueMap.class == type) {
return (AdapterType)this.contentProperties;
}
return null;
}
public String[] getLabels() {
return this.labels;
}
public String getId() {
return this.id;
}
public String getPath() {
return this.path;
}
public String getAssetPath() {
return this.assetPath;
}
public String getName() {
return this.versionName;
}
public Calendar getCreated() {
return this.created;
}
public Rendition getRendition(String name) {
return this.assetWrapper.getRendition(name);
}
public Iterator<Rendition> listRenditions() {
return this.assetWrapper.listRenditions();
}
public Iterator<Asset> listRelated(String name) {
return this.assetWrapper.listRelated(name);
}
public Iterator<AssetRelation> listRelations(String name) {
return this.assetWrapper.listRelations(name);
}
}