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 input widget, for use on a widget dialog.<p>
042 *
043 * @since 6.0.0
044 */
045public class CmsInputWidget extends A_CmsWidget implements I_CmsADEWidget {
046
047    /**
048     * Creates a new input widget.<p>
049     */
050    public CmsInputWidget() {
051
052        // empty constructor is required for class registration
053        this("");
054    }
055
056    /**
057     * Creates a new input widget with the given configuration.<p>
058     *
059     * @param configuration the configuration to use
060     */
061    public CmsInputWidget(String configuration) {
062
063        super(configuration);
064    }
065
066    /**
067     * @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)
068     */
069    public String getConfiguration(
070        CmsObject cms,
071        A_CmsXmlContentValue schemaType,
072        CmsMessages messages,
073        CmsResource resource,
074        Locale contentLocale) {
075
076        return getConfiguration();
077    }
078
079    /**
080     * @see org.opencms.widgets.I_CmsADEWidget#getCssResourceLinks(org.opencms.file.CmsObject)
081     */
082    public List<String> getCssResourceLinks(CmsObject cms) {
083
084        // not needed for internal widget
085        return null;
086    }
087
088    /**
089     * @see org.opencms.widgets.I_CmsADEWidget#getDefaultDisplayType()
090     */
091    public DisplayType getDefaultDisplayType() {
092
093        return DisplayType.singleline;
094    }
095
096    /**
097     * @see org.opencms.widgets.I_CmsWidget#getDialogWidget(org.opencms.file.CmsObject, org.opencms.widgets.I_CmsWidgetDialog, org.opencms.widgets.I_CmsWidgetParameter)
098     */
099    public String getDialogWidget(CmsObject cms, I_CmsWidgetDialog widgetDialog, I_CmsWidgetParameter param) {
100
101        String id = param.getId();
102
103        StringBuffer result = new StringBuffer(16);
104
105        result.append("<td class=\"xmlTd\">");
106        result.append("<input class=\"xmlInput textInput");
107        if (param.hasError()) {
108            result.append(" xmlInputError");
109        }
110        result.append("\"");
111        result.append(" name=\"");
112        result.append(id);
113        result.append("\" id=\"");
114        result.append(id);
115        result.append("\" value=\"");
116        result.append(CmsEncoder.escapeXml(param.getStringValue(cms)));
117        result.append("\">");
118        result.append("</td>");
119
120        return result.toString();
121    }
122
123    /**
124     * @see org.opencms.widgets.I_CmsADEWidget#getInitCall()
125     */
126    public String getInitCall() {
127
128        // not needed for internal widget
129        return null;
130    }
131
132    /**
133     * @see org.opencms.widgets.I_CmsADEWidget#getJavaScriptResourceLinks(org.opencms.file.CmsObject)
134     */
135    public List<String> getJavaScriptResourceLinks(CmsObject cms) {
136
137        // not needed for internal widget
138        return null;
139    }
140
141    /**
142     * @see org.opencms.widgets.I_CmsADEWidget#getWidgetName()
143     */
144    public String getWidgetName() {
145
146        return CmsInputWidget.class.getName();
147    }
148
149    /**
150     * @see org.opencms.widgets.I_CmsADEWidget#isInternal()
151     */
152    public boolean isInternal() {
153
154        return true;
155    }
156
157    /**
158     * @see org.opencms.widgets.I_CmsWidget#newInstance()
159     */
160    public I_CmsWidget newInstance() {
161
162        return new CmsInputWidget(getConfiguration());
163    }
164}