Config.java
4.68 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
/*
* 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.CompositeValueMap
* org.apache.sling.api.wrappers.ValueMapDecorator
*/
package com.adobe.granite.ui.components;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ValueMap;
import org.apache.sling.api.wrappers.CompositeValueMap;
import org.apache.sling.api.wrappers.ValueMapDecorator;
/*
* This class specifies class file version 49.0 but uses Java 6 signatures. Assumed Java 6.
*/
public class Config {
private Resource resource;
private ValueMap properties;
private ValueMap propertiesWithParent;
private Resource parentResource;
public static String DEFAULTS = "defaults";
public static String ITEMS = "items";
public static String LAYOUT = "layout";
public static String DATASOURCE = "datasource";
public static String RENDERCONDITION = "rendercondition";
public Config(Resource resource) {
this(resource, false);
}
public Config(Resource resource, boolean inherit) {
this.resource = resource;
ValueMap valueMap = this.properties = resource != null ? resource.getValueMap() : new ValueMapDecorator(new HashMap());
if (inherit) {
this.parentResource = this.getParentResource();
if (this.parentResource != null) {
Resource defaults = this.parentResource.getChild(DEFAULTS);
if (defaults != null) {
this.properties = new CompositeValueMap(this.properties, defaults.getValueMap());
}
this.propertiesWithParent = new CompositeValueMap(this.properties, this.parentResource.getValueMap());
}
}
}
public Config(Resource resource, ValueMap defaults, ValueMap parentProperties) {
this.resource = resource;
ValueMap prop = resource != null ? resource.getValueMap() : new ValueMapDecorator(new HashMap());
this.properties = new CompositeValueMap(prop, defaults);
this.propertiesWithParent = new CompositeValueMap(prop, parentProperties);
}
public String get(String name) {
return this.get(name, "");
}
public <T> T get(String name, T defaultValue) {
return (T)this.properties.get(name, defaultValue);
}
public <T> T get(String name, Class<T> type) {
return (T)this.properties.get(name, type);
}
public String getInherited(String name) {
return this.getInherited(name, "");
}
public <T> T getInherited(String name, T defaultValue) {
return (T)this.propertiesWithParent.get(name, defaultValue);
}
public <T> T getInherited(String name, Class<T> type) {
return (T)this.propertiesWithParent.get(name, type);
}
public String getInheritedDefault(String name) {
return this.getInheritedDefault(name, "");
}
public <T> T getInheritedDefault(String name, T defaultValue) {
return this.get(name, defaultValue);
}
public <T> T getInheritedDefault(String name, Class<T> type) {
return this.get(name, type);
}
public ValueMap getDefaultProperties() {
Resource defaults = this.resource.getChild(DEFAULTS);
return defaults != null ? defaults.getValueMap() : new ValueMapDecorator(new HashMap());
}
public ValueMap getProperties() {
return this.properties;
}
public Iterator<Resource> getItems() {
return this.getItems(this.resource, ITEMS);
}
public Iterator<Resource> getItems(String name) {
return this.getItems(this.resource, name);
}
public Iterator<Resource> getItems(Resource resource) {
return this.getItems(resource, ITEMS);
}
public Iterator<Resource> getItems(Resource resource, String name) {
Resource items;
if (name == null || name.length() == 0) {
name = ITEMS;
}
if ((items = resource.getChild(name)) != null) {
return items.listChildren();
}
return Collections.emptyList().iterator();
}
public Resource getChild(String name) {
return this.resource.getChild(name);
}
public Resource getParentResource() {
if (this.parentResource != null) {
return this.parentResource;
}
this.parentResource = this.resource.getParent();
if ("nt:unstructured".equals(this.parentResource.getResourceType())) {
this.parentResource = this.parentResource.getParent();
}
return this.parentResource;
}
}