KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > jcorporate > expresso > ext > struts > taglib > html > ExLayerTag


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.struts.taglib.html;
66
67 /*
68  * ExLayerTag.java
69  *
70  * Copyright 2002, 2002 Yves Henri AMAIZO.
71  * amy_amaizo@compuserve.com
72  */

73
74 import com.jcorporate.expresso.core.misc.StringUtil;
75 import org.apache.struts.taglib.html.BaseFieldTag;
76 import org.apache.struts.util.ResponseUtils;
77
78 import javax.servlet.jsp.JspException JavaDoc;
79
80 /**
81  *
82  * Sample:
83  * <code>
84  * <%@taglib uri="/WEB-INF/tld/expresso.tld" prefix="expresso"%>
85  * <%@taglib uri="/WEB-INF/tld/expresso-html.tld" prefix="html"%>
86  * <html:html locale="true">
87  * <head>
88  * <TITLE>Sample TagLib Layer</TITLE>
89  * </head>
90  * <body>
91  * <html:form action="/expresso/Test.do">
92  * <table border="0" bgcolor="red">
93  * <tr>
94  * <TD width="10">Titre1</TD>
95  * <TD align="left" width="10"><html:radioLayer property="toto" id="titi" action="show" value="Yes"/>Yes</TD>
96  * <TD width="100%"align="left"><html:radioLayer property="toto" id="titi" action="hide" value="No"/>No</TD>
97  * </tr>
98  * <TR height="1">
99  * <TD colspan="3" height="1">
100  * <html:layer id="titi" state="hide">
101  * <table border="0" bgcolor="GREEN">
102  * <tr>
103  * <TD bgcolor="WHITE">Titre2</TD>
104  * <TD bgcolor="WHITE"><html:radioLayer property="toto" id="titi2" action="show" value="Yes"/>Yes</TD>
105  * <TD bgcolor="WHITE"><html:radioLayer property="toto" id="titi2" action="hide" value="No"/>No</TD>
106  * </tr>
107  * <tr height="1" bgcolor="WHITE">
108  * <TD height="1" colspan="3" bgcolor="WHITE"><html:layer id="titi2" state="hide"><expresso:InputTag name="toto"/></html:layer></TD>
109  * </tr>
110  * </table>
111  * </html:layer>
112  * </TD>
113  * </tr>
114  * </table>
115  * </html:form>
116  * </body>
117  * </html:html>
118  * </code>
119  *
120  */

121
122 /**
123  * Tag for input fields of type "Layer".
124  *
125  * @author Yves Henri AMAIZO
126  */

127 public class ExLayerTag extends BaseFieldTag {
128
129     private String JavaDoc id = "";
130
131     private String JavaDoc state = "SHOW";
132
133     private String JavaDoc tag = "SPAN";
134
135
136     private static String JavaDoc SPAN = "SPAN";
137     private static String JavaDoc DIV = "DIV";
138     private static String JavaDoc FONT = "FONT";
139
140     protected static String JavaDoc SHOW = "block";
141     protected static String JavaDoc HIDE = "none";
142
143     /**
144      * Constructor for LayerTag
145      */

146     public ExLayerTag() {
147         super();
148     }
149
150     public int doStartTag() throws JspException JavaDoc {
151
152         StringBuffer JavaDoc results = new StringBuffer JavaDoc();
153         results.append("<");
154         results.append(tag);
155         results.append(" id=\"");
156         results.append(id);
157         results.append("\"");
158         results.append(prepareEventHandlers());
159         String JavaDoc style = StringUtil.notNull(getStyle());
160         setStyle("display:" + state + ";" + style);
161         results.append(prepareStyles());
162         results.append(">");
163         ResponseUtils.write(pageContext, results.toString());
164         //return EVAL_BODY_TAG;
165
return EVAL_BODY_BUFFERED;
166     }
167
168
169     public int doEndTag() throws JspException JavaDoc {
170         StringBuffer JavaDoc results = new StringBuffer JavaDoc();
171         results.append(getBodyContent().getString());
172         results.append("</");
173         results.append(tag);
174         results.append(">");
175         ResponseUtils.write(pageContext, results.toString());
176         return EVAL_PAGE;
177     }
178
179     /**
180      * Gets the id
181      *
182      * @return Returns a String
183      */

184     public String JavaDoc getId() {
185         return id;
186     }
187
188     /**
189      * Sets the id
190      *
191      * @param id The id to set
192      */

193     public void setId(String JavaDoc id) {
194         this.id = id;
195     }
196
197     /**
198      * Gets the display
199      *
200      * @return Returns a String
201      */

202     public String JavaDoc getState() {
203         return state;
204     }
205
206     /**
207      * Sets the display
208      *
209      * @param state The display to set
210      * @throws JspException for invalid parameters
211      */

212     public void setState(String JavaDoc state) throws JspException JavaDoc {
213         if (state.equalsIgnoreCase("SHOW")) {
214             this.state = SHOW;
215         } else {
216             if (state.equalsIgnoreCase("HIDE")) {
217                 this.state = HIDE;
218             } else {
219                 throw new JspException JavaDoc("state must be hide or show");
220             }
221         }
222     }
223
224     /**
225      * Gets the tag
226      *
227      * @return Returns a String
228      */

229     public String JavaDoc getTag() {
230         return tag;
231     }
232
233     /**
234      * Sets the tag
235      *
236      * @param tag The tag to set
237      * @throws JspException for invalid parameters
238      */

239     public void setTag(String JavaDoc tag) throws JspException JavaDoc {
240         if (tag.equalsIgnoreCase(SPAN)) {
241             this.tag = SPAN;
242         } else {
243             if (tag.equalsIgnoreCase(DIV)) {
244                 this.tag = DIV;
245             } else {
246                 if (tag.equalsIgnoreCase(FONT)) {
247                     this.tag = FONT;
248                 } else {
249                     throw new JspException JavaDoc("tag must be 'span' 'div' or 'font'");
250                 }
251             }
252         }
253     }
254
255
256 }
257
258
Popular Tags