AdaptiveFormResourcePropertyTransformer.java
2.6 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
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* org.apache.sling.api.resource.Resource
* org.apache.sling.api.resource.ValueMap
* org.apache.sling.commons.json.JSONException
* org.apache.sling.commons.json.JSONObject
*/
package com.adobe.aemds.guide.common;
import com.adobe.aemds.guide.common.ExpressionEditorResourcePropertyTransformer;
import java.util.HashMap;
import java.util.Map;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ValueMap;
import org.apache.sling.commons.json.JSONException;
import org.apache.sling.commons.json.JSONObject;
public class AdaptiveFormResourcePropertyTransformer
extends ExpressionEditorResourcePropertyTransformer {
private Map<String, Integer> elementSOMMap = new HashMap<String, Integer>();
public JSONObject transform(Resource resource, String parentSOM) throws JSONException {
ValueMap props = (ValueMap)resource.adaptTo(ValueMap.class);
if ("layout".equals(resource.getName()) || "guideCompositeFieldItem".equals(props.get((Object)"guideNodeClass"))) {
return null;
}
JSONObject obj = new JSONObject();
if (!"items".equals(resource.getName())) {
String name = (String)props.get("name", null);
String type = (String)props.get("sling:resourceType", null);
String fragRef = (String)props.get((Object)"fragRef");
if (fragRef != null) {
type = "FRAGMENT";
}
if (name == null) {
name = resource.getName();
}
if ("fd/af/components/guideContainer".equals(type)) {
name = "Form Container";
} else if ("fd/adaddon/components/guideDocumentContainer".equals(type)) {
name = "Document Container";
}
String id = name;
if (parentSOM.length() > 0) {
String key = id = parentSOM + "." + name;
Integer somCounter = this.elementSOMMap.get(key);
int counter = 0;
if (somCounter != null) {
counter = somCounter;
id = parentSOM + "." + name + "[" + counter + "]";
}
this.elementSOMMap.put(key, counter + 1);
}
obj.put("id", (Object)id);
obj.put("fragRef", (Object)fragRef);
obj.put("name", (Object)name);
obj.put("type", (Object)type);
obj.put("displayName", props.get((Object)"jcr:title"));
obj.put("path", (Object)resource.getPath());
}
return obj;
}
}