KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ajaxtags > tags > AjaxCalloutTag


1 /**
2  * Copyright 2005 Darren L. Spurgeon
3  * Copyright 2007 Jens Kapitza
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

17 package org.ajaxtags.tags;
18
19 import java.io.IOException JavaDoc;
20
21 import javax.servlet.jsp.JspException JavaDoc;
22 import javax.servlet.jsp.JspWriter JavaDoc;
23 import javax.servlet.jsp.tagext.TagSupport JavaDoc;
24
25 import org.apache.commons.lang.StringUtils;
26 import org.apache.taglibs.standard.lang.support.ExpressionEvaluatorManager;
27
28 /**
29  * Tag handler for the callout AJAX tag.
30  *
31  * @author Darren Spurgeon
32  * @version $Revision: 1.4 $ $Date: 2007/07/03 13:56:28 $ $Author: jenskapitza $
33  */

34 public class AjaxCalloutTag extends TagSupport JavaDoc {
35
36     private boolean doPost;
37     
38     private String JavaDoc var;
39
40     private String JavaDoc attachTo;
41
42     private String JavaDoc baseUrl;
43
44     private String JavaDoc source;
45
46     private String JavaDoc sourceClass;
47
48     private String JavaDoc parameters;
49
50     private String JavaDoc title;
51
52     private String JavaDoc overlib;
53
54     private String JavaDoc postFunction;
55
56     private String JavaDoc preFunction;
57
58     private String JavaDoc emptyFunction;
59
60     private String JavaDoc errorFunction;
61
62     private String JavaDoc openEventType;
63
64     private String JavaDoc closeEventType;
65
66     public String JavaDoc getCloseEventType() {
67         return closeEventType;
68     }
69
70     public void setCloseEventType(String JavaDoc closeEvent) {
71         this.closeEventType = closeEvent;
72     }
73
74     public String JavaDoc getOpenEventType() {
75         return openEventType;
76     }
77
78     public void setOpenEventType(String JavaDoc openEvent) {
79         this.openEventType = openEvent;
80     }
81
82     public String JavaDoc getBaseUrl() {
83         return baseUrl;
84     }
85
86     public void setBaseUrl(String JavaDoc baseUrl) {
87         this.baseUrl = baseUrl;
88     }
89
90     public String JavaDoc getEmptyFunction() {
91         return emptyFunction;
92     }
93
94     public void setEmptyFunction(String JavaDoc emptyFunction) {
95         this.emptyFunction = emptyFunction;
96     }
97
98     public String JavaDoc getErrorFunction() {
99         return errorFunction;
100     }
101
102     public void setErrorFunction(String JavaDoc errorFunction) {
103         this.errorFunction = errorFunction;
104     }
105
106     public String JavaDoc getVar() {
107         return var;
108     }
109
110     public void setVar(String JavaDoc var) {
111         this.var = var;
112     }
113
114     public String JavaDoc getAttachTo() {
115         return attachTo;
116     }
117
118     public void setAttachTo(String JavaDoc attachTo) {
119         this.attachTo = attachTo;
120     }
121
122     public String JavaDoc getOverlib() {
123         return overlib;
124     }
125
126     public void setOverlib(String JavaDoc overlib) {
127         this.overlib = overlib;
128     }
129
130     public String JavaDoc getParameters() {
131         return parameters;
132     }
133
134     public void setParameters(String JavaDoc parameters) {
135         this.parameters = parameters;
136     }
137
138     public String JavaDoc getPreFunction() {
139         return preFunction;
140     }
141
142     public void setPreFunction(String JavaDoc preFunction) {
143         this.preFunction = preFunction;
144     }
145
146     public String JavaDoc getPostFunction() {
147         return postFunction;
148     }
149
150     public void setPostFunction(String JavaDoc postFunction) {
151         this.postFunction = postFunction;
152     }
153
154     public String JavaDoc getSource() {
155         return source;
156     }
157
158     public void setSource(String JavaDoc source) {
159         this.source = source;
160     }
161
162     public String JavaDoc getSourceClass() {
163         return sourceClass;
164     }
165
166     public void setSourceClass(String JavaDoc sourceClass) {
167         this.sourceClass = sourceClass;
168     }
169
170     public String JavaDoc getTitle() {
171         return title;
172     }
173
174     public void setTitle(String JavaDoc title) {
175         this.title = title;
176     }
177
178     @Override JavaDoc
179     public int doStartTag() throws JspException JavaDoc {
180         // Required Properties
181
this.baseUrl = (String JavaDoc) ExpressionEvaluatorManager.evaluate("baseUrl",
182                 this.baseUrl, String JavaDoc.class, this, super.pageContext);
183         this.parameters = (String JavaDoc) ExpressionEvaluatorManager.evaluate(
184                 "parameters", this.parameters, String JavaDoc.class, this,
185                 super.pageContext);
186         if (this.title != null) {
187             this.title = (String JavaDoc) ExpressionEvaluatorManager.evaluate("title",
188                     this.title, String JavaDoc.class, this, super.pageContext);
189         }
190
191         // Optional Properties
192
if (this.var != null) {
193             this.var = (String JavaDoc) ExpressionEvaluatorManager.evaluate("var",
194                     this.var, String JavaDoc.class, this, super.pageContext);
195         }
196         if (this.attachTo != null) {
197             this.attachTo = (String JavaDoc) ExpressionEvaluatorManager.evaluate(
198                     "attachTo", this.attachTo, String JavaDoc.class, this,
199                     super.pageContext);
200         }
201         if (this.source != null) {
202             this.source = (String JavaDoc) ExpressionEvaluatorManager.evaluate(
203                     "source", this.source, String JavaDoc.class, this,
204                     super.pageContext);
205         }
206         if (this.sourceClass != null) {
207             this.sourceClass = (String JavaDoc) ExpressionEvaluatorManager.evaluate(
208                     "sourceClass", this.sourceClass, String JavaDoc.class, this,
209                     super.pageContext);
210         }
211         if (this.title != null) {
212             this.title = (String JavaDoc) ExpressionEvaluatorManager.evaluate("title",
213                     this.title, String JavaDoc.class, this, super.pageContext);
214         }
215         if (this.overlib != null) {
216             this.overlib = (String JavaDoc) ExpressionEvaluatorManager.evaluate(
217                     "overlib", this.overlib, String JavaDoc.class, this,
218                     super.pageContext);
219         }
220         if (this.postFunction != null) {
221             this.postFunction = (String JavaDoc) ExpressionEvaluatorManager.evaluate(
222                     "postFunction", this.postFunction, String JavaDoc.class, this,
223                     super.pageContext);
224         }
225         if (this.errorFunction != null) {
226             this.errorFunction = (String JavaDoc) ExpressionEvaluatorManager.evaluate(
227                     "errorFunction", this.errorFunction, String JavaDoc.class, this,
228                     super.pageContext);
229         }
230         if (this.emptyFunction != null) {
231             this.emptyFunction = (String JavaDoc) ExpressionEvaluatorManager.evaluate(
232                     "emptyFunction", this.emptyFunction, String JavaDoc.class, this,
233                     super.pageContext);
234         }
235         if (this.openEventType != null) {
236             this.openEventType = (String JavaDoc) ExpressionEvaluatorManager.evaluate(
237                     "openEvent", this.openEventType, String JavaDoc.class, this,
238                     super.pageContext);
239         }
240         if (this.closeEventType != null) {
241             this.closeEventType = (String JavaDoc) ExpressionEvaluatorManager.evaluate(
242                     "closeEvent", this.closeEventType, String JavaDoc.class, this,
243                     super.pageContext);
244         }
245         return SKIP_BODY;
246     }
247
248     @Override JavaDoc
249     public int doEndTag() throws JspException JavaDoc {
250         OptionsBuilder options = new OptionsBuilder();
251         if (this.source != null) {
252             options.add("source", this.source, true);
253         } else {
254             options.add("sourceClass", this.sourceClass, true);
255         }
256         options.add("parameters", this.parameters, true);
257         if (this.title != null)
258             options.add("title", this.title, true);
259         if (this.overlib != null)
260             options.add("overlib", this.overlib, true);
261         if (this.postFunction != null)
262             options.add("postFunction", this.postFunction, false);
263         if (this.emptyFunction != null)
264             options.add("emptyFunction", this.emptyFunction, false);
265         if (this.errorFunction != null)
266             options.add("errorFunction", this.errorFunction, false);
267         if (this.openEventType != null)
268             options.add("openEvent", this.openEventType, true);
269         if (this.closeEventType != null)
270             options.add("closeEvent", this.closeEventType, true);
271
272             options.add("doPost", String.valueOf(this.doPost), false);
273
274         StringBuffer JavaDoc script = new StringBuffer JavaDoc();
275         script.append("<script type=\"text/javascript\">\n");
276         if (StringUtils.isNotEmpty(this.var)) {
277             if (StringUtils.isNotEmpty(this.attachTo)) {
278                 script.append(this.attachTo).append(".").append(this.var);
279             } else {
280                 script.append("var ").append(this.var);
281             }
282             script.append(" = ");
283         }
284         script.append("new AjaxJspTag.Callout(\n").append("\"").append(
285                 this.baseUrl).append("\", {\n").append(options.toString())
286                 .append("});\n").append("</script>\n\n");
287
288         JspWriter JavaDoc writer = pageContext.getOut();
289         try {
290             writer.println(script);
291         } catch (IOException JavaDoc e) {
292             throw new JspException JavaDoc(e.getMessage());
293         }
294         return EVAL_PAGE;
295     }
296
297     @Override JavaDoc
298     public void release() {
299         this.var = null;
300         this.doPost = false;
301         this.attachTo = null;
302         this.baseUrl = null;
303         this.source = null;
304         this.sourceClass = null;
305         this.parameters = null;
306         this.title = null;
307         this.overlib = null;
308         this.postFunction = null;
309         this.emptyFunction = null;
310         this.errorFunction = null;
311         this.openEventType = null;
312         this.closeEventType = null;
313         super.release();
314     }
315
316     public boolean getDoPost() {
317         return doPost;
318     }
319
320     public void setDoPost(boolean doPost) {
321         this.doPost = doPost;
322     }
323
324 }
325
Popular Tags