1 18 19 20 package org.apache.struts.taglib.html; 21 22 23 import javax.servlet.http.HttpServletRequest ; 24 import javax.servlet.http.HttpServletResponse ; 25 import javax.servlet.jsp.JspException ; 26 27 import org.apache.struts.Globals; 28 import org.apache.struts.config.ModuleConfig; 29 import org.apache.struts.taglib.TagUtils; 30 31 32 37 38 public class ImageTag extends SubmitTag { 39 40 41 43 44 47 protected String align = null; 48 49 52 public String getAlign() { 53 return (this.align); 54 } 55 56 59 public void setAlign(String align) { 60 this.align = align; 61 } 62 63 64 67 protected String border = null; 68 69 public String getBorder() { 70 return (this.border); 71 } 72 73 public void setBorder(String border) { 74 this.border = border; 75 } 76 77 78 81 protected String page = null; 82 83 public String getPage() { 84 return (this.page); 85 } 86 87 public void setPage(String page) { 88 this.page = page; 89 } 90 91 92 95 protected String pageKey = null; 96 97 public String getPageKey() { 98 return (this.pageKey); 99 } 100 101 public void setPageKey(String pageKey) { 102 this.pageKey = pageKey; 103 } 104 105 108 protected String src = null; 109 110 public String getSrc() { 111 return (this.src); 112 } 113 114 public void setSrc(String src) { 115 this.src = src; 116 } 117 118 119 122 protected String srcKey = null; 123 124 public String getSrcKey() { 125 return (this.srcKey); 126 } 127 128 public void setSrcKey(String srcKey) { 129 this.srcKey = srcKey; 130 } 131 132 133 135 public ImageTag() { 136 super(); 137 property = ""; 138 } 139 140 142 147 protected String getElementOpen() { 148 return "<input type=\"image\""; 149 } 150 151 155 protected void prepareButtonAttributes(StringBuffer results) 156 throws JspException { 157 String tmp = src(); 158 if (tmp != null) { 159 HttpServletResponse response = 160 (HttpServletResponse ) pageContext.getResponse(); 161 prepareAttribute(results, "src", response.encodeURL(tmp)); 162 } 163 prepareAttribute(results, "align", getAlign()); 164 prepareAttribute(results, "border", getBorder()); 165 prepareAttribute(results, "value", getValue()); 166 prepareAttribute(results, "accesskey", getAccesskey()); 167 prepareAttribute(results, "tabindex", getTabindex()); 168 } 169 170 171 174 public void release() { 175 176 super.release(); 177 page = null; 178 pageKey = null; 179 property = ""; 180 src = null; 181 srcKey = null; 182 183 } 184 185 186 188 189 196 protected String src() throws JspException { 197 198 if (this.page != null) { 200 if ((this.src != null) || (this.srcKey != null) || 201 (this.pageKey != null)) { 202 JspException e = new JspException 203 (messages.getMessage("imgTag.src")); 204 TagUtils.getInstance().saveException(pageContext, e); 205 throw e; 206 } 207 208 ModuleConfig config = (ModuleConfig) 209 pageContext.getRequest().getAttribute(Globals.MODULE_KEY); 210 211 HttpServletRequest request = 212 (HttpServletRequest ) pageContext.getRequest(); 213 214 String pageValue = this.page; 215 if (config != null) { 216 pageValue = TagUtils.getInstance().pageURL(request, 217 this.page, 218 config); 219 } 220 return (request.getContextPath() + pageValue); 221 } 222 223 if (this.pageKey != null) { 225 if ((this.src != null) || (this.srcKey != null)) { 226 JspException e = new JspException 227 (messages.getMessage("imgTag.src")); 228 TagUtils.getInstance().saveException(pageContext, e); 229 throw e; 230 } 231 232 ModuleConfig config = (ModuleConfig) 233 pageContext.getRequest().getAttribute(Globals.MODULE_KEY); 234 235 HttpServletRequest request = 236 (HttpServletRequest ) pageContext.getRequest(); 237 238 String pageValue = TagUtils.getInstance().message( 239 pageContext, 240 getBundle(), 241 getLocale(), 242 this.pageKey); 243 if (config != null) { 244 pageValue = TagUtils.getInstance().pageURL(request, 245 pageValue, 246 config); 247 } 248 return (request.getContextPath() + pageValue); 249 } 250 251 if (this.src != null) { 253 if (this.srcKey != null) { 254 JspException e = new JspException 255 (messages.getMessage("imgTag.src")); 256 TagUtils.getInstance().saveException(pageContext, e); 257 throw e; 258 } 259 return (this.src); 260 } 261 262 if (this.srcKey == null) { 264 JspException e = new JspException 265 (messages.getMessage("imgTag.src")); 266 TagUtils.getInstance().saveException(pageContext, e); 267 throw e; 268 } 269 270 return TagUtils.getInstance().message( 271 pageContext, 272 getBundle(), 273 getLocale(), 274 this.srcKey); 275 276 } 277 278 279 } 280 | Popular Tags |