Value.java
3.87 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
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* org.apache.sling.api.SlingHttpServletRequest
* org.apache.sling.api.resource.Resource
* org.apache.sling.api.resource.ResourceResolver
* org.apache.sling.api.resource.ResourceUtil
* org.apache.sling.api.resource.ValueMap
*/
package com.adobe.granite.ui.components;
import com.adobe.granite.ui.components.Config;
import java.util.Arrays;
import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.api.resource.ResourceUtil;
import org.apache.sling.api.resource.ValueMap;
/*
* This class specifies class file version 49.0 but uses Java 6 signatures. Assumed Java 6.
*/
public class Value {
public static final String FORM_VALUESS_ATTRIBUTE = "granite.ui.form.values";
public static final String CONTENTPATH_ATTRIBUTE = "granite.ui.form.contentpath";
private Config config;
private ValueMap values;
public Value(SlingHttpServletRequest request, Config config) {
Resource contentResource;
String contentPath;
this.config = config;
this.values = (ValueMap)request.getAttribute("granite.ui.form.values");
if (this.values == null && (contentPath = (String)request.getAttribute("granite.ui.form.contentpath")) != null && (contentResource = request.getResourceResolver().getResource(contentPath)) != null && !ResourceUtil.isNonExistingResource((Resource)contentResource)) {
this.values = contentResource.getValueMap();
}
}
public String get(String name) {
return this.get(name, "");
}
public <T> T get(String name, T defaultValue) {
if (this.values == null || this.config.get("ignoreData", false).booleanValue()) {
return this.config.get("value", defaultValue);
}
return this.getContentValue(name, defaultValue);
}
public <T> T get(String name, Class<T> type) {
if (this.values == null || this.config.get("ignoreData", false).booleanValue()) {
return this.config.get("value", type);
}
return this.getContentValue(name, type);
}
public <T> T val(T defaultValue) {
return this.val(this.config.get("name", String.class), defaultValue);
}
public <T> T val(String name, T defaultValue) {
if (this.values == null || this.config.get("ignoreData", false).booleanValue()) {
return defaultValue;
}
return this.getContentValue(name, defaultValue);
}
public boolean isSelected(String value, boolean defaultReturn) {
return this.isSelected(this.config.get("name", String.class), value, defaultReturn);
}
public boolean isSelected(String name, String value, boolean defaultReturn) {
if (this.values == null || this.config.get("ignoreData", false).booleanValue()) {
return defaultReturn;
}
String[] contentValue = this.getContentValue(name, (Class<T>)String[].class);
if (contentValue != null) {
if (value == null) {
return false;
}
return Arrays.asList(contentValue).contains(value);
}
if (value == null) {
return defaultReturn;
}
if (value.length() == 0) {
return true;
}
return defaultReturn;
}
public String getContentValue(String name) {
return this.getContentValue(name, "");
}
public <T> T getContentValue(String name, T defaultValue) {
if (this.values == null || name == null) {
return defaultValue;
}
return (T)this.values.get(name, defaultValue);
}
public <T> T getContentValue(String name, Class<T> type) {
if (this.values == null || name == null) {
return null;
}
return (T)this.values.get(name, type);
}
}