AbstractAssetBasedElement.java
2.31 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
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.adobe.cq.dam.cfm.VersionDef
* com.adobe.cq.dam.cfm.Versionable
* com.day.cq.dam.api.Asset
* com.day.cq.dam.api.Rendition
* com.day.cq.dam.api.Revision
* org.apache.sling.api.adapter.Adaptable
* org.apache.sling.api.resource.Resource
*/
package com.adobe.cq.dam.cfm.impl;
import com.adobe.cq.dam.cfm.VersionDef;
import com.adobe.cq.dam.cfm.Versionable;
import com.adobe.cq.dam.cfm.impl.CFMUtils;
import com.adobe.cq.dam.cfm.impl.VersionDefImpl;
import com.adobe.cq.dam.cfm.impl.VersioningException;
import com.day.cq.dam.api.Asset;
import com.day.cq.dam.api.Rendition;
import com.day.cq.dam.api.Revision;
import java.util.Calendar;
import org.apache.sling.api.adapter.Adaptable;
import org.apache.sling.api.resource.Resource;
abstract class AbstractAssetBasedElement
implements Adaptable,
Versionable {
private final Asset asset;
private final long lastModified;
private final Asset mainAsset;
protected AbstractAssetBasedElement(Asset asset, Asset mainAsset) {
this.asset = asset;
Rendition rendition = asset.getOriginal();
Calendar lastChanged = CFMUtils.getRenditionLastModified(rendition);
this.lastModified = lastChanged != null ? lastChanged.getTimeInMillis() : 0;
this.mainAsset = mainAsset;
}
protected Asset getAsset() {
return this.asset;
}
protected Asset getMainAsset() {
return this.mainAsset;
}
protected long getLastModified() {
return this.lastModified;
}
public <AdapterType> AdapterType adaptTo(Class<AdapterType> type) {
if (type == Resource.class) {
return (AdapterType)this.asset.adaptTo(Resource.class);
}
if (type == Asset.class) {
return (AdapterType)this.asset;
}
return null;
}
public VersionDef createVersion(String label, String comment) throws VersioningException {
VersionDefImpl versionCreated;
try {
Revision revision = this.mainAsset.createRevision(label, comment);
versionCreated = new VersionDefImpl(revision);
}
catch (Exception e) {
throw new VersioningException("Could not create revision of the fragment asset.", e);
}
return versionCreated;
}
}