KickJava   Java API By Example, From Geeks To Geeks.

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


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 portlet AJAX tag.
30  *
31  * @author Darren Spurgeon
32  * @author Jens Kapitza
33  * @version $Revision: 1.5 $ $Date: 2007/06/28 21:50:35 $ $Author: jenskapitza $
34  */

35 public class AjaxPortletTag extends TagSupport JavaDoc {
36
37     public AjaxPortletTag() {
38         withBar = true;
39     }
40
41     private String JavaDoc var;
42
43     private boolean startMinimize;
44
45     public void setStartMinimize(boolean startMinimize) {
46         this.startMinimize = startMinimize;
47     }
48
49     public boolean getStartMinimize() {
50         return this.startMinimize;
51     }
52
53     private String JavaDoc attachTo;
54
55     private String JavaDoc baseUrl;
56
57     private String JavaDoc source;
58
59     private String JavaDoc parameters;
60
61     private String JavaDoc classNamePrefix;
62
63     private String JavaDoc title;
64
65     private String JavaDoc imageClose;
66
67     private String JavaDoc imageMaximize;
68
69     private String JavaDoc imageMinimize;
70
71     private String JavaDoc imageRefresh;
72
73     private String JavaDoc refreshPeriod;
74
75     private String JavaDoc executeOnLoad;
76
77     private String JavaDoc expireDays;
78
79     private String JavaDoc expireHours;
80
81     private String JavaDoc expireMinutes;
82
83     private String JavaDoc preFunction;
84
85     private String JavaDoc postFunction;
86
87     private String JavaDoc errorFunction;
88
89     private String JavaDoc parser;
90
91     public String JavaDoc getBaseUrl() {
92         return baseUrl;
93     }
94
95     public void setBaseUrl(String JavaDoc baseUrl) {
96         this.baseUrl = baseUrl;
97     }
98
99     public String JavaDoc getClassNamePrefix() {
100         return classNamePrefix;
101     }
102
103     public void setClassNamePrefix(String JavaDoc classNamePrefix) {
104         this.classNamePrefix = classNamePrefix;
105     }
106
107     public String JavaDoc getImageClose() {
108         return imageClose;
109     }
110
111     public void setImageClose(String JavaDoc imageClose) {
112         this.imageClose = imageClose;
113     }
114
115     public String JavaDoc getPreFunction() {
116         return preFunction;
117     }
118
119     public void setPreFunction(String JavaDoc preFunction) {
120         this.preFunction = preFunction;
121     }
122
123     public String JavaDoc getExecuteOnLoad() {
124         return executeOnLoad;
125     }
126
127     public void setExecuteOnLoad(String JavaDoc executeOnLoad) {
128         this.executeOnLoad = executeOnLoad;
129     }
130
131     public String JavaDoc getExpireDays() {
132         return expireDays;
133     }
134
135     public void setExpireDays(String JavaDoc expireDays) {
136         this.expireDays = expireDays;
137     }
138
139     public String JavaDoc getExpireHours() {
140         return expireHours;
141     }
142
143     public void setExpireHours(String JavaDoc expireHours) {
144         this.expireHours = expireHours;
145     }
146
147     public String JavaDoc getExpireMinutes() {
148         return expireMinutes;
149     }
150
151     public void setExpireMinutes(String JavaDoc expireMinutes) {
152         this.expireMinutes = expireMinutes;
153     }
154
155     public String JavaDoc getErrorFunction() {
156         return errorFunction;
157     }
158
159     public void setErrorFunction(String JavaDoc errorFunction) {
160         this.errorFunction = errorFunction;
161     }
162
163     public String JavaDoc getImageMaximize() {
164         return imageMaximize;
165     }
166
167     public void setImageMaximize(String JavaDoc imageMaximize) {
168         this.imageMaximize = imageMaximize;
169     }
170
171     public String JavaDoc getImageMinimize() {
172         return imageMinimize;
173     }
174
175     public void setImageMinimize(String JavaDoc imageMinimize) {
176         this.imageMinimize = imageMinimize;
177     }
178
179     public String JavaDoc getParameters() {
180         return parameters;
181     }
182
183     public void setParameters(String JavaDoc parameters) {
184         this.parameters = parameters;
185     }
186
187     public String JavaDoc getPostFunction() {
188         return postFunction;
189     }
190
191     public void setPostFunction(String JavaDoc postFunction) {
192         this.postFunction = postFunction;
193     }
194
195     public String JavaDoc getImageRefresh() {
196         return imageRefresh;
197     }
198
199     public void setImageRefresh(String JavaDoc imageRefresh) {
200         this.imageRefresh = imageRefresh;
201     }
202
203     public String JavaDoc getParser() {
204         return parser;
205     }
206
207     public void setParser(String JavaDoc parser) {
208         this.parser = parser;
209     }
210
211     public String JavaDoc getRefreshPeriod() {
212         return refreshPeriod;
213     }
214
215     public void setRefreshPeriod(String JavaDoc refreshPeriod) {
216         this.refreshPeriod = refreshPeriod;
217     }
218
219     public String JavaDoc getSource() {
220         return source;
221     }
222
223     public void setSource(String JavaDoc source) {
224         this.source = source;
225     }
226
227     public String JavaDoc getTitle() {
228         return title;
229     }
230
231     public void setTitle(String JavaDoc title) {
232         this.title = title;
233     }
234
235     public String JavaDoc getVar() {
236         return var;
237     }
238
239     public void setVar(String JavaDoc var) {
240         this.var = var;
241     }
242
243     public String JavaDoc getAttachTo() {
244         return attachTo;
245     }
246
247     public void setAttachTo(String JavaDoc attachTo) {
248         this.attachTo = attachTo;
249     }
250
251     @Override JavaDoc
252     public int doStartTag() throws JspException JavaDoc {
253         // Required Properties
254
this.baseUrl = (String JavaDoc) ExpressionEvaluatorManager.evaluate("baseUrl",
255                 this.baseUrl, String JavaDoc.class, this, super.pageContext);
256         if (this.parameters != null) {
257             this.parameters = (String JavaDoc) ExpressionEvaluatorManager.evaluate(
258                     "parameters", this.parameters, String JavaDoc.class, this,
259                     super.pageContext);
260         }
261         if (this.classNamePrefix != null) {
262             this.classNamePrefix = (String JavaDoc) ExpressionEvaluatorManager
263                     .evaluate("classNamePrefix", this.classNamePrefix,
264                             String JavaDoc.class, this, super.pageContext);
265         }
266
267         // Optional Properties
268
if (this.var != null) {
269             this.var = (String JavaDoc) ExpressionEvaluatorManager.evaluate("var",
270                     this.var, String JavaDoc.class, this, super.pageContext);
271         }
272         if (this.attachTo != null) {
273             this.attachTo = (String JavaDoc) ExpressionEvaluatorManager.evaluate(
274                     "attachTo", this.attachTo, String JavaDoc.class, this,
275                     super.pageContext);
276         }
277         if (this.source != null) {
278             this.source = (String JavaDoc) ExpressionEvaluatorManager.evaluate(
279                     "source", this.source, String JavaDoc.class, this,
280                     super.pageContext);
281         }
282         if (this.title != null) {
283             this.title = (String JavaDoc) ExpressionEvaluatorManager.evaluate("title",
284                     this.title, String JavaDoc.class, this, super.pageContext);
285         }
286         if (this.imageClose != null) {
287             this.imageClose = (String JavaDoc) ExpressionEvaluatorManager.evaluate(
288                     "imageClose", this.imageClose, String JavaDoc.class, this,
289                     super.pageContext);
290         }
291         if (this.imageMaximize != null) {
292             this.imageMaximize = (String JavaDoc) ExpressionEvaluatorManager.evaluate(
293                     "imageMaximize", this.imageMaximize, String JavaDoc.class, this,
294                     super.pageContext);
295         }
296         if (this.imageMinimize != null) {
297             this.imageMinimize = (String JavaDoc) ExpressionEvaluatorManager.evaluate(
298                     "imageMinimize", this.imageMinimize, String JavaDoc.class, this,
299                     super.pageContext);
300         }
301         if (this.imageRefresh != null) {
302             this.imageRefresh = (String JavaDoc) ExpressionEvaluatorManager.evaluate(
303                     "imageRefresh", this.imageRefresh, String JavaDoc.class, this,
304                     super.pageContext);
305         }
306         if (this.refreshPeriod != null) {
307             this.refreshPeriod = (String JavaDoc) ExpressionEvaluatorManager.evaluate(
308                     "refreshPeriod", this.refreshPeriod, String JavaDoc.class, this,
309                     super.pageContext);
310         }
311         if (this.executeOnLoad != null) {
312             this.executeOnLoad = (String JavaDoc) ExpressionEvaluatorManager.evaluate(
313                     "executeOnLoad", this.executeOnLoad, String JavaDoc.class, this,
314                     super.pageContext);
315         }
316         if (this.postFunction != null) {
317             this.postFunction = (String JavaDoc) ExpressionEvaluatorManager.evaluate(
318                     "postFunction", this.postFunction, String JavaDoc.class, this,
319                     super.pageContext);
320         }
321         if (this.errorFunction != null) {
322             this.errorFunction = (String JavaDoc) ExpressionEvaluatorManager.evaluate(
323                     "errorFunction", this.errorFunction, String JavaDoc.class, this,
324                     super.pageContext);
325         }
326         if (this.preFunction != null) {
327             this.preFunction = (String JavaDoc) ExpressionEvaluatorManager.evaluate(
328                     "preFunction", this.preFunction, String JavaDoc.class, this,
329                     super.pageContext);
330         }
331         if (!this.withBar) {
332             this.imageClose = null;
333             this.imageMaximize = null;
334             this.imageMinimize = null;
335             this.imageRefresh = null;
336         }
337         return SKIP_BODY;
338     }
339
340     @Override JavaDoc
341     public int doEndTag() throws JspException JavaDoc {
342         OptionsBuilder options = new OptionsBuilder();
343         options.add("source", this.source, true);
344         options.add("classNamePrefix", this.classNamePrefix, true);
345         options.add("title", this.title, true);
346         if (this.imageClose != null)
347             options.add("imageClose", this.imageClose, true);
348         if (this.imageMaximize != null)
349             options.add("imageMaximize", this.imageMaximize, true);
350         if (this.imageMinimize != null)
351             options.add("imageMinimize", this.imageMinimize, true);
352         if (this.imageRefresh != null)
353             options.add("imageRefresh", this.imageRefresh, true);
354         if (this.parameters != null)
355             options.add("parameters", this.parameters, true);
356         if (this.refreshPeriod != null)
357             options.add("refreshPeriod", this.refreshPeriod, true);
358         if (this.executeOnLoad != null)
359             options.add("executeOnLoad", this.executeOnLoad, true);
360         if (this.expireDays != null)
361             options.add("expireDays", this.expireDays, true);
362         if (this.expireHours != null)
363             options.add("expireHours", this.expireHours, true);
364         if (this.expireMinutes != null)
365             options.add("expireMinutes", this.expireMinutes, true);
366         if (this.postFunction != null)
367             options.add("postFunction", this.postFunction, false);
368         if (this.preFunction != null)
369             options.add("preFunction", this.preFunction, false);
370         if (this.errorFunction != null)
371             options.add("errorFunction", this.errorFunction, false);
372         if (this.parser != null)
373             options.add("parser", this.parser, false);
374         if (this.startMinimize)
375             options.add("startMinimize", String.valueOf(this.startMinimize),
376                     false);
377         if (this.withBar)
378             options.add("withBar", String.valueOf(this.withBar), false);
379
380         StringBuffer JavaDoc script = new StringBuffer JavaDoc();
381         // surrounding box
382
script.append("<div id=\"").append(this.source).append("\" class=\"")
383                 .append(this.classNamePrefix).append("Box\">");
384         // toolbar
385
if (this.withBar) {
386             script.append("<div id=\"").append(this.source).append(
387                     "Tools\" class=\"").append(this.classNamePrefix).append(
388                     "Tools\">");
389             if (this.imageRefresh != null) {
390                 script.append("<img id=\"").append(this.source).append(
391                         "Refresh\" class=\"").append(this.classNamePrefix)
392                         .append("Refresh\" SRC=\"").append(this.imageRefresh)
393                         .append("\"/>");
394             }
395             if (this.imageMaximize != null && this.imageMinimize != null) {
396                 script.append("<img id=\"").append(this.source).append(
397                         "Size\" class=\"").append(this.classNamePrefix).append(
398                         "Size\" SRC=\"").append(this.imageMinimize).append(
399                         "\"/>");
400             }
401             if (this.imageClose != null) {
402                 script.append("<img id=\"").append(this.source).append(
403                         "Close\" class=\"").append(this.classNamePrefix)
404                         .append("Close\" SRC=\"").append(this.imageClose)
405                         .append("\"/>");
406             }
407             script.append("</div>");
408         }
409         // title
410
script.append("<div id=\"").append(this.source).append(
411                 "Title\" class=\"").append(this.classNamePrefix).append(
412                 "Title\">").append(this.title).append("</div>");
413         // content
414
script.append("<div id=\"").append(this.source).append(
415                 "Content\" class=\"").append(this.classNamePrefix).append(
416                 "Content\"></div>");
417         script.append("</div>\n");
418         script.append("<script type=\"text/javascript\">\n");
419
420         if (StringUtils.isNotEmpty(this.attachTo)) {
421             script.append(this.attachTo).append(".");
422             if (StringUtils.isNotEmpty(this.var)) {
423                 script.append(this.var);
424             } else {
425                 script.append("aj_").append(this.source);
426             }
427         } else if (StringUtils.isNotEmpty(this.var)) {
428             script.append("var ").append(this.var);
429         } else {
430             script.append("var aj_").append(this.source);
431         }
432
433         script.append(" = new AjaxJspTag.Portlet(\n").append("\"").append(
434                 this.baseUrl).append("\", {\n").append(options.toString())
435                 .append("});\n").append("</script>\n\n");
436
437         JspWriter JavaDoc writer = pageContext.getOut();
438         try {
439             writer.println(script);
440         } catch (IOException JavaDoc e) {
441             throw new JspException JavaDoc(e.getMessage());
442         }
443         return EVAL_PAGE;
444     }
445
446     @Override JavaDoc
447     public void release() {
448         this.var = null;
449         this.startMinimize = false;
450         this.withBar = false;
451         this.attachTo = null;
452         this.baseUrl = null;
453         this.source = null;
454         this.parameters = null;
455         this.classNamePrefix = null;
456         this.title = null;
457         this.imageClose = null;
458         this.imageMaximize = null;
459         this.imageMinimize = null;
460         this.imageRefresh = null;
461         this.refreshPeriod = null;
462         this.executeOnLoad = null;
463         this.expireDays = null;
464         this.expireHours = null;
465         this.expireMinutes = null;
466         this.postFunction = null;
467         this.preFunction = null;
468         this.errorFunction = null;
469         this.parser = null;
470         super.release();
471     }
472
473     public boolean getWithBar() {
474         return withBar;
475     }
476
477     private boolean withBar;
478
479     public void setWithBar(boolean withBar) {
480         this.withBar = withBar;
481     }
482
483 }
484
Popular Tags