KickJava   Java API By Example, From Geeks To Geeks.

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


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

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

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