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

📄 imagetag.java

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

import org.apache.struts.Globals;
import org.apache.struts.config.ModuleConfig;
import org.apache.struts.taglib.TagUtils;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.jsp.JspException;


public class ImageTag extends SubmitTag {
    /**
     * The alignment for this image.
     */
    protected String align = null;

    /**
     * @return .
     * @deprecated Align attribute is deprecated in HTML 4.x.
     */
    public String getAlign() {
        return (this.align);
    }

    /**
     * @param align .
     * @deprecated Align attribute is deprecated in HTML 4.x.
     */
    public void setAlign(String align) {
        this.align = align;
    }


    /**
     * The border attributersSize around the image.
     */
    protected String border = null;

    /**
     * @return .
     */
    public String getBorder() {
        return (this.border);
    }

    /**
     * @param border .
     */
    public void setBorder(String border) {
        this.border = border;
    }


    /**
     * The module-relative URI of the image.
     */
    protected String page = null;

    /**
     * @return .
     */
    public String getPage() {
        return (this.page);
    }

    /**
     * @param page .
     */
    public void setPage(String page) {
        this.page = page;
    }


    /**
     * The message resources key of the module-relative URI of the image.
     */
    protected String pageKey = null;

    /**
     * @return .
     */
    public String getPageKey() {
        return (this.pageKey);
    }

    /**
     * @param pageKey .
     */
    public void setPageKey(String pageKey) {
        this.pageKey = pageKey;
    }


    /**
     * The name attribute for the image button.
     */
    protected String property = "";

    /**
     * @return .
     */
    public String getProperty() {
        return (this.property);
    }

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


    /**
     * The URL of this image.
     */
    protected String src = null;

    /**
     * @return .
     */
    public String getSrc() {
        return (this.src);
    }

    /**
     * @param src .
     */
    public void setSrc(String src) {
        this.src = src;
    }


    /**
     * The message resources key for the URL of this image.
     */
    protected String srcKey = null;

    /**
     * @return .
     */
    public String getSrcKey() {
        return (this.srcKey);
    }

    /**
     * @param srcKey .
     */
    public void setSrcKey(String srcKey) {
        this.srcKey = srcKey;
    }

    // --------------------------------------------------------- Public Methods


    /**
     * Process the start of this tag.
     *
     * @return .
     * @throws JspException if a JSP exception has occurred
     */
    public int doStartTag() throws JspException {
        super.clear();
        return (EVAL_BODY_TAG);

    }


    /**
     * Process the end of this tag.
     * [Indexed property since Struts 1.1]
     * @return  .
     * @throws JspException if a JSP exception has occurred
     */
    public int doEndTag() throws JspException {

        // Generate an HTML <input type="image"> element
        HttpServletResponse response =
                (HttpServletResponse) pageContext.getResponse();
        String tmp;
        StringBuffer results = new StringBuffer();
        results.append("<input type=\"image\"");
        if (property != null) {
            results.append(" name=\"");
            results.append(property);

            if (indexed) {
                prepareIndex(results, null);
            }
            results.append("\"");
        }

        tmp = src();
        if (tmp != null) {
            results.append(" src=\"");
            results.append(response.encodeURL(tmp));
            results.append("\"");
        }
        if (align != null) {
            results.append(" align=\"");
            results.append(align);
            results.append("\"");
        }
        if (border != null) {
            results.append(" border=\"");
            results.append(border);
            results.append("\"");
        }
        if (value != null) {
            results.append(" value=\"");
            results.append(value);
            results.append("\"");
        }
        if (accesskey != null) {
            results.append(" accesskey=\"");
            results.append(accesskey);
            results.append("\"");
        }
        if (tabindex != null) {
            results.append(" tabindex=\"");
            results.append(tabindex);
            results.append("\"");
        }
        results.append(prepareEventHandlers());
        results.append(prepareStyles());
        results.append(getElementClose());
        if (condition())
            TagUtils.getInstance().write(pageContext, results.toString());

        return (EVAL_PAGE);

    }


    /**
     * Release any acquired resources.
     */
    public void release() {

        super.release();
        page = null;
        pageKey = null;
        property = "";
        src = null;
        srcKey = null;

    }

    // ------------------------------------------------------ Protected Methods


    /**
     * Return the base source URL that will be rendered in the <code>src</code>
     * property for this generated element, or <code>null</code> if there is
     * no such URL.
     *
     * @return .
     * @throws JspException if an error occurs
     */
    protected String src() throws JspException {

        // Deal with a direct context-relative page that has been specified
        if (this.page != null) {
            if ((this.src != null) || (this.srcKey != null) ||
                    (this.pageKey != null)) {
                JspException e = new JspException(messages.getMessage("imgTag.src"));
                TagUtils.getInstance().saveException(pageContext, e);
                throw e;
            }

            ModuleConfig config = (ModuleConfig)
                    pageContext.getRequest().getAttribute(Globals.MODULE_KEY);

            HttpServletRequest request =
                    (HttpServletRequest) pageContext.getRequest();

            if (config == null) {
                return (request.getContextPath() + this.page);
            }
            else {
                return (request.getContextPath() + config.getPrefix() + this.page);
            }
        }

        // Deal with an indirect context-relative page that has been specified
        if (this.pageKey != null) {
            if ((this.src != null) || (this.srcKey != null)) {
                JspException e = new JspException(messages.getMessage("imgTag.src"));
                TagUtils.getInstance().saveException(pageContext, e);
                throw e;
            }

            ModuleConfig config = (ModuleConfig)
                    pageContext.getRequest().getAttribute(Globals.MODULE_KEY);

            HttpServletRequest request =
                    (HttpServletRequest) pageContext.getRequest();

            if (config == null) {
                return (
                        request.getContextPath()
                                + TagUtils.getInstance().message(
                                pageContext,
                                getBundle(),
                                getLocale(),
                                this.pageKey));
            }
            else {
                return (
                        request.getContextPath()
                                + config.getPrefix()
                                + TagUtils.getInstance().message(
                                pageContext,
                                getBundle(),
                                getLocale(),
                                this.pageKey));
            }
        }

        // Deal with an absolute source that has been specified
        if (this.src != null) {
            if (this.srcKey != null) {
                JspException e = new JspException(messages.getMessage("imgTag.src"));
                TagUtils.getInstance().saveException(pageContext, e);
                throw e;
            }
            return (this.src);
        }

        // Deal with an indirect source that has been specified
        if (this.srcKey == null) {
            JspException e = new JspException(messages.getMessage("imgTag.src"));
            TagUtils.getInstance().saveException(pageContext, e);
            throw e;
        }

        return TagUtils.getInstance().message(
                pageContext,
                getBundle(),
                getLocale(),
                this.srcKey);

    }

}

⌨️ 快捷键说明

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