StateELResolver.java
5.42 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
171
172
173
174
175
176
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* javax.el.ELContext
* javax.el.ELResolver
* javax.el.PropertyNotWritableException
* javax.servlet.jsp.JspContext
* javax.servlet.jsp.PageContext
* org.apache.sling.api.SlingHttpServletRequest
* org.apache.sling.scripting.jsp.util.TagUtil
*/
package com.adobe.granite.ui.components.impl;
import com.adobe.granite.ui.components.State;
import java.beans.FeatureDescriptor;
import java.util.AbstractMap;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import javax.el.ELContext;
import javax.el.ELResolver;
import javax.el.PropertyNotWritableException;
import javax.servlet.jsp.JspContext;
import javax.servlet.jsp.PageContext;
import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.scripting.jsp.util.TagUtil;
/*
* This class specifies class file version 49.0 but uses Java 6 signatures. Assumed Java 6.
*/
public class StateELResolver
extends ELResolver {
private static final String PROPERTY_NAME = "state";
public Object getValue(ELContext context, Object base, Object property) {
if (context == null) {
throw new NullPointerException();
}
if (base != null) {
return null;
}
if ("state".equals(property)) {
PageContext pageContext = (PageContext)context.getContext(JspContext.class);
context.setPropertyResolved(true);
return this.getState(TagUtil.getRequest((PageContext)pageContext));
}
return null;
}
public Class<?> getType(ELContext context, Object base, Object property) {
if (context == null) {
throw new NullPointerException();
}
if (base == null && "state".equals(property)) {
context.setPropertyResolved(true);
}
return null;
}
public void setValue(ELContext context, Object base, Object property, Object val) {
if (context == null) {
throw new NullPointerException();
}
if (base == null && "state".equals(property)) {
throw new PropertyNotWritableException();
}
}
public boolean isReadOnly(ELContext context, Object base, Object property) {
if (context == null) {
throw new NullPointerException();
}
if (base == null && "state".equals(property)) {
context.setPropertyResolved(true);
return true;
}
return false;
}
public Iterator<FeatureDescriptor> getFeatureDescriptors(ELContext context, Object base) {
ArrayList<FeatureDescriptor> list = new ArrayList<FeatureDescriptor>(1);
FeatureDescriptor descriptor = new FeatureDescriptor();
descriptor.setName("state");
descriptor.setDisplayName("state");
descriptor.setShortDescription("A variable exposing the client state of current request");
descriptor.setExpert(false);
descriptor.setHidden(false);
descriptor.setPreferred(true);
descriptor.setValue("type", StateMap.class);
descriptor.setValue("resolvableAtDesignTime", Boolean.TRUE);
list.add(descriptor);
return list.iterator();
}
public Class<?> getCommonPropertyType(ELContext context, Object base) {
if (base == null) {
return String.class;
}
return null;
}
private StateMap getState(SlingHttpServletRequest request) {
String key = StateELResolver.class.getName();
StateMap map = (StateMap)request.getAttribute(key);
if (map == null) {
map = new StateMap(new State(request));
request.setAttribute(key, (Object)map);
}
return map;
}
/*
* This class specifies class file version 49.0 but uses Java 6 signatures. Assumed Java 6.
*/
private class StateMap
extends AbstractMap<String, State.Item> {
private State state;
public StateMap(State state) {
this.state = state;
}
@Override
public Set<Map.Entry<String, State.Item>> entrySet() {
HashSet<Map.Entry<String, State.Item>> set = new HashSet<Map.Entry<String, State.Item>>();
Iterator<String> it = this.state.names();
while (it.hasNext()) {
set.add(new StateMapEntry(this.state.getItem(it.next())));
}
return set;
}
/*
* This class specifies class file version 49.0 but uses Java 6 signatures. Assumed Java 6.
*/
private class StateMapEntry
implements Map.Entry<String, State.Item> {
private State.Item item;
public StateMapEntry(State.Item item) {
this.item = item;
}
@Override
public String getKey() {
return this.item.getName();
}
@Override
public State.Item getValue() {
return this.item;
}
@Override
public State.Item setValue(State.Item value) {
throw new UnsupportedOperationException();
}
@Override
public boolean equals(Object obj) {
return obj != null && this.hashCode() == obj.hashCode();
}
@Override
public int hashCode() {
return this.getKey().hashCode();
}
}
}
}