⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 elparserhelper.java

📁 一个使用struts+hibernate+spring开发的完的网站源代码。
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
    private static boolean isEscaped(String expressionString, int i)    {        int escapeCharCount = 0;        while ((--i >= 0) && (expressionString.charAt(i) == '\\'))        {            escapeCharCount++;        }        return (escapeCharCount % 2) != 0;    }    /**     * Replaces all <code>ValueSuffix</code>es with custom implementation     * ValueSuffexes that use JSF <code>PropertyResolver</code> insted of JSP     * EL one.     *      * @param expression <code>Expression</code> or     *        <code>ExpressionString</code> instance     * @param application <code>Application</code> instance to get     *        <code>PropertyResolver</code> from     */    private static void replaceSuffixes(Object expression)    {        if (expression instanceof Expression)        {            replaceSuffixes((Expression) expression);        }        else if (expression instanceof ExpressionString)        {            replaceSuffixes((ExpressionString) expression);        }        else        {            throw new IllegalStateException(                "Expression element of unknown class: "                    + expression.getClass().getName());        }    }    private static void replaceSuffixes(ExpressionString expressionString)    {        Object[] expressions = expressionString.getElements();        for (int i = 0, len = expressions.length; i < len; i++)        {            Object expression = expressions[i];            if (expression instanceof Expression)            {                replaceSuffixes((Expression) expression);            }            else if (expression instanceof ExpressionString)            {                replaceSuffixes((ExpressionString) expression);            }            else if (!(expression instanceof String))            {                throw new IllegalStateException(                    "Expression element of unknown class: "                        + expression.getClass().getName());            }            // ignore Strings        }    }    static void replaceSuffixes(Expression expression)    {        if (expression instanceof BinaryOperatorExpression)        {            replaceSuffixes(((BinaryOperatorExpression) expression)                .getExpression());        }        else if (expression instanceof ComplexValue)        {            replaceSuffixes((ComplexValue) expression);        }        else if (expression instanceof ConditionalExpression)        {            ConditionalExpression conditionalExpression =                 (ConditionalExpression) expression;            replaceSuffixes(conditionalExpression.getTrueBranch());            replaceSuffixes(conditionalExpression.getFalseBranch());        }        else if (expression instanceof UnaryOperatorExpression)        {            replaceSuffixes(((UnaryOperatorExpression) expression)                .getExpression());        }        // ignore the remaining expression types        else if (!(expression instanceof FunctionInvocation            || expression instanceof Literal || expression instanceof NamedValue))        {            throw new IllegalStateException(                "Expression element of unknown class: "                    + expression.getClass().getName());        }    }    private static void replaceSuffixes(ComplexValue complexValue)    {        Application application = FacesContext.getCurrentInstance()            .getApplication();        List suffixes = complexValue.getSuffixes();        for (int i = 0, len = suffixes.size(); i < len; i++)        {            ValueSuffix suffix = (ValueSuffix) suffixes.get(i);            if (suffix instanceof PropertySuffix)            {                if (suffix instanceof MyPropertySuffix)                {                    throw new IllegalStateException(                        "Suffix is MyPropertySuffix and must not be");                }                suffixes.set(i, new MyPropertySuffix((PropertySuffix) suffix,                    application));            }            else if (suffix instanceof ArraySuffix)            {                if (suffix instanceof MyArraySuffix)                {                    throw new IllegalStateException(                        "Suffix is MyArraySuffix and must not be");                }                suffixes.set(i, new MyArraySuffix((ArraySuffix) suffix,                    application));            }            else            {                throw new IllegalStateException("Unknown suffix class: "                    + suffix.getClass().getName());            }        }    }    private static Integer coerceToIntegerWrapper(Object base, Object index)        throws EvaluationException, ELException    {        Integer integer = Coercions.coerceToInteger(index, LOGGER);        if (integer != null)        {            return integer;        }        throw new ReferenceSyntaxException(            "Cannot convert index to int for base " + base.getClass().getName()                + " and index " + index);    }    /**     * Coerces <code>index</code> to Integer for array types, or returns     * <code>null</code> for non-array types.     *      * @param base Object for the base     * @param index Object for the index     * @return Integer a valid Integer index, or null if not an array type     *      * @throws ELException if exception occurs trying to coerce to Integer     * @throws EvaluationException if base is array type but cannot convert     *         index to Integer     */    public static Integer toIndex(Object base, Object index)        throws ELException, EvaluationException    {        if ((base instanceof List) || (base.getClass().isArray()))        {            return coerceToIntegerWrapper(base, index);        }        if (base instanceof UIComponent)        {            try            {                return coerceToIntegerWrapper(base, index);            }            catch (Throwable t)            {                // treat as simple property                return null;            }        }        // If not an array type        return null;    }    /**     * Override ArraySuffix.evaluate() to use our property resolver     */    public static class MyArraySuffix extends ArraySuffix    {        private Application _application;        public MyArraySuffix(ArraySuffix arraySuffix, Application application)        {            super(arraySuffix.getIndex());            replaceSuffixes(getIndex());            _application = application;        }        /**         * Evaluates the expression in the given context, operating on the given         * value, using JSF property resolver.         */        public Object evaluate(Object base, VariableResolver variableResolver,            FunctionMapper functions, Logger logger)            throws ELException        {            // Check for null value            if (base == null)            {                return null;            }            // Evaluate the index            Object indexVal = getIndex().evaluate(variableResolver, functions,                logger);            if (indexVal == null)            {                return null;            }            Integer index = toIndex(base, indexVal);            if (index == null)            {                return _application.getPropertyResolver().getValue(base,                    indexVal);            }            else            {                return _application.getPropertyResolver().getValue(base,                    index.intValue());            }        }    }    public static class MyPropertySuffix extends PropertySuffix    {        private Application _application;        public MyPropertySuffix(PropertySuffix propertySuffix,            Application application)        {            super(propertySuffix.getName());            _application = application;        }        /**         * Evaluates the expression in the given context, operating on the given         * value, using JSF property resolver.         */        public Object evaluate(Object base, VariableResolver variableResolver,            FunctionMapper functions, Logger logger)            throws ELException        {            // Check for null value            if (base == null)            {                return null;            }            // Evaluate the index            String indexVal = getName();            if (indexVal == null)            {                return null;            }            Integer index = toIndex(base, indexVal);            if (index == null)            {                return _application.getPropertyResolver().getValue(base,                    indexVal);            }            else            {                return _application.getPropertyResolver().getValue(base,                    index.intValue());            }        }    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -