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

📄 evalhelper.java

📁 jakarta-struts-1.2.4-src
💻 JAVA
字号:
/*
 * $Header: /home/cvs/jakarta-struts/contrib/struts-el/src/share/org/apache/strutsel/taglib/utils/EvalHelper.java,v 1.3 2004/03/14 07:15:06 sraeburn Exp $
 * $Revision: 1.3 $
 * $Date: 2004/03/14 07:15:06 $
 *
 * Copyright 1999-2004 The Apache Software Foundation.
 * 
 * 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 org.apache.strutsel.taglib.utils;

import javax.servlet.jsp.PageContext;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.Tag;
import org.apache.taglibs.standard.lang.support.ExpressionEvaluatorManager;

/**
 * This class is used in the <code>evaluateExpressions</code> method of each
 * Tag class.  It is used to process the original attribute value through the
 * JSTL EL engine to produce an evaluated value.  It provides functions to
 * evaluate the expression assuming it is an Object, String, Integer, or
 * Boolean result.
 */
public final class EvalHelper
{
    private EvalHelper() {}

    /**
     * Evaluates the attribute value in the JSTL EL engine, returning the raw
     * Object value of the evaluated expression.  If the original expression is
     * null, or the resulting value is null, it will return null.
     */
    public static Object eval(String      attrName,
                              String      attrValue,
                              Tag         tagObject,
                              PageContext pageContext) 
        throws JspException
    {
        Object result   = null;
        if (attrValue != null) {
            result   =
                ExpressionEvaluatorManager.
                evaluate(attrName, attrValue, Object.class, tagObject,
                         pageContext);
        }

        return (result);
    }

    /**
     * Evaluates the attribute value in the JSTL EL engine, assuming the
     * resulting value is a String object.  If the original expression is null,
     * or the resulting value is null, it will return null.
     */
    public static String evalString(String      attrName,
                                    String      attrValue,
                                    Tag         tagObject,
                                    PageContext pageContext) 
        throws JspException
    {
        Object result   = null;
        if (attrValue != null) {
            result   =
                ExpressionEvaluatorManager.
                evaluate(attrName, attrValue, String.class, tagObject,
                         pageContext);
        }

        return ((String) result);
    }

    /**
     * Evaluates the attribute value in the JSTL EL engine, assuming the
     * resulting value is an Integer object.  If the original expression is
     * null, or the resulting value is null, it will return null.
     */
    public static Integer evalInteger(String       attrName,
                                      String       attrValue,
                                      Tag          tagObject,
                                      PageContext  pageContext) 
        throws JspException
    {
        Object result   = null;
        if (attrValue != null) {
            result   = ExpressionEvaluatorManager.
                evaluate(attrName, attrValue, Integer.class, tagObject,
                         pageContext);
        }

        return ((Integer) result);
    }

    /**
     * Evaluates the attribute value in the JSTL EL engine, assuming the
     * resulting value is an Boolean object.  If the original expression is
     * null, or the resulting value is null, it will return null.
     */
    public static Boolean evalBoolean(String       attrName,
                                      String       attrValue,
                                      Tag          tagObject,
                                      PageContext  pageContext) 
        throws JspException
    {
        Object result   = null;
        if (attrValue != null) {
            result   = ExpressionEvaluatorManager.
                evaluate(attrName, attrValue, Boolean.class, tagObject,
                         pageContext);
        }

        return ((Boolean) result);
    }
}

⌨️ 快捷键说明

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