VariationImpl.java
5.12 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
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.adobe.cq.dam.cfm.ContentFragmentException
* com.adobe.cq.dam.cfm.ContentVariation
* com.adobe.cq.dam.cfm.SyncStatus
* com.adobe.cq.dam.cfm.VariationTemplate
* com.adobe.cq.dam.cfm.VersionDef
* com.adobe.cq.dam.cfm.VersionedContent
* com.day.cq.dam.api.Asset
* com.day.cq.dam.api.Rendition
* com.day.cq.dam.api.Revision
*/
package com.adobe.cq.dam.cfm.impl;
import com.adobe.cq.dam.cfm.ContentFragmentException;
import com.adobe.cq.dam.cfm.ContentVariation;
import com.adobe.cq.dam.cfm.SyncStatus;
import com.adobe.cq.dam.cfm.VariationTemplate;
import com.adobe.cq.dam.cfm.VersionDef;
import com.adobe.cq.dam.cfm.VersionedContent;
import com.adobe.cq.dam.cfm.impl.CFMUtils;
import com.adobe.cq.dam.cfm.impl.ElementImpl;
import com.adobe.cq.dam.cfm.impl.FragmentWriteException;
import com.adobe.cq.dam.cfm.impl.InvalidFragmentException;
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 java.util.Iterator;
public class VariationImpl
implements ContentVariation {
private Rendition rendition;
private final ElementImpl element;
private final Asset mainAsset;
private final long lastModified;
private final String subPath;
private final VariationTemplate template;
public VariationImpl(Config cfg) throws InvalidFragmentException {
this.rendition = cfg.rendition;
this.element = cfg.element;
this.mainAsset = this.element.getMainAsset();
this.subPath = cfg.subPath;
this.template = cfg.template;
if (this.template == null && !cfg.allowInvalidTemplate) {
throw new InvalidFragmentException("Missing template for variation '" + cfg.rendition.getName() + "'.");
}
Calendar modifiedCal = CFMUtils.getRenditionLastModified(this.rendition);
this.lastModified = modifiedCal != null ? modifiedCal.getTimeInMillis() : 0;
}
public String getName() {
return this.template.getName();
}
public String getTitle() {
return this.template.getTitle();
}
public String getDescription() {
return this.template.getDescription();
}
public String getContentType() {
return CFMUtils.getContentType(this.rendition);
}
public String getContent() {
return CFMUtils.getContentAsString(this.rendition);
}
public void setContent(String content, String contentType) throws FragmentWriteException {
CFMUtils.setContent(this.rendition, content, contentType);
}
/*
* WARNING - Removed try catching itself - possible behaviour change.
*/
public Calendar syncContent(String content, String contentType) throws FragmentWriteException {
Asset asset = this.rendition.getAsset();
boolean oldBatchMode = asset.isBatchMode();
asset.setBatchMode(true);
try {
Rendition newRendition;
this.rendition = newRendition = CFMUtils.setContent(this.rendition, content, contentType);
Calendar calendar = CFMUtils.getRenditionLastModified(newRendition);
return calendar;
}
finally {
asset.setBatchMode(oldBatchMode);
}
}
public SyncStatus getSyncStatus() {
return this.element.getSyncStatus(this);
}
public void synchronize() throws ContentFragmentException {
this.element.synchronize(this);
}
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;
}
public Iterator<VersionDef> listVersions() throws VersioningException {
return CFMUtils.listVersions(this.mainAsset, this.lastModified, this.rendition.getName(), this.subPath);
}
public VersionedContent getVersionedContent(VersionDef version) throws VersioningException {
return CFMUtils.getVersionedContent(version, this.mainAsset, this.rendition.getName(), this.subPath);
}
public Calendar getModification() {
return CFMUtils.getRenditionLastModified(this.rendition);
}
static class Config {
public final Rendition rendition;
public final ElementImpl element;
public final String subPath;
public final VariationTemplate template;
public final boolean allowInvalidTemplate;
public Config(Rendition rendition, ElementImpl element, String subPath, VariationTemplate template, boolean allowInvalidTemplate) {
this.rendition = rendition;
this.element = element;
this.subPath = subPath;
this.template = template;
this.allowInvalidTemplate = allowInvalidTemplate;
}
}
}