KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > jcorporate > expresso > ext > taglib > TransitionTag


1 /* ====================================================================
2  * The Jcorporate Apache Style Software License, Version 1.2 05-07-2002
3  *
4  * Copyright (c) 1995-2002 Jcorporate Ltd. All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  *
10  * 1. Redistributions of source code must retain the above copyright
11  * notice, this list of conditions and the following disclaimer.
12  *
13  * 2. Redistributions in binary form must reproduce the above copyright
14  * notice, this list of conditions and the following disclaimer in
15  * the documentation and/or other materials provided with the
16  * distribution.
17  *
18  * 3. The end-user documentation included with the redistribution,
19  * if any, must include the following acknowledgment:
20  * "This product includes software developed by Jcorporate Ltd.
21  * (http://www.jcorporate.com/)."
22  * Alternately, this acknowledgment may appear in the software itself,
23  * if and wherever such third-party acknowledgments normally appear.
24  *
25  * 4. "Jcorporate" and product names such as "Expresso" must
26  * not be used to endorse or promote products derived from this
27  * software without prior written permission. For written permission,
28  * please contact info@jcorporate.com.
29  *
30  * 5. Products derived from this software may not be called "Expresso",
31  * or other Jcorporate product names; nor may "Expresso" or other
32  * Jcorporate product names appear in their name, without prior
33  * written permission of Jcorporate Ltd.
34  *
35  * 6. No product derived from this software may compete in the same
36  * market space, i.e. framework, without prior written permission
37  * of Jcorporate Ltd. For written permission, please contact
38  * partners@jcorporate.com.
39  *
40  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
41  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
42  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
43  * DISCLAIMED. IN NO EVENT SHALL JCORPORATE LTD OR ITS CONTRIBUTORS
44  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
45  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
46  * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
47  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
48  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
49  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
50  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51  * SUCH DAMAGE.
52  * ====================================================================
53  *
54  * This software consists of voluntary contributions made by many
55  * individuals on behalf of the Jcorporate Ltd. Contributions back
56  * to the project(s) are encouraged when you make modifications.
57  * Please send them to support@jcorporate.com. For more information
58  * on Jcorporate Ltd. and its products, please see
59  * <http://www.jcorporate.com/>.
60  *
61  * Portions of this software are based upon other open source
62  * products and are subject to their respective licenses.
63  */

64
65 package com.jcorporate.expresso.ext.taglib;
66
67 import com.jcorporate.expresso.core.controller.Transition;
68 import com.jcorporate.expresso.core.misc.StringUtil;
69 import com.jcorporate.expresso.kernel.util.FastStringBuffer;
70
71 import javax.servlet.http.HttpServletResponse JavaDoc;
72 import javax.servlet.jsp.JspTagException JavaDoc;
73 import javax.servlet.jsp.JspWriter JavaDoc;
74 import javax.servlet.jsp.tagext.Tag JavaDoc;
75
76 /**
77  * ActionTag.java
78  *
79  * Copyright 2001 Jcorporate Ltd.
80  */

81
82
83 /**
84  * The TransitionTag renders an Expresso Transition item in HTML
85  * as either a submit button or an image button. To render an image
86  * button the SRC and TYPE="IMAGE" attributes must be specified in the tag.
87  *
88  * @author Adam Rossi, Platinum Solutions
89  * @since Expresso 4.0
90  */

