下面列出了javax.servlet.jsp.el.VariableResolver#javax.servlet.jsp.el.ELException 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@Override
public Expression parseExpression(String expression,
@SuppressWarnings("rawtypes") Class expectedType,
FunctionMapper fMapper) throws ELException {
try {
ELContextImpl ctx =
new ELContextImpl(ELContextImpl.getDefaultResolver(factory));
if (fMapper != null) {
ctx.setFunctionMapper(new FunctionMapperImpl(fMapper));
}
ValueExpression ve = this.factory.createValueExpression(ctx, expression, expectedType);
return new ExpressionImpl(ve, factory);
} catch (javax.el.ELException e) {
throw new ELParseException(e.getMessage());
}
}
@Override
public Expression parseExpression(String expression,
@SuppressWarnings("rawtypes") // API does not use generics
Class expectedType,
FunctionMapper fMapper) throws ELException {
try {
ELContextImpl ctx =
new ELContextImpl(ELContextImpl.getDefaultResolver());
if (fMapper != null) {
ctx.setFunctionMapper(new FunctionMapperImpl(fMapper));
}
ValueExpression ve = this.factory.createValueExpression(ctx, expression, expectedType);
return new ExpressionImpl(ve);
} catch (javax.el.ELException e) {
throw new ELParseException(e.getMessage());
}
}
@Override
public Expression parseExpression(String expression,
@SuppressWarnings("rawtypes") // API does not use generics
Class expectedType,
FunctionMapper fMapper) throws ELException {
try {
ELContextImpl ctx =
new ELContextImpl(ELContextImpl.getDefaultResolver());
if (fMapper != null) {
ctx.setFunctionMapper(new FunctionMapperImpl(fMapper));
}
ValueExpression ve = this.factory.createValueExpression(ctx, expression, expectedType);
return new ExpressionImpl(ve);
} catch (javax.el.ELException e) {
throw new ELParseException(e.getMessage());
}
}
public Expression parseExpression(String expression,
Class expectedType,
FunctionMapper fMapper )
throws ELException {
ExpressionFactory fac = ExpressionFactory.newInstance();
javax.el.ValueExpression expr;
ELContextImpl elContext = new ELContextImpl(null);
javax.el.FunctionMapper fm = new FunctionMapperWrapper(fMapper);
elContext.setFunctionMapper(fm);
try {
expr = fac.createValueExpression(
elContext,
expression, expectedType);
} catch (javax.el.ELException ex) {
throw new ELException(ex);
}
return new ExpressionImpl(expr, pageContext);
}
public Object evaluate(VariableResolver vResolver) throws ELException {
ELContext elContext;
if (vResolver instanceof VariableResolverImpl) {
elContext = pageContext.getELContext();
}
else {
// The provided variable Resolver is a custom resolver,
// wrap it with a ELResolver
elContext = new ELContextImpl(new ELResolverWrapper(vResolver));
}
try {
return valueExpr.getValue(elContext);
} catch (javax.el.ELException ex) {
throw new ELException(ex);
}
}
/**
* VariableResolver interface
*/
@Override
@Deprecated
public Object resolveVariable(String pName) throws ELException {
ELContext ctx = this.getELContext();
return ctx.getELResolver().getValue(ctx, null, pName);
}
@Override
public Object evaluate(String expression,
@SuppressWarnings("rawtypes") Class expectedType,
VariableResolver vResolver, FunctionMapper fMapper)
throws ELException {
return this.parseExpression(expression, expectedType, fMapper).evaluate(vResolver);
}
/**
* VariableResolver interface
*/
@Override
@Deprecated
public Object resolveVariable(String pName) throws ELException {
ELContext ctx = this.getELContext();
return ctx.getELResolver().getValue(ctx, null, pName);
}
@Override
public Object evaluate(String expression,
@SuppressWarnings("rawtypes") // API does not use generics
Class expectedType,
VariableResolver vResolver, FunctionMapper fMapper)
throws ELException {
return this.parseExpression(expression, expectedType, fMapper).evaluate(vResolver);
}
/**
* VariableResolver interface
*/
@Override
@Deprecated
public Object resolveVariable(String pName) throws ELException {
ELContext ctx = this.getELContext();
return ctx.getELResolver().getValue(ctx, null, pName);
}
@Override
public Object evaluate(String expression,
@SuppressWarnings("rawtypes") // API does not use generics
Class expectedType,
VariableResolver vResolver, FunctionMapper fMapper)
throws ELException {
return this.parseExpression(expression, expectedType, fMapper).evaluate(vResolver);
}
public Object evaluate(String expression,
Class expectedType,
VariableResolver vResolver,
FunctionMapper fMapper )
throws ELException {
ELContextImpl elContext;
if (vResolver instanceof VariableResolverImpl) {
elContext = (ELContextImpl) pageContext.getELContext();
}
else {
// The provided variable Resolver is a custom resolver,
// wrap it with a ELResolver
elContext = new ELContextImpl(new ELResolverWrapper(vResolver));
}
javax.el.FunctionMapper fm = new FunctionMapperWrapper(fMapper);
elContext.setFunctionMapper(fm);
ExpressionFactory fac = ExpressionFactory.newInstance();
Object value;
try {
ValueExpression expr = fac.createValueExpression(
elContext,
expression,
expectedType);
value = expr.getValue(elContext);
} catch (javax.el.ELException ex) {
throw new ELException(ex);
}
return value;
}
public Object getValue(ELContext context,
Object base,
Object property)
throws javax.el.ELException {
if (base == null) {
context.setPropertyResolved(true);
try {
return vResolver.resolveVariable(property.toString());
} catch (ELException ex) {
throw new javax.el.ELException(ex);
}
}
return null;
}
public static void parseEL(String el) throws ELEvalException {
try {
EVALUATOR.parseExpressionString(el);
} catch (ELException e) {
LOG.debug("Error parsering EL '{}': {}", el, e.toString(), e);
throw new ELEvalException(ContainerCommonError.CTRCMN_0101, el, e.toString(), e);
}
}
@Override
@SuppressWarnings("unchecked")
public <T> T evaluate (final ELVars vars, String expression, Class<T> returnType) throws ELEvalException {
VariableResolver variableResolver = new VariableResolver() {
@Override
public Object resolveVariable(String name) throws ELException {
Object value = constants.get(name);
if (!vars.hasVariable(name)) {
if (value == null && !constants.containsKey(name)) {
throw new ELException(Utils.format("Constants/Variable '{}' cannot be resolved", name));
}
} else {
value = vars.getVariable(name);
}
return value;
}
};
try {
return (T) EVALUATOR.evaluate(expression, returnType, variableResolver, functionMapper);
} catch (ELException e) {
// Apache evaluator is not using the getCause exception chaining that is available in Java but rather a custom
// chaining mechanism. This doesn't work well for us as we're effectively swallowing the cause that is not
// available in log, ...
Throwable t = e;
if(e.getRootCause() != null) {
t = e.getRootCause();
if(e.getCause() == null) {
e.initCause(t);
}
}
LOG.debug("Error valuating EL '{}': {}", expression, e.toString(), e);
throw new ELEvalException(ContainerCommonError.CTRCMN_0100, expression, t.toString(), e);
}
}
private String evaluate (final Map<String, Object> configs, String expression) throws
ELEvalException {
try {
CONFIGS_TL.set(configs);
return (String) EVALUATOR.evaluate(
expression,
String.class,
name -> null,
(prefix, name) -> (prefix.equals("") && name.equals("value")) ? CONFIG_VALUE_FUNCTION : null
);
} catch (ELException e) {
// Apache evaluator is not using the getCause exception chaining that is available in Java but rather a custom
// chaining mechanism. This doesn't work well for us as we're effectively swallowing the cause that is not
// available in log, ...
Throwable t = e;
if(e.getRootCause() != null) {
t = e.getRootCause();
if(e.getCause() == null) {
e.initCause(t);
}
}
LOG.debug(Errors.YAML_UPGRADER_12.getMessage(), getName(), expression, t.toString(), e);
throw new ELEvalException(Errors.YAML_UPGRADER_12, getName(), expression, t.toString());
} finally {
CONFIGS_TL.remove();
}
}
@Override
public Object resolveVariable(String pName) throws ELException {
return this.ctx.getELResolver().getValue(this.ctx, null, pName);
}
@Override
public Object evaluate(VariableResolver vResolver) throws ELException {
ELContext ctx =
new ELContextImpl(new ELResolverImpl(vResolver, factory));
return ve.getValue(ctx);
}
private void doHandlePageException(Throwable t) throws IOException,
ServletException {
if (errorPageURL != null && !errorPageURL.equals("")) {
/*
* Set request attributes. Do not set the
* javax.servlet.error.exception attribute here (instead, set in the
* generated servlet code for the error page) in order to prevent
* the ErrorReportValve, which is invoked as part of forwarding the
* request to the error page, from throwing it if the response has
* not been committed (the response will have been committed if the
* error page is a JSP page).
*/
request.setAttribute(PageContext.EXCEPTION, t);
request.setAttribute(RequestDispatcher.ERROR_STATUS_CODE,
Integer.valueOf(HttpServletResponse.SC_INTERNAL_SERVER_ERROR));
request.setAttribute(RequestDispatcher.ERROR_REQUEST_URI,
((HttpServletRequest) request).getRequestURI());
request.setAttribute(RequestDispatcher.ERROR_SERVLET_NAME,
config.getServletName());
try {
forward(errorPageURL);
} catch (IllegalStateException ise) {
include(errorPageURL);
}
// The error page could be inside an include.
Object newException =
request.getAttribute(RequestDispatcher.ERROR_EXCEPTION);
// t==null means the attribute was not set.
if ((newException != null) && (newException == t)) {
request.removeAttribute(RequestDispatcher.ERROR_EXCEPTION);
}
// now clear the error code - to prevent double handling.
request.removeAttribute(RequestDispatcher.ERROR_STATUS_CODE);
request.removeAttribute(RequestDispatcher.ERROR_REQUEST_URI);
request.removeAttribute(RequestDispatcher.ERROR_SERVLET_NAME);
request.removeAttribute(PageContext.EXCEPTION);
} else {
// Otherwise throw the exception wrapped inside a ServletException.
// Set the exception as the root cause in the ServletException
// to get a stack trace for the real problem
if (t instanceof IOException)
throw (IOException) t;
if (t instanceof ServletException)
throw (ServletException) t;
if (t instanceof RuntimeException)
throw (RuntimeException) t;
Throwable rootCause = null;
if (t instanceof JspException) {
rootCause = ((JspException) t).getCause();
} else if (t instanceof ELException) {
rootCause = ((ELException) t).getCause();
}
if (rootCause != null) {
throw new ServletException(t.getClass().getName() + ": "
+ t.getMessage(), rootCause);
}
throw new ServletException(t);
}
}
@Override
public Object resolveVariable(String pName) throws ELException {
return this.ctx.getELResolver().getValue(this.ctx, null, pName);
}
@Override
public Object evaluate(VariableResolver vResolver) throws ELException {
ELContext ctx = new ELContextImpl(new ELResolverImpl(vResolver));
return ve.getValue(ctx);
}
private void doHandlePageException(Throwable t) throws IOException,
ServletException {
if (errorPageURL != null && !errorPageURL.equals("")) {
/*
* Set request attributes. Do not set the
* javax.servlet.error.exception attribute here (instead, set in the
* generated servlet code for the error page) in order to prevent
* the ErrorReportValve, which is invoked as part of forwarding the
* request to the error page, from throwing it if the response has
* not been committed (the response will have been committed if the
* error page is a JSP page).
*/
request.setAttribute(PageContext.EXCEPTION, t);
request.setAttribute(RequestDispatcher.ERROR_STATUS_CODE,
Integer.valueOf(HttpServletResponse.SC_INTERNAL_SERVER_ERROR));
request.setAttribute(RequestDispatcher.ERROR_REQUEST_URI,
((HttpServletRequest) request).getRequestURI());
request.setAttribute(RequestDispatcher.ERROR_SERVLET_NAME,
config.getServletName());
try {
forward(errorPageURL);
} catch (IllegalStateException ise) {
include(errorPageURL);
}
// The error page could be inside an include.
Object newException =
request.getAttribute(RequestDispatcher.ERROR_EXCEPTION);
// t==null means the attribute was not set.
if ((newException != null) && (newException == t)) {
request.removeAttribute(RequestDispatcher.ERROR_EXCEPTION);
}
// now clear the error code - to prevent double handling.
request.removeAttribute(RequestDispatcher.ERROR_STATUS_CODE);
request.removeAttribute(RequestDispatcher.ERROR_REQUEST_URI);
request.removeAttribute(RequestDispatcher.ERROR_SERVLET_NAME);
request.removeAttribute(PageContext.EXCEPTION);
} else {
// Otherwise throw the exception wrapped inside a ServletException.
// Set the exception as the root cause in the ServletException
// to get a stack trace for the real problem
if (t instanceof IOException)
throw (IOException) t;
if (t instanceof ServletException)
throw (ServletException) t;
if (t instanceof RuntimeException)
throw (RuntimeException) t;
Throwable rootCause = null;
if (t instanceof JspException) {
rootCause = ((JspException) t).getCause();
} else if (t instanceof ELException) {
rootCause = ((ELException) t).getCause();
}
if (rootCause != null) {
throw new ServletException(t.getClass().getName() + ": "
+ t.getMessage(), rootCause);
}
throw new ServletException(t);
}
}
@Override
public Object resolveVariable(String pName) throws ELException {
return this.ctx.getELResolver().getValue(this.ctx, null, pName);
}
@Override
public Object evaluate(VariableResolver vResolver) throws ELException {
ELContext ctx = new ELContextImpl(new ELResolverImpl(vResolver));
return ve.getValue(ctx);
}
public Class getType(ELContext context,
Object base,
Object property)
throws javax.el.ELException {
return null;
}
public void setValue(ELContext context,
Object base,
Object property,
Object value)
throws javax.el.ELException {
}
public boolean isReadOnly(ELContext context,
Object base,
Object property)
throws javax.el.ELException {
return false;
}
@Override
public Object evaluate(String arg0, Class arg1, VariableResolver arg2, FunctionMapper arg3) throws ELException {
return null;
}
@Override
public Expression parseExpression(String arg0, Class arg1, FunctionMapper arg2) throws ELException {
return null;
}