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

📄 jahiabutton.java

📁 java 写的一个新闻发布系统
💻 JAVA
字号:
package org.jahia.taglibs.button;import org.jahia.utils.JahiaConsole;import org.jahia.data.JahiaData;import org.jahia.utils.JahiaTools;import org.jahia.params.ParamBean;import org.jahia.resourcebundle.JahiaResourceBundle;import org.jahia.taglibs.resourcebundle.EngineResourceBundleTag;import java.io.*;import java.util.*;import javax.servlet.*;import javax.servlet.http.*;import javax.servlet.jsp.*;import javax.servlet.jsp.tagext.*;/** * Create a graphic rollover button defining by three parameters. * * All these following parameters are required ('JahiaTags.tld' file) : * * img :    The image button start name defined in the resource bundle properties            files. For example if the button defined in the resource bundle file            is 'sortOffButtonImg' and 'sortOnButtonIMg', the start name is 'sort'.            This tag will retrieve automatically the end of string identifier. * href :   This is the anchor tag <A> "href" parameter. * alt :    Correspond to the <IMG> tag "alt" parameter. */public class JahiaButton extends BodyTagSupport {    public void setImg(String img) {        this.img = img;    }    public void setHref(String href) {        this.href = href;    }    public void setAlt(String alt) {        this.alt = alt;    }    public int doStartTag() {        // Recover 'jData'        HttpServletRequest request = (HttpServletRequest)pageContext.getRequest();        JahiaData jData = (JahiaData)request.getAttribute("org.jahia.data.JahiaData");        if (jData == null) {            HashMap tempEngineMap = (HashMap)request.getAttribute("org.jahia.engines.EngineHashMap");            jData = (JahiaData)tempEngineMap.get("jData");        }        // Build the resource bundle image parameters        String bImageOff = "";        String bImageOn = "";        try {            bImageOff = EngineResourceBundleTag.parseResourceValue(                            JahiaResourceBundle.getEngineResource(img + "OffButtonImg",                                                                  jData.params(),                                                                  jData.params().getLocale()),jData.params());            bImageOn = EngineResourceBundleTag.parseResourceValue(                            JahiaResourceBundle.getEngineResource(img + "OnButtonImg",                                                                  jData.params(),                                                                  jData.params().getLocale()),jData.params());        } catch (MissingResourceException mre) {            JahiaConsole.println("JahiaButton.doStartTag", mre.toString());        }        // FIXME : Why does the "JahiaResourceBundle.getEngineResource" method        // return a null String when resource is not found ????        if (bImageOff == null) bImageOff = "";        if (bImageOn == null) bImageOn = "";        bImageOff = getServerHttpPath(jData.params()) + bImageOff;        bImageOn = getServerHttpPath(jData.params()) + bImageOn;        // Define a unique ID that identify the rollover        String sImgID = "img" + String.valueOf(imgID++);        // Produce the HTML code        try {            JspWriter out = pageContext.getOut();            StringBuffer str = new StringBuffer("\n");            if (debug) {                str.append("<!-- ============================================================= -->\n");                str.append("<!-- The following HTML code is generated by 'jahiaButton' taglib -->\n");                str.append("<!-- Parameters : img = ");                    str.append(img); str.append("\n");                str.append("                : href = ");                    str.append(href); str.append("\n");                str.append("                : alt = ");                    str.append(alt);                    str.append("\n--------------------------------------------------------------------->\n");            }            str.append("<a href=\"");                str.append(href);                str.append("\"\n");            str.append("   onMouseOut=\"MM_swapImgRestore()\"\n");            str.append("   onMouseOver=\"MM_swapImage('");                str.append(sImgID);                str.append("','','");                str.append(bImageOn);                str.append("',1)\">\n");            str.append("   <img name=\"");                str.append(sImgID);                str.append("\" alt=\"");                str.append(alt);                str.append("\"\n");            str.append("        src=\"");                str.append(bImageOff);                str.append("\" border=\"0\"></a>\n");            // @todo : an optional focus parameter (yes/no) are to be implemented            //      1. give a "name" the anchor <a>.            //      2. use this name to implement the following focus script.            // str.append(<script language="javascript">a62.focus();</script>);            if (debug) {                str.append("<!-- ============================================================= -->\n");            }            out.print(str.toString());        } catch (IOException ioe) {            JahiaConsole.println("JahiaButton.doStartTag", ioe.toString());        }        return SKIP_BODY;    }    /**     * Build an http path containing the server name and port,     * instead of the path from JahiaPrivateSettings.     *     * @return An http path leading to Jahia, built with the server name, and     *         the server port if nonstandard.     *     * FIXME : This method duplicate the method already defined in ServerHttpPathTag     */    private final String getServerHttpPath (ParamBean jParams)    {        return jParams.getRequest().getContextPath();    }    // Taglib parameters    private String img = "";    private String href = "";    private String alt = "";    // Internal members    private static long imgID = 0;    private boolean debug = true;}

⌨️ 快捷键说明

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