TenantELResolver.java
4.05 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
/*
* 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.api.resource.ResourceResolver
* org.apache.sling.scripting.jsp.util.TagUtil
* org.apache.sling.tenant.Tenant
*/
package com.adobe.granite.ui.components.impl;
import java.beans.FeatureDescriptor;
import java.util.ArrayList;
import java.util.Iterator;
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.api.resource.ResourceResolver;
import org.apache.sling.scripting.jsp.util.TagUtil;
import org.apache.sling.tenant.Tenant;
/*
* This class specifies class file version 49.0 but uses Java 6 signatures. Assumed Java 6.
*/
public class TenantELResolver
extends ELResolver {
private static final String PROPERTY_NAME = "tenant";
public Object getValue(ELContext context, Object base, Object property) {
if (context == null) {
throw new NullPointerException();
}
if (base != null) {
return null;
}
if ("tenant".equals(property)) {
PageContext pageContext = (PageContext)context.getContext(JspContext.class);
context.setPropertyResolved(true);
return this.getTenant(TagUtil.getRequest((PageContext)pageContext));
}
return null;
}
public Class<?> getType(ELContext context, Object base, Object property) {
if (context == null) {
throw new NullPointerException();
}
if (base == null && "tenant".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 && "tenant".equals(property)) {
throw new PropertyNotWritableException();
}
}
public boolean isReadOnly(ELContext context, Object base, Object property) {
if (context == null) {
throw new NullPointerException();
}
if (base == null && "tenant".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("tenant");
descriptor.setDisplayName("tenant");
descriptor.setShortDescription("A variable exposing the tenant of current request");
descriptor.setExpert(false);
descriptor.setHidden(false);
descriptor.setPreferred(true);
descriptor.setValue("type", TenantMap.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 TenantMap getTenant(SlingHttpServletRequest request) {
Tenant t = (Tenant)request.getResourceResolver().adaptTo(Tenant.class);
return t == null ? null : new TenantMap(t);
}
public class TenantMap {
private Tenant tenant;
public TenantMap(Tenant tenant) {
this.tenant = tenant;
}
public String getDescription() {
return this.tenant.getDescription();
}
public String getId() {
return this.tenant.getId();
}
public String getName() {
return this.tenant.getName();
}
}
}