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

📄 controltag.java

📁 struts+spring+hibernate自创框架
💻 JAVA
字号:
package com.pegasus.framework.component.taglib.html;

import org.apache.commons.beanutils.PropertyUtils;
import org.apache.commons.collections.IteratorUtils;
import org.apache.struts.taglib.TagUtils;
import org.apache.struts.taglib.html.BaseHandlerTag;

import javax.servlet.jsp.JspException;
import java.lang.reflect.InvocationTargetException;
import java.util.Arrays;
import java.util.Collection;
import java.util.Enumeration;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;

public class ControlTag extends BaseHandlerTag {
    protected String codeValue;
    protected String code = null;

    protected String idName = null;

    protected String setName;

    protected String setProperty;

    protected String setValue;

    /**
     * @return .
     */
    public String getCode() {
        return code;
    }

    /**
     * @param code .
     */
    public void setCode(String code) {
        this.code = code;
    }

    /**
     * @return .
     */
    public String getIdName() {
        return idName;
    }

    /**
     * @param idName .
     */
    public void setIdName(String idName) {
        this.idName = idName;
    }

    /**
     * @return .
     */
    public String getSetName() {
        return setName;
    }

    /**
     * @param setName .
     */
    public void setSetName(String setName) {
        this.setName = setName;
    }

    /**
     * @return .
     */
    public String getSetProperty() {
        return setProperty;
    }

    /**
     * @param setProperty .
     */
    public void setSetProperty(String setProperty) {
        this.setProperty = setProperty;
    }

    /**
     * @return .
     */
    public String getSetValue() {
        return setValue;
    }

    /**
     * @param setValue .
     */
    public void setSetValue(String setValue) {
        this.setValue = setValue;
    }

    /**
     * @return .
     * @throws JspException .
     */
    protected boolean condition() throws JspException {
        if (setName == null || code == null) return true;

        if (codeValue == null) {
            if (idName == null)
                codeValue = code;
            else {
                Object obj = TagUtils.getInstance().lookup(pageContext, idName, code, null);
                codeValue = formatValue(obj);
            }
        }

        Object set_values = TagUtils.getInstance().lookup(pageContext, setName, setProperty, null);
        if (set_values == null) {
            return true;
        }
        Set set = null;
        if (set_values instanceof Set)
            set = (Set) set_values;
        else
            set = getSet(set_values);
        return set.contains(codeValue);
    }

    /**
     * @param value .
     * @return .
     * @throws JspException .
     */
    protected String formatValue(Object value) throws JspException {
        if (value == null)
            return "";
        else
            return TagUtils.getInstance().filter(value.toString());
    }

    /**
     * @param collection .
     * @return .
     * @throws JspException .
     */
    protected Iterator getIterator(Object collection) throws JspException {
        if (collection.getClass().isArray())
            collection = Arrays.asList((Object[]) collection);
        if (collection instanceof Collection)
            return ((Collection) collection).iterator();
        if (collection instanceof Iterator)
            return (Iterator) collection;
        if (collection instanceof Map)
            return ((Map) collection).values().iterator();
        if (collection instanceof Enumeration)
            return IteratorUtils.asIterator((Enumeration) collection);
        else
            throw new JspException(messages.getMessage("radioCollectionTag.iterator", collection.toString()));
    }

    /**
     * @param iterator .
     * @return .
     * @throws JspException .
     */
    protected Set initSet(Iterator iterator) throws JspException {
        Set set = new HashSet();
        while (iterator.hasNext()) {
            Object bean = iterator.next();
            if (setValue == null || "".equals(setValue))
                set.add(bean.toString());
            else {
                Object beanValue = null;
                try {
                    beanValue = PropertyUtils.getProperty(bean, setValue);
                    if (beanValue == null)
                        beanValue = "";
                }
                catch (IllegalAccessException e) {
                    JspException jspe = new JspException(messages.getMessage("getter.access", setValue, bean));
                    TagUtils.getInstance().saveException(pageContext, jspe);
                    throw jspe;
                }
                catch (InvocationTargetException e) {
                    Throwable t = e.getTargetException();
                    JspException jspe = new JspException(messages.getMessage("getter.result", setValue, t
                            .toString()));
                    TagUtils.getInstance().saveException(pageContext, jspe);
                    throw jspe;
                }
                catch (NoSuchMethodException e) {
                    JspException jspe = new JspException(messages.getMessage("getter.method", setValue, bean));
                    TagUtils.getInstance().saveException(pageContext, jspe);
                    throw jspe;
                }
                set.add(beanValue.toString());
            }
        }
        return set;
    }

    /**
     * @param collection .
     * @return .
     * @throws JspException .
     */
    protected Set getSet(Object collection) throws JspException {
        Iterator iter = getIterator(collection);
        return initSet(iter);
    }

    /**
     *
     */
    public void release() {
        super.release();
        clear();
    }

    /**
     *
     */
    protected void clear() {
        codeValue = null;
//        code = null;
//        idName = null;
//        setValue = null;
//        setProperty = null;
//        setValue = null;

    }

}

⌨️ 快捷键说明

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