KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sslexplorer > input > tags > ToolTipTag


1 /*
2  * SSL-Explorer
3  *
4  * Copyright (C) 2003-2006 3SP LTD. All Rights Reserved
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2 of
9  * the License, or (at your option) any later version.
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public
16  * License along with this program; if not, write to the Free Software
17  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18  */

19             
20 package com.sslexplorer.input.tags;
21
22 import javax.servlet.jsp.JspException JavaDoc;
23 import javax.servlet.jsp.tagext.BodyTagSupport JavaDoc;
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 /**
35  * @author Brett Smith <brett@3sp.com>
36  */

37 public class ToolTipTag extends BodyTagSupport JavaDoc {
38     
39     final static Log log = LogFactory.getLog(ToolTipTag.class);
40     
41     protected String JavaDoc key;
42     protected String JavaDoc bundle;
43     protected String JavaDoc displayText;
44     protected String JavaDoc property;
45     protected String JavaDoc scope;
46     protected String JavaDoc name;
47     protected String JavaDoc toolTipText;
48     protected String JavaDoc width;
49     protected String JavaDoc textAlign;
50     protected String JavaDoc value;
51     protected String JavaDoc styleId;
52     protected String JavaDoc href = "javascript:void(0);";
53     protected String JavaDoc target;
54     protected String JavaDoc onclick;
55     protected boolean enabled;
56     protected boolean showToolTip = false;
57     protected String JavaDoc additionalAttributeName;
58     protected String JavaDoc additionalAttributeValue;
59     protected String JavaDoc contentLocation;
60     protected String JavaDoc backgroundColor;
61     protected String JavaDoc shadowWidth;
62     protected String JavaDoc padding;
63     protected String JavaDoc borderWidth;
64
65     protected String JavaDoc localeKey = Globals.LOCALE_KEY;
66
67     public String JavaDoc getLocale() {
68         return (this.localeKey);
69     }
70
71     public void setLocale(String JavaDoc localeKey) {
72         this.localeKey = localeKey;
73     }
74
75     /**
76      * The message resources for this package.
77      */

78     protected static MessageResources messages =
79         MessageResources.getMessageResources(
80             "org.apache.struts.taglib.bean.LocalStrings");
81
82     /**
83      *
84      */

85     public ToolTipTag() {
86         super();
87     }
88     
89     /**
90      * Set the a request location where content may be
91      * dynamically retrieved from
92      *
93      * @param contentLocation location of content
94      */

95     public void setContentLocation(String JavaDoc contentLocation) {
96         this.contentLocation = contentLocation;
97     }
98     
99     /**
100      * @return Returns the bundle.
101      */

102     public String JavaDoc getBundle() {
103         return bundle;
104     }
105     /**
106      * @param bundle The bundle to set.
107      */

108     public void setBundle(String JavaDoc bundle) {
109         this.bundle = bundle;
110     }
111     /**
112      * @return Returns the key.
113      */

114     public String JavaDoc getKey() {
115         return key;
116     }
117     /**
118      * @param key The key to set.
119      */

120     public void setKey(String JavaDoc key) {
121         this.key = key;
122     }
123
124     /* (non-Javadoc)
125      * @see javax.servlet.jsp.tagext.Tag#doStartTag()
126      */

127     public int doStartTag() throws JspException JavaDoc {
128         enabled = CoreUtil.getToolTipsEnabled(pageContext.getSession());
129        
130         displayText = null;
131         if(value == null) {
132
133             if (key == null && name != null) {
134                 // Look up the requested property value
135
Object JavaDoc value = TagUtils.getInstance().lookup(pageContext, name, property, scope);
136                 if (value != null && !(value instanceof String JavaDoc)) {
137                     JspException JavaDoc e =
138                         new JspException JavaDoc(messages.getMessage("message.property", key));
139                    TagUtils.getInstance().saveException(pageContext, e);
140                     throw e;
141                 }
142                 displayText = (String JavaDoc) value;
143             }
144     
145             // Retrieve the message string we are looking for
146
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             // Content location
159
if(contentLocation != null) {
160                 displayText = "";
161             }
162         }
163         else {
164             displayText = value;
165         }
166         
167         return EVAL_BODY_BUFFERED;
168     }
169
170     /**
171      * Save the associated label from the body content (if any).
172      * @exception JspException if a JSP exception has occurred
173      */

174     public int doAfterBody() throws JspException JavaDoc {
175
176         if (bodyContent != null) {
177             String JavaDoc 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 JavaDoc {
192
193         StringBuffer JavaDoc results = new StringBuffer JavaDoc();
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 // results.append("return escape(");
230
// if(contentLocation != null) {
231
// results.append("loadXMLDoc('");
232
// results.append(Util.escapeForJavascriptString(contentLocation));
233
// results.append("')");
234
// }
235
// else {
236
// results.append("'");
237
// results.append(Util.escapeForJavascriptString(displayText));
238
// results.append("'");
239
// }
240
// results.append(");\" ");
241

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         // Render this element to our writer
277
TagUtils.getInstance().write(pageContext, results.toString());
278
279         // Evaluate the remainder of this page
280
return (EVAL_PAGE);
281     }
282
283     public String JavaDoc getName() {
284         return (this.name);
285     }
286
287     public void setName(String JavaDoc name) {
288         this.name = name;
289     }
290
291
292     public String JavaDoc getProperty() {
293         return (this.property);
294     }
295
296     public void setProperty(String JavaDoc property) {
297         this.property = property;
298     }
299
300     public String JavaDoc getScope() {
301         return (this.scope);
302     }
303
304     public void setScope(String JavaDoc scope) {
305         this.scope = scope;
306     }
307     
308     public void setValue(String JavaDoc value) {
309         this.value = value;
310     }
311     
312     public void setStyleId(String JavaDoc styleId) {
313         this.styleId = styleId;
314     }
315     
316     public String JavaDoc getStyleId() {
317         return styleId;
318     }
319     
320     public void setHref(String JavaDoc href) {
321         this.href = href;
322     }
323     
324     public String JavaDoc getHref() {
325         return href;
326     }
327
328     /* (non-Javadoc)
329      * @see javax.servlet.jsp.tagext.BodyTagSupport#release()
330      */

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 JavaDoc width) {
357         this.width = width;
358     }
359     
360     public void setTextAlign(String JavaDoc textAlign) {
361         this.textAlign = textAlign;
362     }
363
364     public void setText(String JavaDoc text) {
365         this.toolTipText = text;
366     }
367
368     public String JavaDoc getOnclick() {
369         return onclick;
370     }
371
372     public void setOnclick(String JavaDoc onclick) {
373         this.onclick = onclick;
374     }
375
376     public String JavaDoc getTarget() {
377         return target;
378     }
379
380     public void setTarget(String JavaDoc 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 JavaDoc additionalAttributeName) {
393         this.additionalAttributeName = additionalAttributeName;
394     }
395
396     public void setAdditionalAttributeValue(String JavaDoc additionalAttributeValue) {
397         this.additionalAttributeValue = additionalAttributeValue;
398     }
399
400     public String JavaDoc getBackgroundColor() {
401         return backgroundColor;
402     }
403
404     public void setBackgroundColor(String JavaDoc backgroundColor) {
405         this.backgroundColor = backgroundColor;
406     }
407
408     public String JavaDoc getBorderWidth() {
409         return borderWidth;
410     }
411
412     public void setBorderWidth(String JavaDoc borderWidth) {
413         this.borderWidth = borderWidth;
414     }
415
416     public String JavaDoc getPadding() {
417         return padding;
418     }
419
420     public void setPadding(String JavaDoc padding) {
421         this.padding = padding;
422     }
423
424     public String JavaDoc getShadowWidth() {
425         return shadowWidth;
426     }
427
428     public void setShadowWidth(String JavaDoc shadowWidth) {
429         this.shadowWidth = shadowWidth;
430     }
431 }
432
Popular Tags