001/*
002 * This library is part of OpenCms -
003 * the Open Source Content Management System
004 *
005 * Copyright (c) Alkacon Software GmbH & Co. KG (http://www.alkacon.com)
006 *
007 * This library is free software; you can redistribute it and/or
008 * modify it under the terms of the GNU Lesser General Public
009 * License as published by the Free Software Foundation; either
010 * version 2.1 of the License, or (at your option) any later version.
011 *
012 * This library is distributed in the hope that it will be useful,
013 * but WITHOUT ANY WARRANTY; without even the implied warranty of
014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015 * Lesser General Public License for more details.
016 *
017 * For further information about Alkacon Software GmbH & Co. KG, please see the
018 * company website: http://www.alkacon.com
019 *
020 * For further information about OpenCms, please see the
021 * project website: http://www.opencms.org
022 *
023 * You should have received a copy of the GNU Lesser General Public
024 * License along with this library; if not, write to the Free Software
025 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
026 */
027
028package org.opencms.widgets;
029
030import org.opencms.file.CmsObject;
031import org.opencms.file.CmsResource;
032import org.opencms.i18n.CmsEncoder;
033import org.opencms.i18n.CmsMessages;
034import org.opencms.xml.content.I_CmsXmlContentHandler.DisplayType;
035import org.opencms.xml.types.A_CmsXmlContentValue;
036
037import java.util.List;
038import java.util.Locale;
039
040/**
041 * Provides a standard HTML form textarea widget, for use on a widget dialog.<p>
042 *
043 * Displays a textarea with 4 rows to enter String values conveniently.<p>
044 *
045 * @since 6.0.0
046 */
047public class CmsTextareaWidget extends A_CmsWidget implements I_CmsADEWidget {
048
049    /** Default number of rows to display. */
050    private static final int DEFAULT_ROWS_NUMBER = 4;
051
052    /**
053     * Creates a new textarea widget.<p>
054     */
055    public CmsTextareaWidget() {
056
057        // default configuration is to display 4 rows
058        this(DEFAULT_ROWS_NUMBER);
059    }
060
061    /**
062     * Creates a new textarea widget with the given number of rows.<p>
063     *
064     * @param rows the number of rows to display
065     */
066    public CmsTextareaWidget(int rows) {
067
068        super("" + rows);
069    }
070
071    /**
072     * Creates a new textarea widget with the given configuration.<p>
073     *
074     * @param configuration the configuration to use
075     */
076    public CmsTextareaWidget(String configuration) {
077
078        super(configuration);
079    }
080
081    /**
082     * @see org.opencms.widgets.I_CmsADEWidget#getConfiguration(org.opencms.file.CmsObject, org.opencms.xml.types.A_CmsXmlContentValue, org.opencms.i18n.CmsMessages, org.opencms.file.CmsResource, java.util.Locale)
083     */
084    public String getConfiguration(
085        CmsObject cms,
086        A_CmsXmlContentValue schemaType,
087        CmsMessages messages,
088        CmsResource resource,
089        Locale contentLocale) {
090
091        return getConfiguration();
092    }
093
094    /**
095     * @see org.opencms.widgets.I_CmsADEWidget#getCssResourceLinks(org.opencms.file.CmsObject)
096     */
097    public List<String> getCssResourceLinks(CmsObject cms) {
098
099        return null;
100    }
101
102    /**
103     * @see org.opencms.widgets.I_CmsADEWidget#getDefaultDisplayType()
104     */
105    public DisplayType getDefaultDisplayType() {
106
107        return DisplayType.wide;
108    }
109
110    /**
111     * @see org.opencms.widgets.I_CmsWidget#getDialogWidget(org.opencms.file.CmsObject, org.opencms.widgets.I_CmsWidgetDialog, org.opencms.widgets.I_CmsWidgetParameter)
112     */
113    public String getDialogWidget(CmsObject cms, I_CmsWidgetDialog widgetDialog, I_CmsWidgetParameter param) {
114
115        String id = param.getId();
116        StringBuffer result = new StringBuffer(16);
117        int rows = DEFAULT_ROWS_NUMBER;
118        try {
119            rows = Integer.valueOf(getConfiguration()).intValue();
120        } catch (Exception e) {
121            // ignore
122        }
123
124        result.append("<td class=\"xmlTd\">");
125        result.append("<textarea class=\"xmlInput maxwidth");
126        if (param.hasError()) {
127            result.append(" xmlInputError");
128        }
129        result.append("\" name=\"");
130        result.append(id);
131        result.append("\" rows=\"");
132        result.append(rows);
133        result.append("\" cols=\"60\" style=\"overflow:auto;\">");
134        result.append(CmsEncoder.escapeXml(param.getStringValue(cms)));
135        result.append("</textarea>");
136        result.append("</td>");
137
138        return result.toString();
139    }
140
141    /**
142     * @see org.opencms.widgets.I_CmsADEWidget#getInitCall()
143     */
144    public String getInitCall() {
145
146        return null;
147    }
148
149    /**
150     * @see org.opencms.widgets.I_CmsADEWidget#getJavaScriptResourceLinks(org.opencms.file.CmsObject)
151     */
152    public List<String> getJavaScriptResourceLinks(CmsObject cms) {
153
154        return null;
155    }
156
157    /**
158     * @see org.opencms.widgets.I_CmsADEWidget#getWidgetName()
159     */
160    public String getWidgetName() {
161
162        return CmsTextareaWidget.class.getName();
163    }
164
165    /**
166     * @see org.opencms.widgets.I_CmsADEWidget#isInternal()
167     */
168    public boolean isInternal() {
169
170        return true;
171    }
172
173    /**
174     * @see org.opencms.widgets.I_CmsWidget#newInstance()
175     */
176    public I_CmsWidget newInstance() {
177
178        return new CmsTextareaWidget(getConfiguration());
179    }
180
181}