Example usage for javax.servlet.jsp.el ELException ELException

List of usage examples for javax.servlet.jsp.el ELException ELException

Introduction

In this page you can find the example usage for javax.servlet.jsp.el ELException ELException.

Prototype

public ELException(Throwable pRootCause) 

Source Link

Document

Creates an ELException with the given root cause.

Usage

From source file:it.cilea.osd.jdyna.web.tag.ExpressionEvaluatorImpl.java

/**
 * /*  w  w  w. j a v a 2s  .  co m*/
 * Evaluates the given expression String
 * 
 * @param pExpressionString
 *            The expression to be evaluated.
 * @param pExpectedType
 *            The expected type of the result of the evaluation
 * @param pResolver
 *            A VariableResolver instance that can be used at runtime to
 *            resolve the name of implicit objects into Objects.
 * @param functions
 *            A FunctionMapper to resolve functions found in the expression.
 *            It can be null, in which case no functions are supported for
 *            this invocation.
 * @return the expression String evaluated to the given expected type
 **/
public Object evaluate(String pExpressionString, Class pExpectedType, VariableResolver pResolver,
        FunctionMapper functions) throws ELException {
    // Check for null expression strings
    if (pExpressionString == null) {
        throw new ELException(Constants.NULL_EXPRESSION_STRING);
    }

    // Get the parsed version of the expression string
    Object parsedValue = parseExpressionString(pExpressionString);

    // Evaluate differently based on the parsed type
    if (parsedValue instanceof String) {
        // Convert the String, and cache the conversion
        String strValue = (String) parsedValue;
        return convertStaticValueToExpectedType(strValue, pExpectedType, pLogger);
    }

    else if (parsedValue instanceof Expression) {
        // Evaluate the expression and convert
        Object value = ((Expression) parsedValue).evaluate(pResolver, functions, pLogger);
        return convertToExpectedType(value, pExpectedType, pLogger);
    }

    else if (parsedValue instanceof ExpressionString) {
        // Evaluate the expression/string list and convert
        String strValue = ((ExpressionString) parsedValue).evaluate(pResolver, functions, pLogger);
        return convertToExpectedType(strValue, pExpectedType, pLogger);
    }

    else {
        // This should never be reached
        return null;
    }
}

From source file:it.cilea.osd.jdyna.web.tag.ExpressionEvaluatorImpl.java

/**
 * /*w  w  w.ja  v  a2  s  . c om*/
 * Gets the parsed form of the given expression string. If the parsed form
 * is cached (and caching is not bypassed), return the cached form,
 * otherwise parse and cache the value. Returns either a String, Expression,
 * or ExpressionString.
 **/
public Object parseExpressionString(String pExpressionString) throws ELException {
    // See if it's an empty String
    if (pExpressionString.length() == 0) {
        return "";
    }

    // See if it's in the cache
    Object ret = null;

    if (ret == null) {
        // Parse the expression
        Reader r = new StringReader(pExpressionString);
        ELParser parser = new ELParser(r);
        try {
            ret = parser.ExpressionString();

        } catch (ParseException exc) {
            throw new ELException(exc);
        } catch (TokenMgrError exc) {
            // Note - this should never be reached, since the parser is
            // constructed to tokenize any input (illegal inputs get
            // parsed to <BADLY_ESCAPED_STRING_LITERAL> or
            // <ILLEGAL_CHARACTER>
            throw new ELException(exc.getMessage());
        }
    }
    return ret;
}

From source file:com.streamsets.datacollector.el.ELEvaluator.java

@Override
@SuppressWarnings("unchecked")
public <T> T evaluate(final ELVars vars, String expression, Class<T> returnType) throws ELEvalException {
    VariableResolver variableResolver = new VariableResolver() {

        @Override//ww w. ja v a2  s. c o  m
        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) {
        LOG.debug("Error valuating EL '{}': {}", expression, e.toString(), e);
        Throwable t = e;
        if (e.getRootCause() != null) {
            t = e.getRootCause();
        }
        throw new ELEvalException(CommonError.CMN_0104, expression, t.toString(), e);
    }
}

From source file:org.apache.jasper.runtime.PageContextImpl.java

/**
 * Proprietary method to evaluate EL expressions.
 * XXX - This method should go away once the EL interpreter moves
 * out of JSTL and into its own project.  For now, this is necessary
 * because the standard machinery is too slow.
 *
 * @param expression The expression to be evaluated
 * @param expectedType The expected resulting type
 * @param pageContext The page context/*from  w  ww  .  ja  v  a2  s .  c om*/
 * @param functionMap Maps prefix and name to Method
 * @return The result of the evaluation
 */
public static Object proprietaryEvaluate(final String expression, final Class expectedType,
        final PageContext pageContext, final ProtectedFunctionMapper functionMap, final boolean escape)
        throws ELException {
    Object retValue;
    if (System.getSecurityManager() != null) {
        try {
            retValue = AccessController.doPrivileged(new PrivilegedExceptionAction() {

                public Object run() throws Exception {
                    return elExprEval.evaluate(expression, expectedType, pageContext.getVariableResolver(),
                            functionMap);
                }
            });
        } catch (PrivilegedActionException ex) {
            Exception realEx = ex.getException();
            if (realEx instanceof ELException) {
                throw (ELException) realEx;
            } else {
                throw new ELException(realEx);
            }
        }
    } else {
        retValue = elExprEval.evaluate(expression, expectedType, pageContext.getVariableResolver(),
                functionMap);
    }
    if (escape) {
        retValue = XmlEscape(retValue.toString());
    }

    return retValue;
}

From source file:org.apache.struts2.jasper.runtime.PageContextImpl.java

/**
 * Proprietary method to evaluate EL expressions.
 * XXX - This method should go away once the EL interpreter moves
 * out of JSTL and into its own project.  For now, this is necessary
 * because the standard machinery is too slow.
 *
 * @param expression   The expression to be evaluated
 * @param expectedType The expected resulting type
 * @param pageContext  The page context//  w  ww  .  java2s  .c  om
 * @param functionMap  Maps prefix and name to Method
 * @return The result of the evaluation
 */
public static Object proprietaryEvaluate(final String expression, final Class expectedType,
        final PageContext pageContext, final ProtectedFunctionMapper functionMap, final boolean escape)
        throws ELException {
    Object retValue;
    if (SecurityUtil.isPackageProtectionEnabled()) {
        try {
            retValue = AccessController.doPrivileged(new PrivilegedExceptionAction() {

                public Object run() throws Exception {
                    return elExprEval.evaluate(expression, expectedType, pageContext.getVariableResolver(),
                            functionMap);
                }
            });
        } catch (PrivilegedActionException ex) {
            Exception realEx = ex.getException();
            if (realEx instanceof ELException) {
                throw (ELException) realEx;
            } else {
                throw new ELException(realEx);
            }
        }
    } else {
        retValue = elExprEval.evaluate(expression, expectedType, pageContext.getVariableResolver(),
                functionMap);
    }
    if (escape) {
        retValue = XmlEscape(retValue.toString());
    }

    return retValue;
}