Image.java
5.39 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
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.day.cq.commons.ImageResource
* com.day.cq.dam.api.Asset
* com.day.cq.dam.api.Rendition
* com.day.cq.dam.api.RenditionPicker
* com.day.cq.wcm.api.components.Component
* com.day.cq.wcm.api.designer.Style
* com.day.cq.wcm.commons.WCMUtils
* com.day.text.Text
* javax.jcr.Node
* org.apache.sling.api.resource.Resource
* org.apache.sling.api.resource.ResourceUtil
* org.apache.sling.api.resource.ValueMap
*/
package com.day.cq.wcm.foundation;
import com.day.cq.commons.ImageResource;
import com.day.cq.dam.api.Asset;
import com.day.cq.dam.api.Rendition;
import com.day.cq.dam.api.RenditionPicker;
import com.day.cq.wcm.api.components.Component;
import com.day.cq.wcm.api.designer.Style;
import com.day.cq.wcm.commons.WCMUtils;
import com.day.cq.wcm.foundation.ImageMap;
import com.day.cq.wcm.foundation.WCMRenditionPicker;
import com.day.text.Text;
import java.io.PrintWriter;
import java.util.Map;
import javax.jcr.Node;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ResourceUtil;
import org.apache.sling.api.resource.ValueMap;
public class Image
extends ImageResource {
public static final String PN_IMAGE_MAP = "imageMap";
private String imageMapId;
private ImageMap imageMap = null;
private boolean noPlaceholder;
public Image(Resource resource) {
super(resource);
if (this.properties.containsKey((Object)"imageMap")) {
try {
String mapDefinition = (String)this.properties.get("imageMap", (Object)"");
if (mapDefinition.length() > 0) {
this.imageMap = ImageMap.fromString(mapDefinition);
this.imageMapId = "map_" + Math.round(Math.random() * 2.147483647E9) + "_" + System.currentTimeMillis();
}
}
catch (IllegalArgumentException iae) {
this.imageMap = null;
this.imageMapId = null;
}
}
}
public Image(Resource resource, String imageName) {
this(Image.getRelativeResource((Resource)resource, (String)imageName));
}
public void setDropTargetId(String id, String classifier) {
if (classifier == null) {
classifier = "";
}
if (!classifier.startsWith("-")) {
classifier = "-" + classifier;
}
this.addCssClass("cq-dd-" + id + classifier);
}
public void setDropTargetId(String id) {
String classifier = ResourceUtil.isNonExistingResource((Resource)this) ? String.valueOf(System.currentTimeMillis()) : Text.getName((String)this.getPath());
this.setDropTargetId(id, classifier);
}
public boolean hasNoPlaceholder() {
return this.noPlaceholder;
}
public void setNoPlaceholder(boolean noPlaceholder) {
this.noPlaceholder = noPlaceholder;
}
public void loadStyleData(Style style) {
if (style != null) {
this.set("minWidth", (String)style.get("minWidth", (Object)""));
this.set("minHeight", (String)style.get("minHeight", (Object)""));
this.set("maxWidth", (String)style.get("maxWidth", (Object)""));
this.set("maxHeight", (String)style.get("maxHeight", (Object)""));
}
}
protected boolean canDraw() {
return !this.noPlaceholder || this.hasContent();
}
protected Map<String, String> getImageTagAttributes() {
String src = null;
if (!this.hasContent()) {
if (this.node != null) {
this.addQueryParam("defaultImagePath", "etc/designs/default/0.gif");
} else {
src = "/etc/designs/default/0.gif";
}
if (this.isTouchAuthoringUIMode()) {
Map attrs = this.getAttributes();
if (attrs.get("data-emptytext") == null) {
this.addAttribute("data-emptytext", "Image");
}
this.addCssClass("cq-placeholder");
this.addCssClass("file");
} else {
this.addCssClass("cq-image-placeholder");
}
}
Map attributes = super.getImageTagAttributes();
if (src != null) {
attributes.put("src", src);
}
if (this.imageMap != null) {
attributes.put("usemap", "#" + this.imageMapId);
}
return attributes;
}
protected void doDraw(PrintWriter w) {
super.doDraw(w);
if (this.imageMap != null) {
w.print(this.imageMap.draw(this.imageMapId));
}
}
public String getIconPath() {
Component c = WCMUtils.getComponent((Resource)this);
if (c == null) {
return null;
}
Resource icon = c.getLocalResource("resources/" + this.getIconType() + ".gif");
if (icon == null) {
icon = c.getLocalResource("resources/default.gif");
}
return icon == null ? null : icon.getPath();
}
protected Resource getReferencedResource(String path) {
Asset asset;
Resource res = super.getReferencedResource(path);
if (res != null && (asset = (Asset)res.adaptTo(Asset.class)) != null) {
Rendition rendition = asset.getRendition((RenditionPicker)new WCMRenditionPicker());
res = null != rendition ? (Resource)rendition.adaptTo(Resource.class) : null;
}
return res;
}
}