MetaDataNodeImpl.java
2.09 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
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* org.apache.sling.commons.json.JSONException
* org.apache.sling.commons.json.JSONObject
*/
package com.adobe.cq.mcm.campaign.profile.impl;
import com.adobe.cq.mcm.campaign.profile.MetaDataNode;
import com.adobe.cq.mcm.campaign.profile.OptionValue;
import com.adobe.cq.mcm.campaign.profile.Options;
import com.adobe.cq.mcm.campaign.profile.impl.AbstractMetaDataNode;
import com.adobe.cq.mcm.campaign.profile.impl.OptionValueImpl;
import com.adobe.cq.mcm.campaign.profile.impl.OptionsImpl;
import java.util.Iterator;
import org.apache.sling.commons.json.JSONException;
import org.apache.sling.commons.json.JSONObject;
public class MetaDataNodeImpl
extends AbstractMetaDataNode {
public MetaDataNodeImpl(JSONObject json, String key, MetaDataNode parent) {
super(key, parent.getPath(), MetaDataNodeImpl.getStringSafe(json, "label"), MetaDataNodeImpl.getStringSafe(json, "type"), MetaDataNodeImpl.getOptions(json));
}
private static String getStringSafe(JSONObject obj, String key) {
String str = null;
try {
str = obj.getString(key);
}
catch (JSONException je) {
// empty catch block
}
return str;
}
private static Options getOptions(JSONObject obj) {
OptionsImpl options = null;
try {
if (obj.has("values")) {
options = new OptionsImpl();
JSONObject optionValues = obj.getJSONObject("values");
Iterator optionKeys = optionValues.keys();
while (optionKeys.hasNext()) {
String optionKey = (String)optionKeys.next();
JSONObject option = optionValues.getJSONObject(optionKey);
String name = option.getString("name");
String label = option.getString("label");
options.addValue(new OptionValueImpl(optionKey, name, label));
}
}
}
catch (JSONException je) {
options = null;
}
return options;
}
}