ExpressionEditorResourcePropertyTransformer.java
7.67 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
160
161
162
163
164
165
166
167
168
169
170
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* org.apache.commons.lang3.StringUtils
* org.apache.sling.api.resource.Resource
* org.apache.sling.api.resource.ValueMap
* org.apache.sling.commons.json.JSONArray
* org.apache.sling.commons.json.JSONException
* org.apache.sling.commons.json.JSONObject
*/
package com.adobe.aemds.guide.common;
import com.adobe.aemds.guide.common.ResourcePropertyTransformer;
import java.util.HashMap;
import java.util.Map;
import org.apache.commons.lang3.StringUtils;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ValueMap;
import org.apache.sling.commons.json.JSONArray;
import org.apache.sling.commons.json.JSONException;
import org.apache.sling.commons.json.JSONObject;
public class ExpressionEditorResourcePropertyTransformer
implements ResourcePropertyTransformer {
private static final Map<String, String> nodeClassToTypeMap = new HashMap<String, String>();
private static final String[] expressionTypes;
private Map<String, Integer> elementSOMMap = new HashMap<String, Integer>();
public String getType(String guideNodeClass) {
String result = nodeClassToTypeMap.get(guideNodeClass);
if (result == null) {
result = guideNodeClass;
}
return result;
}
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())) {
int index;
String name = (String)props.get((Object)"name");
String nodeClass = (String)props.get((Object)"guideNodeClass");
if (StringUtils.isEmpty((CharSequence)nodeClass)) {
return null;
}
String type = this.getType(nodeClass);
if (type == null) {
return null;
}
if (props.containsKey((Object)"completionExpReq") && ((Boolean)props.get("completionExpReq", Boolean.class)).booleanValue()) {
type = type + "|NAVIGABLE_PANEL";
}
if (props.containsKey((Object)"summaryExpVisible") && "yes".equals(props.get("summaryExpVisible", String.class))) {
type = type + "|REPEATABLE_PANEL";
}
if ("FORM".equals(type)) {
name = "FORM";
}
if ((index = parentSOM.lastIndexOf(46)) >= 0 && "toolbar".equals(parentSOM.substring(index + 1)) && "guideButton".equals(nodeClass)) {
type = type + "|TOOLBAR_BUTTON";
}
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("SOM", (Object)id);
obj.put("name", (Object)name);
obj.put("type", (Object)type);
obj.put("status", (Object)this.getStatus(props));
obj.put("displayName", props.get((Object)"jcr:title"));
obj.put("options", (Object)this.getOptions(props));
obj.put("path", (Object)resource.getPath());
obj.put("path", (Object)resource.getPath());
obj.put("resourceType", props.get((Object)"sling:resourceType"));
String fragRef = (String)props.get((Object)"fragRef");
obj.put("isFragment", StringUtils.isNotEmpty((CharSequence)fragRef));
}
return obj;
}
private JSONObject getOptions(ValueMap props) throws JSONException {
Object options = props.get((Object)"options");
if (options != null && options instanceof String[]) {
String[] optionStrings = (String[])options;
JSONObject jsonObject = new JSONObject();
for (String optionString : optionStrings) {
String value;
if (!StringUtils.isNotBlank((CharSequence)optionString)) continue;
String[] parts = optionString.split("=");
String label = value = parts[0];
if (parts.length > 1) {
label = parts[1];
}
jsonObject.put(value, (Object)label);
}
return jsonObject;
}
return null;
}
/*
* Enabled force condition propagation
* Lifted jumps to return sites
*/
private String getStatus(ValueMap props) throws JSONException {
String status = "none";
if (props.containsKey((Object)"expJson")) {
String jsonString = (String)props.get((Object)"expJson");
JSONObject expJson = new JSONObject(jsonString);
JSONArray rules = (JSONArray)expJson.get("items");
if (rules.length() <= 0) return status;
boolean isValid = true;
for (int i = 0; i < rules.length() && isValid; ++i) {
JSONObject rule = (JSONObject)rules.get(i);
isValid = rule.has("isValid") ? rule.getBoolean("isValid") : true;
}
if (!isValid) return "invalid";
return "valid";
}
String[] arr$ = expressionTypes;
int len$ = arr$.length;
int i$ = 0;
while (i$ < len$) {
String script = arr$[i$];
if (props.containsKey((Object)script)) {
return "valid";
}
++i$;
}
return status;
}
static {
nodeClassToTypeMap.put("rootPanelNode", "ROOTPANEL|PANEL|AFCOMPONENT");
nodeClassToTypeMap.put("guidePanel", "PANEL|AFCOMPONENT");
nodeClassToTypeMap.put("guideRadioButton", "RADIO BUTTON|FIELD|AFCOMPONENT|STRING");
nodeClassToTypeMap.put("guideDropDownList", "DROP DOWN|FIELD|AFCOMPONENT|STRING|DROPDOWN");
nodeClassToTypeMap.put("guideChart", "CHART|AFCOMPONENT");
nodeClassToTypeMap.put("guideCheckBox", "CHECK BOX|FIELD|AFCOMPONENT|STRING");
nodeClassToTypeMap.put("guideSwitch", "SWITCH|FIELD|AFCOMPONENT|STRING");
nodeClassToTypeMap.put("guideFileUpload", "FILE ATTACHEMENT|FIELD|AFCOMPONENT");
nodeClassToTypeMap.put("guideTextBox", "TEXT FIELD|FIELD|AFCOMPONENT|STRING");
nodeClassToTypeMap.put("guideButton", "BUTTON|AFCOMPONENT");
nodeClassToTypeMap.put("guideContainerNode", "FORM");
nodeClassToTypeMap.put("guideDatePicker", "DATE FIELD|FIELD|AFCOMPONENT|STRING");
nodeClassToTypeMap.put("guideImage", "IMAGE|AFCOMPONENT");
nodeClassToTypeMap.put("guideNumericBox", "NUMBER FIELD|FIELD|AFCOMPONENT|NUMBER");
nodeClassToTypeMap.put("guidePasswordBox", "PASSWORD FIELD|AFCOMPONENT|STRING");
nodeClassToTypeMap.put("guideScribble", "SCRIBBLE FIELD|FIELD|AFCOMPONENT");
nodeClassToTypeMap.put("guideTermsAndConditions", "TERMS AND CONDITIONS|FIELD|AFCOMPONENT");
nodeClassToTypeMap.put("guideTextDraw", "STATIC TEXT|AFCOMPONENT");
nodeClassToTypeMap.put("guideTable", "TABLE|AFCOMPONENT");
nodeClassToTypeMap.put("guideTableRow", "TABLE ROW|AFCOMPONENT");
expressionTypes = new String[]{"clickExp", "navigationChangeExp", "visibleExp", "initScript", "calcExp", "valueCommitScript", "validateExp", "completionExp", "summaryExp", "optionsExp", "enabledExp"};
}
}