KickJava   Java API By Example, From Geeks To Geeks.

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


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  * Wraps the scriptaculous' in-place editor
28  * (http://wiki.script.aculo.us/scriptaculous/show/Ajax.InPlaceEditor)
29  *
30  * @author Musachy Barroso
31  * @version $Revision: 1.2 $ $Date: 2007/06/20 20:55:56 $ $Author: jenskapitza $
32  */

33 public class AjaxEditorTag extends TagSupport JavaDoc {
34     private boolean showAcceptButton;
35
36     private String JavaDoc acceptText;
37
38     private boolean showCancelLink;
39
40     private String JavaDoc cancelText;
41
42     private String JavaDoc savingText;
43
44     private String JavaDoc mouseOverText;
45
46     private String JavaDoc styleId;
47
48     private String JavaDoc rows;
49
50     private String JavaDoc columns;
51
52     private String JavaDoc postFunction;
53
54     private String JavaDoc errorFunction;
55
56     private String JavaDoc preFunction;
57
58     private String JavaDoc highlightColor;
59
60     private String JavaDoc target;
61
62     private String JavaDoc baseUrl;
63
64     @Override JavaDoc
65     public int doStartTag() throws JspException JavaDoc {
66         // Required Properties
67
this.baseUrl = (String JavaDoc) ExpressionEvaluatorManager.evaluate("baseUrl",
68                 this.baseUrl, String JavaDoc.class, this, super.pageContext);
69         this.target = (String JavaDoc) ExpressionEvaluatorManager.evaluate("target",
70                 this.target, String JavaDoc.class, this, super.pageContext);
71
72         // Optional Properties
73
if (showAcceptButton && this.acceptText != null) {
74             this.acceptText = (String JavaDoc) ExpressionEvaluatorManager.evaluate(
75                     "acceptText", this.acceptText, String JavaDoc.class, this,
76                     super.pageContext);
77         }
78         if (showCancelLink && this.cancelText != null) {
79             this.cancelText = (String JavaDoc) ExpressionEvaluatorManager.evaluate(
80                     "cancelText", this.cancelText, String JavaDoc.class, this,
81                     super.pageContext);
82         }
83         if (this.savingText != null) {
84             this.savingText = (String JavaDoc) ExpressionEvaluatorManager.evaluate(
85                     "savingText", this.savingText, String JavaDoc.class, this,
86                     super.pageContext);
87         }
88         if (this.mouseOverText != null) {
89             this.mouseOverText = (String JavaDoc) ExpressionEvaluatorManager.evaluate(
90                     "mouseOverText", this.mouseOverText, String JavaDoc.class, this,
91                     super.pageContext);
92         }
93         if (this.styleId != null) {
94             this.styleId = (String JavaDoc) ExpressionEvaluatorManager.evaluate(
95                     "styleId", this.styleId, String JavaDoc.class, this,
96                     super.pageContext);
97         }
98         if (this.rows != null) {
99             this.rows = (String JavaDoc) ExpressionEvaluatorManager.evaluate("rows",
100                     this.rows, String JavaDoc.class, this, super.pageContext);
101         }
102         if (this.columns != null) {
103             this.columns = (String JavaDoc) ExpressionEvaluatorManager.evaluate(
104                     "columns", this.columns, String JavaDoc.class, this,
105                     super.pageContext);
106         }
107         if (this.postFunction != null) {
108             this.postFunction = (String JavaDoc) ExpressionEvaluatorManager.evaluate(
109                     "postFunction", this.postFunction, String JavaDoc.class, this,
110                     super.pageContext);
111         }
112         if (this.errorFunction != null) {
113             this.errorFunction = (String JavaDoc) ExpressionEvaluatorManager.evaluate(
114                     "errorFunction", this.errorFunction, String JavaDoc.class, this,
115                     super.pageContext);
116         }
117         if (this.preFunction != null) {
118             this.preFunction = (String JavaDoc) ExpressionEvaluatorManager.evaluate(
119                     "preFunction", this.preFunction, String JavaDoc.class, this,
120                     super.pageContext);
121         }
122         if (this.highlightColor != null) {
123             this.highlightColor = (String JavaDoc) ExpressionEvaluatorManager.evaluate(
124                     "highlightColor", this.highlightColor, String JavaDoc.class, this,
125                     super.pageContext);
126         }
127
128         return SKIP_BODY;
129     }
130
131     @Override JavaDoc
132     public int doEndTag() throws JspException JavaDoc {
133         OptionsBuilder options = new OptionsBuilder();
134
135         options.add("okButton", this.showAcceptButton ? "true" : "false", true);
136         if (this.showAcceptButton && this.acceptText != null)
137             options.add("okText", this.acceptText, true);
138
139         options.add("cancelLink", this.showCancelLink ? "true" : "false", true);
140         if (this.showCancelLink && this.cancelText != null)
141             options.add("cancelText", this.cancelText, true);
142
143         if (this.savingText != null)
144             options.add("savingText", this.savingText, true);
145         if (this.mouseOverText != null)
146             options.add("clickToEditText", this.mouseOverText, true);
147         if (this.preFunction != null)
148             options.add("callback", this.preFunction, false);
149         if (this.postFunction != null)
150             options.add("onComplete", this.postFunction, false);
151         if (this.errorFunction != null)
152             options.add("onFailure", this.errorFunction, false);
153         if (this.styleId != null)
154             options.add("formId", this.styleId, true);
155         if (this.rows != null)
156             options.add("rows", this.rows, true);
157         if (this.columns != null)
158             options.add("cols", this.columns, true);
159         if (this.highlightColor != null)
160             options.add("highlightColor", this.highlightColor, true);
161
162         StringBuffer JavaDoc script = new StringBuffer JavaDoc();
163         script.append("<script type=\"text/javascript\">\n");
164         script.append("var editor_").append(target);
165         script.append(" = new Ajax.InPlaceEditor(\"");
166         script.append(target);
167         script.append("\", \"");
168         script.append(this.baseUrl);
169         script.append("\", {\n");
170         script.append(options.toString());
171         script.append("});\n");
172         script.append("</script>\n\n");
173
174         JspWriter JavaDoc writer = pageContext.getOut();
175         try {
176             writer.println(script);
177         } catch (IOException JavaDoc e) {
178             throw new JspException JavaDoc(e.getMessage());
179         }
180         return EVAL_PAGE;
181     }
182
183     public String JavaDoc getAcceptText() {
184         return acceptText;
185     }
186
187     public void setAcceptText(String JavaDoc acceptText) {
188         this.acceptText = acceptText;
189     }
190
191     public String JavaDoc getCancelText() {
192         return cancelText;
193     }
194
195     public void setCancelText(String JavaDoc cancelText) {
196         this.cancelText = cancelText;
197     }
198
199     public String JavaDoc getColumns() {
200         return columns;
201     }
202
203     public void setColumns(String JavaDoc columns) {
204         this.columns = columns;
205     }
206
207     public String JavaDoc getErrorFunction() {
208         return errorFunction;
209     }
210
211     public void setErrorFunction(String JavaDoc errorFunction) {
212         this.errorFunction = errorFunction;
213     }
214
215     public String JavaDoc getHighlightColor() {
216         return highlightColor;
217     }
218
219     public void setHighlightColor(String JavaDoc highlightColor) {
220         this.highlightColor = highlightColor;
221     }
222
223     public String JavaDoc getMouseOverText() {
224         return mouseOverText;
225     }
226
227     public void setMouseOverText(String JavaDoc mouseOverText) {
228         this.mouseOverText = mouseOverText;
229     }
230
231     public String JavaDoc getPostFunction() {
232         return postFunction;
233     }
234
235     public void setPostFunction(String JavaDoc postFunction) {
236         this.postFunction = postFunction;
237     }
238
239     public String JavaDoc getPreFunction() {
240         return preFunction;
241     }
242
243     public void setPreFunction(String JavaDoc prerFunction) {
244         this.preFunction = prerFunction;
245     }
246
247     public String JavaDoc getRows() {
248         return rows;
249     }
250
251     public void setRows(String JavaDoc rows) {
252         this.rows = rows;
253     }
254
255     public String JavaDoc getSavingText() {
256         return savingText;
257     }
258
259     public void setSavingText(String JavaDoc savingText) {
260         this.savingText = savingText;
261     }
262
263     public boolean isShowAcceptButton() {
264         return showAcceptButton;
265     }
266
267     public void setShowAcceptButton(boolean showAcceptButton) {
268         this.showAcceptButton = showAcceptButton;
269     }
270
271     public boolean isShowCancelLink() {
272         return showCancelLink;
273     }
274
275     public void setShowCancelLink(boolean showCancelLink) {
276         this.showCancelLink = showCancelLink;
277     }
278
279     public String JavaDoc getStyleId() {
280         return styleId;
281     }
282
283     public void setStyleId(String JavaDoc styleId) {
284         this.styleId = styleId;
285     }
286
287     public String JavaDoc getBaseUrl() {
288         return baseUrl;
289     }
290
291     public void setBaseUrl(String JavaDoc baseURL) {
292         this.baseUrl = baseURL;
293     }
294
295     public String JavaDoc getTarget() {
296         return target;
297     }
298
299     public void setTarget(String JavaDoc target) {
300         this.target = target;
301     }
302 }
303
Popular Tags