001: // /////////////////////////////
002: // Makumba, Makumba tag library
003: // Copyright (C) 2000-2003 http://www.makumba.org
004: //
005: // This library is free software; you can redistribute it and/or
006: // modify it under the terms of the GNU Lesser General Public
007: // License as published by the Free Software Foundation; either
008: // version 2.1 of the License, or (at your option) any later version.
009: //
010: // This library is distributed in the hope that it will be useful,
011: // but WITHOUT ANY WARRANTY; without even the implied warranty of
012: // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
013: // Lesser General Public License for more details.
014: //
015: // You should have received a copy of the GNU Lesser General Public
016: // License along with this library; if not, write to the Free Software
017: // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
018: //
019: // -------------
020: // $Id: textEditor.java 1688 2007-09-25 12:54:46Z manuel_gay $
021: // $Name$
022: /////////////////////////////////////
023:
024: package org.makumba.forms.html;
025:
026: import java.util.Dictionary;
027:
028: import org.makumba.HtmlUtils;
029: import org.makumba.commons.formatters.FieldFormatter;
030: import org.makumba.commons.formatters.RecordFormatter;
031:
032: public class textEditor extends FieldEditor {
033:
034: private static final class SingletonHolder {
035: static final FieldEditor singleton = new textEditor();
036: }
037:
038: private textEditor() {
039: }
040:
041: public static FieldFormatter getInstance() {
042: return SingletonHolder.singleton;
043: }
044:
045: static String[] _params = { "default", "empty", "type", "rows",
046: "cols" };
047:
048: static String[][] _paramValues = { null, null,
049: { "textarea", "file" }, null, null };
050:
051: public String[] getAcceptedParams() {
052: return _params;
053: }
054:
055: public String[][] getAcceptedValue() {
056: return _paramValues;
057: }
058:
059: public String getParams(RecordFormatter rf, int fieldIndex,
060: Dictionary formatParams) {
061: return getIntParamString(rf, fieldIndex, formatParams, "rows")
062: + getIntParamString(rf, fieldIndex, formatParams,
063: "cols");
064: }
065:
066: public String formatNull(RecordFormatter rf, int fieldIndex,
067: Dictionary formatParams) {
068: return formatNotNull(rf, fieldIndex, null, formatParams);
069: }
070:
071: public String formatNotNull(RecordFormatter rf, int fieldIndex,
072: Object o, Dictionary formatParams) {
073: if (isTextArea(rf, fieldIndex, formatParams)) {
074: return "<TEXTAREA name=\""
075: + getInputName(rf, fieldIndex, formatParams)
076: + "\" " + getParams(rf, fieldIndex, formatParams)
077: + getExtraFormatting(rf, fieldIndex, formatParams)
078: + " >"
079: + formatValue(rf, fieldIndex, o, formatParams)
080: + "</TEXTAREA>";
081: } else {
082: return fileInput(rf, fieldIndex, formatParams);
083: }
084: }
085:
086: /**
087: * Formats the value to appear in an input statement. For textarea type data
088: * only!
089: */
090: public String formatValue(RecordFormatter rf, int fieldIndex,
091: Object o, Dictionary formatParams) {
092: String s = (o == null) ? null : HtmlUtils.string2html(o
093: .toString());
094: return resetValueFormat(rf, fieldIndex, s, formatParams);
095: }
096:
097: /*
098: * Formats the value to appear in hidden input statement: don't overload
099: * default behaviour set in FieldEditor.
100: */
101: // public String formatHiddenValue(Object o, Dictionary formatParams) {}
102: String fileInput(RecordFormatter rf, int fieldIndex,
103: Dictionary formatParams) {
104: return "<INPUT name=\""
105: + getInputName(rf, fieldIndex, formatParams)
106: + "\" type=\"file\" "
107: + getExtraFormatting(rf, fieldIndex, formatParams)
108: + " >";
109: }
110:
111: boolean isTextArea(RecordFormatter rf, int fieldIndex,
112: Dictionary formatParams) {
113: String s = (String) formatParams.get("type");
114: if (s == null)
115: return true;
116: return s.equals("textarea");
117: }
118: }
|