1 19 20 package com.sslexplorer.input.tags; 21 22 import javax.servlet.jsp.JspException ; 23 import javax.servlet.jsp.tagext.BodyTagSupport ; 24 25 import org.apache.commons.logging.Log; 26 import org.apache.commons.logging.LogFactory; 27 import org.apache.struts.Globals; 28 import org.apache.struts.taglib.TagUtils; 29 import org.apache.struts.util.MessageResources; 30 31 import com.sslexplorer.boot.Util; 32 import com.sslexplorer.core.CoreUtil; 33 34 37 public class ToolTipTag extends BodyTagSupport { 38 39 final static Log log = LogFactory.getLog(ToolTipTag.class); 40 41 protected String key; 42 protected String bundle; 43 protected String displayText; 44 protected String property; 45 protected String scope; 46 protected String name; 47 protected String toolTipText; 48 protected String width; 49 protected String textAlign; 50 protected String value; 51 protected String styleId; 52 protected String href = "javascript:void(0);"; 53 protected String target; 54 protected String onclick; 55 protected boolean enabled; 56 protected boolean showToolTip = false; 57 protected String additionalAttributeName; 58 protected String additionalAttributeValue; 59 protected String contentLocation; 60 protected String backgroundColor; 61 protected String shadowWidth; 62 protected String padding; 63 protected String borderWidth; 64 65 protected String localeKey = Globals.LOCALE_KEY; 66 67 public String getLocale() { 68 return (this.localeKey); 69 } 70 71 public void setLocale(String localeKey) { 72 this.localeKey = localeKey; 73 } 74 75 78 protected static MessageResources messages = 79 MessageResources.getMessageResources( 80 "org.apache.struts.taglib.bean.LocalStrings"); 81 82 85 public ToolTipTag() { 86 super(); 87 } 88 89 95 public void setContentLocation(String contentLocation) { 96 this.contentLocation = contentLocation; 97 } 98 99 102 public String getBundle() { 103 return bundle; 104 } 105 108 public void setBundle(String bundle) { 109 this.bundle = bundle; 110 } 111 114 public String getKey() { 115 return key; 116 } 117 120 public void setKey(String key) { 121 this.key = key; 122 } 123 124 127 public int doStartTag() throws JspException { 128 enabled = CoreUtil.getToolTipsEnabled(pageContext.getSession()); 129 130 displayText = null; 131 if(value == null) { 132 133 if (key == null && name != null) { 134 Object value = TagUtils.getInstance().lookup(pageContext, name, property, scope); 136 if (value != null && !(value instanceof String )) { 137 JspException e = 138 new JspException (messages.getMessage("message.property", key)); 139 TagUtils.getInstance().saveException(pageContext, e); 140 throw e; 141 } 142 displayText = (String ) value; 143 } 144 145 if(displayText == null && key != null) { 147 displayText = 148 TagUtils.getInstance().message( 149 pageContext, 150 this.bundle, 151 this.localeKey, 152 key); 153 if(displayText == null) { 154 log.error("Missing message for key "+ key + " bundle = " + bundle); 155 } 156 } 157 158 if(contentLocation != null) { 160 displayText = ""; 161 } 162 } 163 else { 164 displayText = value; 165 } 166 167 return EVAL_BODY_BUFFERED; 168 } 169 170 174 public int doAfterBody() throws JspException { 175 176 if (bodyContent != null) { 177 String value = bodyContent.getString().trim(); 178 if (value.length() > 0) { 179 if(displayText == null) { 180 displayText = value; 181 } 182 else { 183 toolTipText = value; 184 } 185 } 186 } 187 return (SKIP_BODY); 188 189 } 190 191 public int doEndTag() throws JspException { 192 193 StringBuffer results = new StringBuffer (); 194 if(displayText != null) { 195 results.append("<a "); 196 if(enabled && !showToolTip) { 197 results.append("onmouseover=\""); 198 if(backgroundColor != null) { 199 results.append("this.T_BGCOLOR='"); 200 results.append(backgroundColor); 201 results.append("';"); 202 } 203 if(padding != null) { 204 results.append("this.T_PADDING="); 205 results.append(padding); 206 results.append(";"); 207 } 208 if(shadowWidth != null) { 209 results.append("this.T_SHADOWWIDTH="); 210 results.append(shadowWidth); 211 results.append(";"); 212 } 213 if(borderWidth != null) { 214 results.append("this.T_BORDERWIDTH="); 215 results.append(borderWidth); 216 results.append(";"); 217 } 218 if(width != null) { 219 results.append("this.T_WIDTH="); 220 results.append(width); 221 results.append(";"); 222 } 223 if(textAlign != null) { 224 results.append("this.T_TEXTALIGN='"); 225 results.append(textAlign); 226 results.append("';"); 227 } 228 229 242 243 if(contentLocation != null) { 244 results.append("return escape('"); 245 results.append("!" + Util.escapeForJavascriptString(contentLocation)); 246 results.append("');\" "); 247 } 248 else { 249 results.append("return escape("); 250 results.append("'"); 251 results.append(Util.escapeForJavascriptString(displayText)); 252 results.append("'"); 253 results.append(");\" "); 254 } 255 } 256 if(styleId != null) { 257 results.append("class=\"" + styleId + "\" "); 258 } 259 if (target != null){ 260 results.append("target=\"" + target + "\" "); 261 } 262 results.append("href=\"" + href + "\""); 263 if (onclick != null) 264 results.append(" onclick=\"" + onclick + "\""); 265 if(additionalAttributeName != null && !"".equals(additionalAttributeName)) 266 results.append(" " + additionalAttributeName + "=\"" + additionalAttributeValue + "\""); 267 268 results.append(">"); 269 } 270 if(toolTipText != null) { 271 results.append(toolTipText); 272 } 273 if(displayText != null) { 274 results.append("</a>"); 275 } 276 TagUtils.getInstance().write(pageContext, results.toString()); 278 279 return (EVAL_PAGE); 281 } 282 283 public String getName() { 284 return (this.name); 285 } 286 287 public void setName(String name) { 288 this.name = name; 289 } 290 291 292 public String getProperty() { 293 return (this.property); 294 } 295 296 public void setProperty(String property) { 297 this.property = property; 298 } 299 300 public String getScope() { 301 return (this.scope); 302 } 303 304 public void setScope(String scope) { 305 this.scope = scope; 306 } 307 308 public void setValue(String value) { 309 this.value = value; 310 } 311 312 public void setStyleId(String styleId) { 313 this.styleId = styleId; 314 } 315 316 public String getStyleId() { 317 return styleId; 318 } 319 320 public void setHref(String href) { 321 this.href = href; 322 } 323 324 public String getHref() { 325 return href; 326 } 327 328 331 public void release() { 332 super.release(); 333 key = null; 334 bundle = null; 335 displayText = null; 336 property = null; 337 scope = null; 338 name = null; 339 toolTipText = null; 340 width = null; 341 textAlign = null; 342 value = null; 343 styleId = null; 344 onclick = null; 345 href = "javascript:void(0);"; 346 target = null; 347 additionalAttributeName = ""; 348 additionalAttributeValue = ""; 349 padding = null; 350 shadowWidth = null; 351 borderWidth = null; 352 backgroundColor = null; 353 354 } 355 356 public void setWidth(String width) { 357 this.width = width; 358 } 359 360 public void setTextAlign(String textAlign) { 361 this.textAlign = textAlign; 362 } 363 364 public void setText(String text) { 365 this.toolTipText = text; 366 } 367 368 public String getOnclick() { 369 return onclick; 370 } 371 372 public void setOnclick(String onclick) { 373 this.onclick = onclick; 374 } 375 376 public String getTarget() { 377 return target; 378 } 379 380 public void setTarget(String target) { 381 this.target = target; 382 } 383 384 public boolean isShowToolTip() { 385 return showToolTip; 386 } 387 388 public void setShowToolTip(boolean showToolTip) { 389 this.showToolTip = showToolTip; 390 } 391 392 public void setAdditionalAttributeName(String additionalAttributeName) { 393 this.additionalAttributeName = additionalAttributeName; 394 } 395 396 public void setAdditionalAttributeValue(String additionalAttributeValue) { 397 this.additionalAttributeValue = additionalAttributeValue; 398 } 399 400 public String getBackgroundColor() { 401 return backgroundColor; 402 } 403 404 public void setBackgroundColor(String backgroundColor) { 405 this.backgroundColor = backgroundColor; 406 } 407 408 public String getBorderWidth() { 409 return borderWidth; 410 } 411 412 public void setBorderWidth(String borderWidth) { 413 this.borderWidth = borderWidth; 414 } 415 416 public String getPadding() { 417 return padding; 418 } 419 420 public void setPadding(String padding) { 421 this.padding = padding; 422 } 423 424 public String getShadowWidth() { 425 return shadowWidth; 426 } 427 428 public void setShadowWidth(String shadowWidth) { 429 this.shadowWidth = shadowWidth; 430 } 431 } 432 | Popular Tags |