LayoutBuilder.java
3.34 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
/*
* 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.api.wrappers.ValueMapDecorator
* org.apache.sling.commons.json.JSONException
* org.apache.sling.commons.json.JSONObject
*/
package com.adobe.granite.ui.components;
import com.adobe.granite.ui.components.Config;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ValueMap;
import org.apache.sling.api.wrappers.ValueMapDecorator;
import org.apache.sling.commons.json.JSONException;
import org.apache.sling.commons.json.JSONObject;
/*
* This class specifies class file version 49.0 but uses Java 6 signatures. Assumed Java 6.
*/
public class LayoutBuilder {
private static final String NAME = "name";
private JSONObject result;
private String resourceType;
private ValueMap vm;
public static LayoutBuilder from(Config config) {
return LayoutBuilder.from(config.getChild(Config.LAYOUT));
}
public static LayoutBuilder from(Config config, String defaultResourceType) {
return LayoutBuilder.from(config.getChild(Config.LAYOUT), defaultResourceType);
}
public static LayoutBuilder from(Resource resource) {
return LayoutBuilder.from(resource, null);
}
public static LayoutBuilder from(Resource resource, String defaultResourceType) {
LayoutBuilder b = new LayoutBuilder();
b.vm = resource != null ? resource.getValueMap() : new ValueMapDecorator(new HashMap());
b.setResourceType((String)b.vm.get("sling:resourceType", (Object)defaultResourceType));
return b;
}
private void init() {
if (this.result != null) {
return;
}
this.result = new JSONObject();
if (this.vm != null) {
this.add((Map<String, Object>)this.vm);
}
}
public boolean hasName() {
this.init();
return this.result.has("name");
}
public String getName() {
this.init();
return this.result.optString("name", null);
}
public void setName(String name) {
try {
this.init();
this.result.put("name", (Object)name);
}
catch (JSONException impossible) {
throw new RuntimeException((Throwable)impossible);
}
}
public String getResourceType() {
return this.resourceType;
}
public void setResourceType(String resourceType) {
this.resourceType = resourceType;
}
public void add(String key, Object value) {
try {
this.init();
this.result.accumulate(key, value);
}
catch (JSONException e) {
throw new RuntimeException((Throwable)e);
}
}
public void add(Map<String, Object> data) {
try {
this.init();
for (Map.Entry<String, Object> e : data.entrySet()) {
String key = e.getKey();
if (key.indexOf(":") >= 0) continue;
this.result.accumulate(key, e.getValue());
}
}
catch (JSONException e) {
throw new RuntimeException((Throwable)e);
}
}
public JSONObject toJSON() {
this.init();
return this.result;
}
}