EasyuiButtonTag

import java.io.IOException;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.TagSupport;

import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;

/**
 * @ClassName: EasyuiButtonTag
 * @Description: Easyui的按钮生成标签,结合shiro权限判断
 * @author Bert
 * @date
 *
 */
public class EasyuiButtonTag extends TagSupport {

    /**
     *
     */
    private static final long serialVersionUID = 400291913904068822L;
    public static String EASYUIBUTTON = "easyuiButton";
    public static String IMAGEBUTTON = "imageButton";
    // easyui按钮对应的图标class
    private String iconCls = "";
    // 按钮对应的js函数名称
    private String method = "";
    // 按钮对应的shiro访问权限字符串
    private String permission = "";
    // 按钮显示的操作名称
    private String operationName = "";
    // 要生成按钮的类型,默认为easyui的按钮类型
    private String type = EASYUIBUTTON;
    // 生成图片按钮时的图片链接
    private String imgSrc = "";

    public String getIconCls() {
        return iconCls;
    }

    public void setIconCls(String iconCls) {
        this.iconCls = iconCls;
    }

    public String getMethod() {
        return method;
    }

    public void setMethod(String method) {
        this.method = method;
    }

    public String getPermission() {
        return permission;
    }

    public void setPermission(String permission) {
        this.permission = permission;
    }

    public String getOperationName() {
        return operationName;
    }

    public void setOperationName(String operationName) {
        this.operationName = operationName;
    }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    public String getImgSrc() {
        return imgSrc;
    }

    public void setImgSrc(String imgSrc) {
        this.imgSrc = imgSrc;
    }
    
    @Override
    public int doEndTag() throws JspException {
        return EVAL_PAGE;
    }

    @Override
    public int doStartTag() throws JspException {
        if (!"".equals(this.permission)) {
            Subject subject = SecurityUtils.getSubject();
            if (subject.isPermitted(this.permission)) {
                try {
                    if (EASYUIBUTTON.equals(type)) {
                        pageContext.getOut().println(createEasyuiButton());
                    } else if (IMAGEBUTTON.equals(type)) {
                        pageContext.getOut().print(createImageButton());
                    }
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
        return SKIP_BODY;
    }

    /**
     *
     * @Title: createEasyuiButton
     * @Description: 生成easyui的button
     * @param @return
     * @return String
     * @throws
     */
    private String createEasyuiButton() {
        StringBuffer buffer = new StringBuffer("<a class=\"easyui-linkbutton\" data-options=\"plain : true,");
        if (!"".equals(this.iconCls) && this.iconCls != null) {
            buffer.append("iconCls : '" + this.iconCls + "'\"");
        }
        if (!"".equals(this.method) && this.method != null) {
            buffer.append(" href=\"javascript:" + this.method + "\"");
        }
        buffer.append(">");
        if (!"".equals(this.operationName) && this.operationName != null) {
            buffer.append(this.operationName);
        }
        buffer.append("</a>");
        return buffer.toString();
    }

    /**
     *
     * @Title: createImageButton
     * @Description: 生成图片按钮
     * @param @return
     * @return String
     * @throws
     */
    private String createImageButton() {
        if (!"".equals(this.imgSrc)) {
            StringBuffer buffer = new StringBuffer("<img style=\"cursor: pointer;\"  ");
            if (!"".equals(this.method)) {
                buffer.append(" οnclick=\"" + this.method + "\" ");
            }
            buffer.append(" src=\"" + this.imgSrc + "\" ");
            if (!"".equals(this.operationName)) {
                buffer.append(" title=\"" + this.operationName + "\" ");
            }
            buffer.append(" /> ");
            return buffer.toString();
        } else {
            return "";
        }
    }

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值