View Javadoc

1   package org.gnomekr.potron.web.tag;
2   
3   import javax.servlet.http.HttpServletRequest;
4   import javax.servlet.jsp.JspException;
5   import javax.servlet.jsp.tagext.TagSupport;
6   
7   import org.apache.commons.logging.Log;
8   import org.apache.commons.logging.LogFactory;
9   
10  /***
11   * RollOverImageTag.java
12   * @author Xavier Cho
13   * @version $Revision 1.1 $ $Date: 2005/07/07 15:20:14 $
14   * @jsp:tag
15   *      name="rollover"
16   *      body-content="empty"
17   */
18  public class RollOverImageTag extends TagSupport {
19  
20      private static final long serialVersionUID = 3906931157894314038L;
21  
22      private String id;
23      private String src;
24      private String srcOver;
25      private String align;
26      private String width;
27      private String height;
28      private String styleClass;
29      private String style;
30      private String alt;
31  
32      /***
33       * @return
34       * @jsp.attribute
35       *      required = "false"
36       *      rtexprvalue = "true"
37       */
38      public String getAlign() {
39          return align;
40      }
41  
42      /***
43       * @return
44       * @jsp.attribute
45       *      required = "false"
46       *      rtexprvalue = "true"
47       */
48      public String getAlt() {
49          return alt;
50      }
51  
52      /***
53       * @return
54       * @jsp.attribute
55       *      required = "false"
56       *      rtexprvalue = "true"
57       */
58      public String getHeight() {
59          return height;
60      }
61  
62      /***
63       * @return
64       * @jsp.attribute
65       *      required = "true"
66       *      rtexprvalue = "true"
67       */
68      public String getId() {
69          return id;
70      }
71  
72      /***
73       * @return
74       * @jsp.attribute
75       *      required = "true"
76       *      rtexprvalue = "true"
77       */
78      public String getSrc() {
79          return src;
80      }
81  
82      /***
83       * @return
84       * @jsp.attribute
85       *      required = "true"
86       *      rtexprvalue = "true"
87       */
88      public String getSrcOver() {
89          return srcOver;
90      }
91  
92      /***
93       * @return
94       * @jsp.attribute
95       *      required = "false"
96       *      rtexprvalue = "true"
97       */
98      public String getStyle() {
99          return style;
100     }
101 
102     /***
103      * @return
104      * @jsp.attribute
105      *      required = "false"
106      *      rtexprvalue = "true"
107      */
108     public String getStyleClass() {
109         return styleClass;
110     }
111 
112     /***
113      * @return
114      * @jsp.attribute
115      *      required = "false"
116      *      rtexprvalue = "true"
117      */
118     public String getWidth() {
119         return width;
120     }
121 
122     /***
123      * @param string
124      */
125     public void setAlign(final String string) {
126         align = string;
127     }
128 
129     /***
130      * @param string
131      */
132     public void setAlt(final String string) {
133         alt = string;
134     }
135 
136     /***
137      * @param string
138      */
139     public void setHeight(final String string) {
140         height = string;
141     }
142 
143     /***
144      * @param string
145      */
146     public void setId(final String string) {
147         id = string;
148     }
149 
150     /***
151      * @param string
152      */
153     public void setSrc(final String string) {
154         src = string;
155     }
156 
157     /***
158      * @param string
159      */
160     public void setSrcOver(final String string) {
161         srcOver = string;
162     }
163 
164     /***
165      * @param string
166      */
167     public void setStyle(final String string) {
168         style = string;
169     }
170 
171     /***
172      * @param string
173      */
174     public void setStyleClass(final String string) {
175         styleClass = string;
176     }
177 
178     /***
179      * @param string
180      */
181     public void setWidth(final String string) {
182         width = string;
183     }
184 
185     /***
186      * @see javax.servlet.jsp.tagext.Tag#doStartTag()
187      */
188     public int doStartTag() throws JspException {
189         HttpServletRequest request = (HttpServletRequest) pageContext
190                 .getRequest();
191 
192         String contextPath = request.getContextPath();
193 
194         try {
195             StringBuffer buffer = new StringBuffer();
196             buffer.append("<script language=\"javascript\" ");
197             buffer.append("type=\"text/javascript\">");
198             buffer.append("MM_preloadImages('");
199             buffer.append(contextPath);
200             buffer.append(srcOver);
201             buffer.append("');</script>");
202 
203             buffer.append("<img src=\"");
204             buffer.append(contextPath);
205             buffer.append(src);
206             buffer.append("\"");
207 
208             buffer.append(" id=\"");
209             buffer.append(id);
210             buffer.append("\"");
211 
212             buffer.append(" onmouseover=\"");
213             buffer.append("MM_swapImage('");
214             buffer.append(id);
215             buffer.append("','','");
216             buffer.append(contextPath);
217             buffer.append(srcOver);
218             buffer.append("',1)\"");
219 
220             buffer.append(" onmouseout=\"MM_swapImgRestore()\"");
221 
222             if (align != null) {
223                 buffer.append(" align=\"");
224                 buffer.append(align);
225                 buffer.append("\"");
226             }
227 
228             if (width != null) {
229                 buffer.append(" width=\"");
230                 buffer.append(width);
231                 buffer.append("\"");
232             }
233 
234             if (height != null) {
235                 buffer.append(" height=\"");
236                 buffer.append(height);
237                 buffer.append("\"");
238             }
239 
240             if (styleClass != null) {
241                 buffer.append(" class=\"");
242                 buffer.append(styleClass);
243                 buffer.append("\"");
244             }
245 
246             if (style != null) {
247                 buffer.append(" style=\"");
248                 buffer.append(style);
249                 buffer.append("\"");
250             }
251 
252             if (alt != null) {
253                 buffer.append(" alt=\"");
254                 buffer.append(alt);
255                 buffer.append("\"");
256             }
257 
258             buffer.append("/>");
259 
260             pageContext.getOut().print(buffer.toString());
261         } catch (Exception e) {
262             String msg = "Unable to write tag content : " + e.getMessage();
263 
264             Log log = LogFactory.getLog(getClass());
265             if (log.isErrorEnabled()) {
266                 log.error(msg, e);
267             }
268 
269             throw new JspException(msg);
270         } finally {
271             release();
272         }
273 
274         return SKIP_BODY;
275     }
276 
277     /***
278      * @see javax.servlet.jsp.tagext.Tag#release()
279      */
280     public void release() {
281         this.id = null;
282         this.src = null;
283         this.srcOver = null;
284         this.align = null;
285         this.width = null;
286         this.height = null;
287         this.style = null;
288         this.styleClass = null;
289         this.alt = null;
290     }
291 }