ELEvaluator.java
1.84 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
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.day.cq.security.profile.Profile
* javax.servlet.jsp.PageContext
* javax.servlet.jsp.el.ELException
* javax.servlet.jsp.el.ExpressionEvaluator
* javax.servlet.jsp.el.FunctionMapper
* javax.servlet.jsp.el.VariableResolver
* org.apache.sling.api.SlingHttpServletRequest
* org.slf4j.Logger
* org.slf4j.LoggerFactory
*/
package com.day.cq.wcm.foundation;
import com.day.cq.security.profile.Profile;
import javax.servlet.jsp.PageContext;
import javax.servlet.jsp.el.ELException;
import javax.servlet.jsp.el.ExpressionEvaluator;
import javax.servlet.jsp.el.FunctionMapper;
import javax.servlet.jsp.el.VariableResolver;
import org.apache.sling.api.SlingHttpServletRequest;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class ELEvaluator {
private static final Logger log = LoggerFactory.getLogger(ELEvaluator.class);
public static String evaluate(String expr, SlingHttpServletRequest request, final PageContext pageContext) {
final Profile profile = (Profile)request.adaptTo(Profile.class);
ExpressionEvaluator exprEval = pageContext.getExpressionEvaluator();
try {
return (String)exprEval.evaluate(expr, String.class, new VariableResolver(){
private final VariableResolver base;
public Object resolveVariable(String name) throws ELException {
Object value = this.base.resolveVariable(name);
if (value == null && name.equals("profile")) {
value = profile;
}
return value;
}
}, null);
}
catch (ELException e) {
log.warn("Error while evaluating expression: {}", (Object)expr, (Object)e);
return expr;
}
}
}