KickJava   Java API By Example, From Geeks To Geeks.

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


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.taglibs.standard.lang.support.ExpressionEvaluatorManager;
25
26 /**
27  * Tag handler for the tree AJAX tag.
28  *
29  * @author Musachy Barroso
30  * @version $Revision: 1.2 $ $Date: 2007/06/20 20:55:56 $ $Author: jenskapitza $
31  */

32 public class AjaxTreeTag extends TagSupport JavaDoc {
33     private String JavaDoc baseUrl;
34
35     private String JavaDoc styleId;
36
37     private String JavaDoc preFunction;
38
39     private String JavaDoc postFunction;
40
41     private String JavaDoc errorFunction;
42
43     private String JavaDoc parser;
44
45     private String JavaDoc collapsedClass;
46
47     private String JavaDoc expandedClass;
48
49     private String JavaDoc parameters;
50
51     private String JavaDoc nodeClass;
52
53     private String JavaDoc treeClass;
54
55     public String JavaDoc getBaseUrl() {
56         return baseUrl;
57     }
58
59     public void setBaseUrl(String JavaDoc baseUrl) {
60         this.baseUrl = baseUrl;
61     }
62
63     public String JavaDoc getTreeClass() {
64         return treeClass;
65     }
66
67     public void setTreeClass(String JavaDoc treeClass) {
68         this.treeClass = treeClass;
69     }
70
71     public String JavaDoc getNodeClass() {
72         return nodeClass;
73     }
74
75     public void setNodeClass(String JavaDoc nodeClass) {
76         this.nodeClass = nodeClass;
77     }
78
79     public String JavaDoc getParameters() {
80         return parameters;
81     }
82
83     public void setParameters(String JavaDoc parameters) {
84         this.parameters = parameters;
85     }
86
87     @Override JavaDoc
88     public int doStartTag() throws JspException JavaDoc {
89         // Required Properties
90
this.baseUrl = (String JavaDoc) ExpressionEvaluatorManager.evaluate("baseUrl",
91                 this.baseUrl, String JavaDoc.class, this, super.pageContext);
92         this.parameters = (String JavaDoc) ExpressionEvaluatorManager.evaluate(
93                 "parameters", this.parameters, String JavaDoc.class, this,
94                 super.pageContext);
95
96         // Optional properties
97
if (this.collapsedClass != null)
98             this.collapsedClass = (String JavaDoc) ExpressionEvaluatorManager.evaluate(
99                     "collapsedClass", this.collapsedClass, String JavaDoc.class, this,
100                     super.pageContext);
101         if (this.nodeClass != null)
102             this.nodeClass = (String JavaDoc) ExpressionEvaluatorManager.evaluate(
103                     "nodeClass", this.nodeClass, String JavaDoc.class, this,
104                     super.pageContext);
105         if (this.expandedClass != null)
106             this.expandedClass = (String JavaDoc) ExpressionEvaluatorManager.evaluate(
107                     "expandedClass", this.expandedClass, String JavaDoc.class, this,
108                     super.pageContext);
109         if (this.treeClass != null)
110             this.treeClass = (String JavaDoc) ExpressionEvaluatorManager.evaluate(
111                     "treeClass", this.treeClass, String JavaDoc.class, this,
112                     super.pageContext);
113         return SKIP_BODY;
114     }
115
116     public String JavaDoc getStyleId() {
117         return styleId;
118     }
119
120     public void setStyleId(String JavaDoc treeStyleId) {
121         this.styleId = treeStyleId;
122     }
123
124     public String JavaDoc getErrorFunction() {
125         return errorFunction;
126     }
127
128     public void setErrorFunction(String JavaDoc errorFunction) {
129         this.errorFunction = errorFunction;
130     }
131
132     public String JavaDoc getParser() {
133         return parser;
134     }
135
136     public void setParser(String JavaDoc parser) {
137         this.parser = parser;
138     }
139
140     public String JavaDoc getPostFunction() {
141         return postFunction;
142     }
143
144     public void setPostFunction(String JavaDoc postFunction) {
145         this.postFunction = postFunction;
146     }
147
148     public String JavaDoc getPreFunction() {
149         return preFunction;
150     }
151
152     public void setPreFunction(String JavaDoc preFunction) {
153         this.preFunction = preFunction;
154     }
155
156     public String JavaDoc getCollapsedClass() {
157         return collapsedClass;
158     }
159
160     public void setCollapsedClass(String JavaDoc collapsedClass) {
161         this.collapsedClass = collapsedClass;
162     }
163
164     public String JavaDoc getExpandedClass() {
165         return expandedClass;
166     }
167
168     public void setExpandedClass(String JavaDoc expandedClass) {
169         this.expandedClass = expandedClass;
170     }
171
172     @Override JavaDoc
173     public int doEndTag() throws JspException JavaDoc {
174         OptionsBuilder options = new OptionsBuilder();
175         options.add("target", "elem", false);
176
177         if (this.collapsedClass != null)
178             options.add("collapsedClass", this.collapsedClass, true);
179         if (this.parameters != null)
180             options.add("parameters", this.parameters, true);
181         if (this.expandedClass != null)
182             options.add("expandedClass", this.expandedClass, true);
183         if (this.treeClass != null)
184             options.add("treeClass", this.treeClass, true);
185         if (this.nodeClass != null)
186             options.add("nodeClass", this.nodeClass, true);
187         if (this.preFunction != null)
188             options.add("preFunction", this.preFunction, false);
189         if (this.postFunction != null)
190             options.add("postFunction", this.postFunction, false);
191         if (this.errorFunction != null)
192             options.add("errorFunction", this.errorFunction, false);
193         if (this.parser != null)
194             options.add("parser", this.parser, false);
195
196         StringBuffer JavaDoc script = new StringBuffer JavaDoc();
197         script.append("<div id=\"");
198         script.append(this.styleId);
199         script.append("\"></div>\n");
200         script.append("<script type=\"text/javascript\">\n");
201         script
202                 .append("window.toggleTreeNode = function(elem, url, params) {\n");
203
204         script.append("var aj_").append(this.styleId);
205
206         script.append(" = new AjaxJspTag.Tree(url, {\n").append(
207                 options.toString()).append("});\n").append("}\n\n").append(
208                 "addOnLoadEvent(function() {window.toggleTreeNode('").append(
209                 styleId).append("', '").append(this.baseUrl).append("', null")
210                 .append(");});\n").append("</script>\n\n");
211         JspWriter JavaDoc writer = pageContext.getOut();
212         try {
213             writer.println(script);
214         } catch (IOException JavaDoc e) {
215             throw new JspException JavaDoc(e.getMessage());
216         }
217         return EVAL_PAGE;
218     }
219
220     @Override JavaDoc
221     public void release() {
222         baseUrl = null;
223         styleId = null;
224         preFunction = null;
225         postFunction = null;
226         errorFunction = null;
227         parser = null;
228         collapsedClass = null;
229         expandedClass = null;
230         parameters = null;
231         nodeClass = null;
232         treeClass = null;
233         super.release();
234     }
235 }
236
Popular Tags