01: /*
02: WikiForms - a WikiPage FORM handler for JSPWiki.
03:
04: Copyright (C) 2003 BaseN.
05:
06: JSPWiki Copyright (C) 2002 Janne Jalkanen (Janne.Jalkanen@iki.fi)
07:
08: This program is free software; you can redistribute it and/or modify
09: it under the terms of the GNU Lesser General Public License as published
10: by the Free Software Foundation; either version 2.1 of the License, or
11: (at your option) any later version.
12:
13: This program is distributed in the hope that it will be useful,
14: but WITHOUT ANY WARRANTY; without even the implied warranty of
15: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16: GNU Lesser General Public License for more details.
17:
18: You should have received a copy of the GNU Lesser General Public License
19: along with this program; if not, write to the Free Software
20: */
21: package com.ecyrd.jspwiki.forms;
22:
23: import com.ecyrd.jspwiki.*;
24: import com.ecyrd.jspwiki.plugin.PluginException;
25: import com.ecyrd.jspwiki.plugin.WikiPlugin;
26:
27: import java.util.*;
28:
29: import org.apache.ecs.ConcreteElement;
30: import org.apache.ecs.xhtml.textarea;
31:
32: /**
33: * @author ebu
34: */
35: public class FormTextarea extends FormElement {
36: public static final String PARAM_ROWS = "rows";
37: public static final String PARAM_COLS = "cols";
38:
39: public String execute(WikiContext ctx, Map params)
40: throws PluginException {
41: // Don't render if no error and error-only-rendering is on.
42: FormInfo info = getFormInfo(ctx);
43: Map previousValues = null;
44: ResourceBundle rb = ctx
45: .getBundle(WikiPlugin.CORE_PLUGINS_RESOURCEBUNDLE);
46:
47: if (info != null) {
48: if (info.hide()) {
49: return "<p>" + rb.getString("formclose.noneedtoshow")
50: + "</p>";
51: }
52: previousValues = info.getSubmission();
53: }
54:
55: if (previousValues == null) {
56: previousValues = new HashMap();
57: }
58:
59: ConcreteElement field = null;
60:
61: field = buildTextArea(params, previousValues, rb);
62:
63: // We should look for extra params, e.g. width, ..., here.
64: if (field != null)
65: return field.toString(ctx.getEngine().getContentEncoding());
66:
67: return "";
68: }
69:
70: private textarea buildTextArea(Map params, Map previousValues,
71: ResourceBundle rb) throws PluginException {
72: String inputName = (String) params.get(PARAM_INPUTNAME);
73: String rows = (String) params.get(PARAM_ROWS);
74: String cols = (String) params.get(PARAM_COLS);
75:
76: if (inputName == null)
77: throw new PluginException(rb
78: .getString("formtextarea.namemissing"));
79:
80: // In order to isolate posted form elements into their own
81: // map, prefix the variable name here. It will be stripped
82: // when the handler plugin is executed.
83: textarea field = new textarea(HANDLERPARAM_PREFIX + inputName,
84: rows, cols);
85:
86: if (previousValues != null) {
87: String oldValue = (String) previousValues.get(inputName);
88: if (oldValue != null) {
89: field.addElement(oldValue);
90: } else {
91: oldValue = (String) params.get(PARAM_VALUE);
92: if (oldValue != null)
93: field.addElement(oldValue);
94: }
95: }
96: return field;
97: }
98: }
|