KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jahia > deprecated > taglibs > button > AbstractRolloverTag


1 package org.jahia.deprecated.taglibs.button;
2
3 import javax.servlet.http.HttpServletRequest JavaDoc;
4
5 import org.jahia.data.JahiaData;
6 import org.jahia.deprecated.taglibs.util.Utils;
7 import org.jahia.exceptions.JahiaException;
8 import org.jahia.utils.JahiaConsole;
9
10
11 /**
12  * Class AbstracRolloverTag : defines common code for different rollovers tags
13  *
14  * @author Jerome Tamiotti
15  */

16 public abstract class AbstractRolloverTag extends AbstractButtonTag {
17
18
19     // counter to handle multiple tag occurrences
20
private Integer JavaDoc counter;
21
22     // the short class name of the tag
23
private String JavaDoc className;
24
25     // use a counter to identify images in the HTML page
26
// in case of several tags
27
public void checkCounter(HttpServletRequest JavaDoc request) {
28
29         // init class name
30
this.className = Utils.getShortClassName(this.getClass());
31         // increments the counter or initialize it
32
String JavaDoc counterName = this.className + "_counter";
33         this.counter = (Integer JavaDoc)request.getAttribute(counterName);
34         if (this.counter == null) {
35             this.counter = new Integer JavaDoc(1);
36         } else {
37             this.counter = new Integer JavaDoc(this.counter.intValue() + 1);
38         }
39         request.setAttribute(counterName, this.counter);
40     }
41
42
43     // build the string drawing the rollover button
44
public String JavaDoc buildButton (JahiaData jData, HttpServletRequest JavaDoc request) {
45
46         // get data in subclasses
47
String JavaDoc imgDir = getImgDir();
48         String JavaDoc width = getWidth();
49         String JavaDoc height = getHeight();
50         String JavaDoc align = getAlign();
51         String JavaDoc imgName = this.className + "Img_";
52         String JavaDoc context = jData.gui().drawHttpJspContext(request);
53         String JavaDoc outImage = null;
54         String JavaDoc overImage = null;
55         String JavaDoc launcher = null;
56         try {
57             outImage = getMouseOutImage(jData);
58             overImage = getMouseOverImage(jData);
59             launcher = getLauncher(jData);
60         } catch (JahiaException jex) {
61             JahiaConsole.println("AbstractRolloverTag: buildButton ", "Can not get launcher from subclass !");
62             return null;
63         }
64         StringBuffer JavaDoc text = new StringBuffer JavaDoc( "<a HREF=\"" );
65         text.append( launcher );
66         text.append( "\" onMouseOut=\"document." );
67         text.append( imgName );
68         text.append( this.counter );
69         text.append( ".src='" );
70         text.append( context );
71         text.append( "/" );
72         text.append( imgDir );
73         text.append( "/" );
74         text.append( outImage );
75         text.append( "';\" onMouseOver=\"document." );
76         text.append( imgName );
77         text.append( this.counter );
78         text.append( ".src='" );
79         text.append( context );
80         text.append( "/" );
81         text.append( imgDir );
82         text.append( "/" );
83         text.append( overImage );
84         text.append( "';\"><img name=\"" );
85         text.append( imgName );
86         text.append( this.counter.intValue() );
87         text.append( "\" SRC=\"" );
88         text.append( context );
89         text.append( "/" );
90         text.append( imgDir );
91         text.append( "/" );
92         text.append( outImage );
93         text.append( "\"" );
94         if ( !width.equals("" ) ) {
95             text.append( " width=\"" );
96             text.append( width );
97             text.append( "\"" );
98         }
99         if ( !height.equals("") ) {
100             text.append( " height=\"" );
101             text.append( height );
102             text.append( "\"" );
103         }
104         if ( !align.equals("") ) {
105             text.append( " align=\"" );
106             text.append( align );
107             text.append( "\"" );
108         }
109
110         text.append( " border=\"0\" alt=\"\">" );
111         text.append( getTitle() );
112         text.append( "</a>" );
113         return text.toString();
114     }
115
116     public String JavaDoc getTitle() {
117         return "";
118     }
119
120     public String JavaDoc getStyle() {
121         return "";
122     }
123
124     public String JavaDoc getAlign(){
125         return "";
126     };
127
128     // The following methods will be implemented in the concrete rollover tags
129
public abstract String JavaDoc getMouseOverImage(JahiaData jData) throws JahiaException;
130
131     public abstract String JavaDoc getMouseOutImage(JahiaData jData) throws JahiaException;
132
133     public abstract String JavaDoc getImgDir();
134
135     public abstract String JavaDoc getWidth();
136
137     public abstract String JavaDoc getHeight();
138     public String JavaDoc getClassName() {
139         return className;
140     }
141     public Integer JavaDoc getCounter() {
142         return counter;
143     }
144
145 }
146
147
148
Popular Tags