ElementTemplateImpl.java
3.03 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
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.adobe.cq.dam.cfm.ElementTemplate
* com.day.cq.dam.api.Asset
* org.apache.sling.api.resource.ModifiableValueMap
* org.apache.sling.api.resource.Resource
* org.apache.sling.api.resource.ValueMap
* org.slf4j.Logger
* org.slf4j.LoggerFactory
*/
package com.adobe.cq.dam.cfm.impl;
import com.adobe.cq.dam.cfm.ElementTemplate;
import com.adobe.cq.dam.cfm.impl.FragmentTemplateImpl;
import com.adobe.cq.dam.cfm.impl.FragmentWriteException;
import com.adobe.cq.dam.cfm.impl.InvalidTemplateException;
import com.day.cq.dam.api.Asset;
import org.apache.sling.api.resource.ModifiableValueMap;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ValueMap;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class ElementTemplateImpl
implements ElementTemplate {
private final Logger log;
public final FragmentTemplateImpl fragmentTemplate;
private final String name;
private final String title;
private final String initialContentType;
private final String defaultContent;
private final Resource resource;
private String assetName;
public ElementTemplateImpl(FragmentTemplateImpl fragmentTemplate, Resource resource) throws InvalidTemplateException {
this.log = LoggerFactory.getLogger(this.getClass());
this.resource = resource;
this.fragmentTemplate = fragmentTemplate;
ValueMap properties = (ValueMap)resource.adaptTo(ValueMap.class);
String name = (String)properties.get("name", String.class);
if (name == null) {
throw new InvalidTemplateException("Missing element name on template.");
}
this.name = name;
String title = (String)properties.get("jcr:title", String.class);
if (title == null) {
throw new InvalidTemplateException("Missing element title on template.");
}
this.title = title;
this.assetName = (String)properties.get("assetName", String.class);
this.initialContentType = (String)properties.get("initialContentType", (Object)"text/html");
this.defaultContent = (String)properties.get("defaultContent", (Object)"");
}
public String getName() {
return this.name;
}
public String getTitle() {
return this.title;
}
public String getInitialContentType() {
return this.initialContentType;
}
public String getDefaultContent() {
return this.defaultContent;
}
public FragmentTemplateImpl getFragmentTemplate() {
return this.fragmentTemplate;
}
public void linkToAsset(Asset asset, boolean isMainAsset) throws FragmentWriteException {
if (isMainAsset) {
return;
}
ModifiableValueMap values = (ModifiableValueMap)this.resource.adaptTo(ModifiableValueMap.class);
String assetName = asset.getName();
values.put((Object)"assetName", (Object)assetName);
}
public String getAssetName() {
return this.assetName;
}
}