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

📄 elutils.java

📁 Please read your package and describe it at least 40 bytes in English. System will automatically de
💻 JAVA
字号:
/* * Copyright 2002-2004 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * *      http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */package de.mindmatters.faces.el;import java.lang.reflect.Method;import javax.faces.context.FacesContext;import javax.faces.el.ReferenceSyntaxException;import javax.faces.el.ValueBinding;import javax.servlet.jsp.el.ELException;import javax.servlet.jsp.el.FunctionMapper;import javax.servlet.jsp.el.VariableResolver;import org.apache.commons.el.Coercions;import org.apache.commons.el.ComplexValue;import org.apache.commons.el.ConditionalExpression;import org.apache.commons.el.NamedValue;/** * Utility class for interpreting and evaluating parsed JSF reference * expressions. *  * @author Andreas Kuhrwahl * @see ELParser *  */public final class ELUtils {    /** The servlet-api based VariableResolver. */    private static final VariableResolver VARIABLE_RESOLVER = new ELVariableResolver();    /** The function mapper. */    private static final FunctionMapper FUNCTION_MAPPER = new FunctionMapper() {        public Method resolveFunction(final String prefix,                final String localName) {            throw new ReferenceSyntaxException(                    "Functions not supported in expressions. Function: "                            + prefix + ":" + localName);        }    };    /**     * It's a static class!     */    private ELUtils() {    }    /**     * Returns the name of the base of the given expression     * <code>expression</code> if any.     *      * @param context     *            {@link FacesContext} for the current request     * @param expression     *            The parsed expression.     * @return The name of the base of the given expression or <code>null</code>     *         if not present     */    private static String resolveToBase(final FacesContext context,            final Object expression) {        String beanName = null;        if (context == null) {            throw new NullPointerException("FacesContext");        }        Object currentExpression = expression;        while (currentExpression instanceof ConditionalExpression) {            try {                ConditionalExpression conditionalExpression = (ConditionalExpression) expression;                boolean condition = Coercions.coerceToBoolean(                        conditionalExpression.getCondition().evaluate(                                VARIABLE_RESOLVER, FUNCTION_MAPPER,                                ELParser.LOGGER), ELParser.LOGGER)                        .booleanValue();                if (condition) {                    currentExpression = conditionalExpression.getTrueBranch();                } else {                    currentExpression = conditionalExpression.getFalseBranch();                }            } catch (ELException ex) {                throw new ReferenceSyntaxException(ex.getMessage(), ex);            }        }        if (currentExpression instanceof NamedValue) {            beanName = ((NamedValue) currentExpression).getName();        } else if (currentExpression instanceof ComplexValue) {            ComplexValue complexValue = (ComplexValue) currentExpression;            beanName = resolveToBase(context, (Object) complexValue.getPrefix());        }        return beanName;    }    /**     * Returns the name of the base of the given JSF reference expression string     * <code>expressionString</code> if any.     *      * @param context     *            {@link FacesContext} for the current request     * @param expressionString     *            The reference expression     * @return The name of the base of the given expression or <code>null</code>     *         if not present     */    public static String resolveToBase(final FacesContext context,            final String expressionString) {        try {            return resolveToBase(context, ELParser.getCurrentInstance()                    .parseExpression(expressionString));        } catch (ReferenceSyntaxException ex) {            return null;        }    }    /**     * Returns the name of the base of the given ValueBinding     * <code>valueBinding</code> if any.     *      * @param context     *            {@link FacesContext} for the current request     * @param valueBinding     *            The ValueBinding     * @return The name of the base of the given ValueBinding or     *         <code>null</code> if not present     */    public static String resolveToBase(final FacesContext context,            final ValueBinding valueBinding) {        return resolveToBase(context, valueBinding.getExpressionString());    }}

⌨️ 快捷键说明

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