91 public class TransitionTag
92         extends ExpressoTagSupport {
93     private Transition oneTransition = null;
94     private java.lang.String JavaDoc name = null;
95     private java.lang.String JavaDoc value = null;
96     private java.lang.String JavaDoc type = null;
97     private java.lang.String JavaDoc src = null;
98     private java.lang.String JavaDoc alt = null;
99     private java.lang.String JavaDoc classValue = null;
100
101     private java.lang.String JavaDoc nameToUse = null;
102     private java.lang.String JavaDoc valueToUse = null;
103     private java.lang.String JavaDoc typeToUse = null;
104     private java.lang.String JavaDoc srcToUse = null;
105     private java.lang.String JavaDoc altToUse = null;
106     private java.lang.String JavaDoc classValueToUse = null;
107
108
109     // Handle JavaScript actions by Jan MOONS
110
private java.lang.String JavaDoc onclick = null;
111
112     /**
113      *
114      */

115     public TransitionTag() {
116         super();
117     } /* TransitionTag() */
118
119     /**
120      * Standard doEndTag.
121      *
122      * @return int
123      */

124     public int doEndTag()
125             throws javax.servlet.jsp.JspTagException JavaDoc {
126         nameToUse = name;
127         valueToUse = value;
128         typeToUse = type;
129         srcToUse = src;
130         altToUse = alt;
131         classValueToUse = classValue;
132
133         getControllerResponse();
134
135         try {
136             Tag JavaDoc container = getContainer();
137
138             if (container == null) {
139                 oneTransition = ctlrResp.getTransition(name);
140             } else {
141                 if (container instanceof ElementIterator) {
142                     oneTransition = (Transition) ((ElementIterator) container).getElement();
143                     nameToUse = oneTransition.getName();
144                 } else if (container instanceof BlockTag) {
145                     oneTransition = (Transition) ((BlockTag) container).getBlock().getContent(getName());
146                 } else {
147                     throw new JspTagException JavaDoc("TransitionTag: cannot handle container tag" +
148                             container.getClass().getName());
149                 }
150             }
151
152             JspWriter JavaDoc writer = pageContext.getOut();
153
154             FastStringBuffer fsb = FastStringBuffer.getInstance();
155             try {
156
157                 if (oneTransition != null) {
158                     if (valueToUse == null || "".equals(valueToUse)) {
159
160                         //we need a value for the botton label. Lets try to get it
161
//from the Transition:
162
valueToUse = oneTransition.getLabel();
163                     }
164                     if (valueToUse == null || "".equals(valueToUse)) {
165
166                         //give it a default value
167
valueToUse = "Click";
168                     }
169
170                     // support SRC attribute from 'daniel.kibler@rhi.com'
171
if ((typeToUse == null) || "".equals(typeToUse)) {
172                         //give it a default value
173
typeToUse = oneTransition.getType();
174                     }
175
176
177                     if ((srcToUse == null) || "".equals(srcToUse)) {
178                         //give it a default value
179
srcToUse = oneTransition.getAttribute("SRC");
180                     }
181                     // end mod by 'daniel.kibler@rhi.com'
182

183                     //Add the hidden form field that contains the encoded button params
184
//Also, add a hidden form field with the "cmd=button" pair.
185
//This does not hurt to duplicate...
186
fsb.append(oneTransition.getHTMLParamString());
187                     if (!StringUtil.notNull(typeToUse).equals("IMAGE")) {
188                         fsb.append("<INPUT TYPE=\"submit\" NAME=\"button_");
189                         fsb.append(oneTransition.getName());
190                         fsb.append("\" VALUE=\"");
191                         fsb.append(valueToUse);
192                         fsb.append("\" CLASS=\"");
193                         fsb.append(classValueToUse);
194                         fsb.append("\" ");
195                         fsb.append(getJavaScript());
196                         fsb.append(">\n");
197                         fsb.append("<INPUT TYPE=\"hidden\" NAME=\"cmd\" VALUE=\"button\" >\n");
198                     } else {
199                         if (StringUtil.notNull(srcToUse).equals("")) {
200                             throw new JspTagException JavaDoc("TransitionTag: " +
201                                     getName() + " of type IMAGE " +
202                                     " requires a SRC attribute.");
203                         }
204
205                         HttpServletResponse JavaDoc response = (HttpServletResponse JavaDoc) pageContext
206                                 .getResponse();
207
208                         if (altToUse == null || "".equals(altToUse)) {
209                             altToUse = oneTransition.getLabel();
210                         }
211
212                         fsb.append("<INPUT TYPE=\"image\" NAME=\"button_");
213                         fsb.append(oneTransition.getName());
214                         fsb.append("\" ");
215                         fsb.append("SRC=\"");
216                         fsb.append(response.encodeURL(srcToUse));
217                         fsb.append("\" ");
218                         fsb.append("ALT=\"");
219                         fsb.append(StringUtil.notNull(altToUse));
220                         fsb.append("\" ");
221                         fsb.append(getJavaScript());
222                         fsb.append(">");
223                     }
224
225                     writer.print(fsb.toString());
226                 } else {
227                     writer.println("The Transition Button Could Not Be Displayed");
228                 }
229             } finally {
230                 fsb.release();
231             }
232         } catch (Exception JavaDoc e) {
233             e.printStackTrace(System.err);
234             throw new JspTagException JavaDoc("TransitionTag: " + e.getMessage());
235         }
236
237         return EVAL_PAGE;
238     } /* doEndTag() */
239
240
241     /**
242      * Do nothing until end tag.
243      *
244      * @return int
245      * @throws javax.servlet.jsp.JspTagException
246      * The exception description.
247      */

248     public int doStartTag()
249             throws javax.servlet.jsp.JspTagException JavaDoc {
250         return SKIP_BODY;
251     } /* doStartTag() */
252
253
254     /**
255      * Return the different JavaScript actions : onclick, e.a.
256      * By Jan MOONS
257      * Used a method so you can add more javascript actions to it if needed.
258      *
259      * @return java.lang.String
260      */

261     protected java.lang.String JavaDoc getJavaScript() {
262 // java.lang.String javaScript = ();
263

264         if (onclick != null) {
265             FastStringBuffer fsb = new FastStringBuffer(64);
266             fsb.append("onclick=\"");
267             fsb.append(onclick);
268             fsb.append("\"");
269 // javaScript += "onclick=\"" + onclick + "\"";
270
return fsb.toString();
271         }
272
273         return "";
274     }
275
276     /**
277      * Getter method for getName().
278      *
279      * @return java.lang.String
280      */

281     public java.lang.String JavaDoc getName() {
282         return nameToUse;
283     } /* getName() */
284
285     /**
286      * Insert the method's description here.
287      * Creation date: (12/29/2000 %r)
288      *
289      * @return java.lang.String
290      */

291     public java.lang.String JavaDoc getValue() {
292         return valueToUse;
293     } /* getValue() */
294
295     /**
296      * Get the class value, used for buttons
297      * Creation date: (07/12/02)
298      *
299      * @return java.lang.String
300      */

301     public java.lang.String JavaDoc getClassValue() {
302         return classValueToUse;
303     } /* getClassValue() */
304
305     /**
306      * Getter method for javascript : onclick
307      * by Jan MOONS
308      *
309      * @return java.lang.String
310      * @since 12/18/2001
311      */

312     public java.lang.String JavaDoc getOnclick() {
313         return onclick;
314     } /* getOnclick() */
315
316     /**
317      * Insert the method's description here.
318      * Creation date: (12/29/2000 %r)
319      *
320      * @param newName java.lang.String
321      */

322     public void setName(java.lang.String JavaDoc newName) {
323         name = newName;
324     } /* setName(java.lang.String) */
325
326     /**
327      * Insert the method's description here.
328      * Creation date: (12/29/2000 %r)
329      *
330      * @param newValue java.lang.String
331      */

332     public void setValue(java.lang.String JavaDoc newValue) {
333         value = newValue;
334     } /* setValue(java.lang.String) */
335
336     /**
337      * Used for setting the class value for buttons
338      * Creation date: (12/29/2000 %r)
339      *
340      * @param newClassValue java.lang.String
341      */

342     public void setClassValue(java.lang.String JavaDoc newClassValue) {
343         classValue = newClassValue;
344     } /* setClassValue(java.lang.String) */
345
346     /**
347      * Setter method for javascript : onlick
348      * by Jan MOONS
349      *
350      * @param newValue java.lang.String
351      * @since 12/18/2001
352      */

353     public void setOnclick(java.lang.String JavaDoc newValue) {
354         onclick = newValue;
355     } /* setOnclick(java.lang.String) */
356
357     /**
358      * Insert the method's description here.
359      * Creation date: (5/1/2002 11:36:00 PM)
360      *
361      * @return java.lang.String
362      */

363     public java.lang.String JavaDoc getAlt() {
364         return altToUse;
365     }
366
367
368     /**
369      * Insert the method's description here.
370      * Creation date: (5/1/2002 10:41:45 PM)
371      *
372      * @return java.lang.String
373      */

374     public java.lang.String JavaDoc getSrc() {
375         return srcToUse;
376     }
377
378
379     /**
380      * Insert the method's description here.
381      * Creation date: (5/1/2002 9:47:28 PM)
382      *
383      * @return java.lang.String
384      */

385     public java.lang.String JavaDoc getType() {
386         return typeToUse;
387     }
388
389
390     /**
391      * Insert the method's description here.
392      * Creation date: (5/1/2002 11:36:00 PM)
393      *
394      * @param newAlt java.lang.String
395      */

396     public void setAlt(java.lang.String JavaDoc newAlt) {
397         alt = newAlt;
398     }
399
400
401     /**
402      * Insert the method's description here.
403      * Creation date: (5/1/2002 10:41:45 PM)
404      *
405      * @param newSrc java.lang.String
406      */

407     public void setSrc(java.lang.String JavaDoc newSrc) {
408         src = newSrc;
409     }
410
411     /**
412      * Insert the method's description here.
413      * Creation date: (5/1/2002 9:47:28 PM)
414      *
415      * @param newType java.lang.String
416      */

417     public void setType(java.lang.String JavaDoc newType) {
418         type = newType;
419     }
420
421 } /* TransitionTag */
422
423 /* TransitionTag */
Popular Tags