1 package org.jahia.taglibs.button; 2 3 import java.io.IOException ; 4 import java.util.MissingResourceException ; 5 6 import javax.servlet.http.HttpServletRequest ; 7 import javax.servlet.jsp.JspException ; 8 import javax.servlet.jsp.JspWriter ; 9 import javax.servlet.jsp.tagext.BodyTagSupport ; 10 11 import org.jahia.data.JahiaData; 12 import org.jahia.params.ParamBean; 13 import org.jahia.resourcebundle.JahiaResourceBundle; 14 import org.jahia.taglibs.resourcebundle.EngineResourceBundleTag; 15 import org.jahia.utils.JahiaConsole; 16 17 29 public class JahiaButton extends BodyTagSupport { 30 31 private static org.apache.log4j.Logger logger = 32 org.apache.log4j.Logger.getLogger(JahiaButton.class); 33 34 public void setImg(String img) { 35 this.img = img; 36 } 37 38 public void setHref(String href) { 39 this.href = href; 40 } 41 42 public void setAlt(String alt) { 43 this.alt = alt; 44 } 45 46 public void setAltKey(String altKey) { 47 this.altKey = altKey; 48 } 49 50 public void setAltBundle(String altBundle) { 51 this.altBundle = altBundle; 52 } 53 54 public void setOnclick(String onclick) { 55 this.onclick = onclick; 56 } 57 58 59 public int doStartTag() { 60 61 HttpServletRequest request = (HttpServletRequest )pageContext.getRequest(); 63 JahiaData jData = (JahiaData)request.getAttribute("org.jahia.data.JahiaData"); 64 65 String bImageOff = ""; 67 String bImageOn = ""; 68 try { 69 bImageOff = EngineResourceBundleTag.parseResourceValue( 70 JahiaResourceBundle.getEngineResource("org.jahia." + img + "Off.button", 71 jData.params(), 72 jData.params().getLocale()),jData.params()); 73 bImageOn = EngineResourceBundleTag.parseResourceValue( 74 JahiaResourceBundle.getEngineResource("org.jahia." + img + "On.button", 75 jData.params(), 76 jData.params().getLocale()),jData.params()); 77 78 } catch (MissingResourceException mre) { 79 logger.debug("Error while trying to retrieve resource for image :" + img, mre); 80 } 81 82 if (bImageOff == null) bImageOff = ""; 85 if (bImageOn == null) bImageOn = ""; 86 bImageOff = getServerHttpPath(jData.params()) + bImageOff; 87 bImageOn = getServerHttpPath(jData.params()) + bImageOn; 88 String sImgID = "img" + String.valueOf(imgID++); 90 91 if (altKey != null) { 93 alt = JahiaResourceBundle.getResource(altBundle, altKey, jData.params().getLocale(), jData.params()); 94 } 95 96 try { 98 JspWriter out = pageContext.getOut(); 99 StringBuffer str = new StringBuffer ("\n"); 100 if (debug) { 101 str.append("<!-- ============================================================= -->\n"); 102 str.append("<!-- The following HTML code is generated by 'jahiaButton' taglib -->\n"); 103 str.append("<!-- Parameters : img = "); 104 str.append(img); str.append("\n"); 105 str.append(" : href = "); 106 str.append(href); str.append("\n"); 107 str.append(" : alt = "); 108 str.append(alt); 109 str.append("\n--------------------------------------------------------------------->\n"); 110 } 111 str.append("<a HREF=\""); 112 str.append(href); 113 str.append("\"\n"); 114 str.append(" onMouseOut=\"MM_swapImgRestore()\"\n"); 115 str.append(" onMouseOver=\"MM_swapImage('"); 116 str.append(sImgID); 117 str.append("','','"); 118 str.append(bImageOn); 119 str.append("',1)\"\n"); 120 if (onclick != null) { 121 str.append(" onclick=\""); 122 str.append(onclick); 123 str.append("\"\n"); 124 } 125 str.append(" ><img name=\""); 126 str.append(sImgID); 127 str.append("\" alt=\""); 128 str.append(alt); 129 str.append("\"\n"); 130 str.append(" SRC=\""); 131 str.append(bImageOff); 132 str.append("\" border=\"0\"></a>"); 133 if (debug) { 138 str.append("<!-- End 'jahiaButton' taglib ===== -->"); 139 } 140 out.print(str.toString()); 141 } catch (IOException ioe) { 142 JahiaConsole.println("JahiaButton.doStartTag", ioe.toString()); 143 } 144 return SKIP_BODY; 145 } 146 147 156 private final String getServerHttpPath (ParamBean jParams) 157 { 158 return jParams.getRequest().getContextPath(); 159 } 160 161 public int doEndTag() throws JspException { 162 img = ""; 165 href = ""; 166 alt = ""; 167 onclick = null; 168 altKey = null; 169 altBundle = null; 170 return EVAL_PAGE; 171 } 172 173 private String img = ""; 175 private String href = ""; 176 private String alt = ""; 177 private String onclick = null; 178 179 private String altKey = null; 180 private String altBundle = null; 181 182 private static long imgID = 0; 184 private boolean debug = true; 185 186 187 } 188 | Popular Tags |