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.gwt.shared.CmsGwtConstants; 033import org.opencms.i18n.CmsEncoder; 034import org.opencms.i18n.CmsMessages; 035import org.opencms.json.JSONObject; 036import org.opencms.main.CmsLog; 037import org.opencms.xml.content.I_CmsXmlContentHandler.DisplayType; 038import org.opencms.xml.types.A_CmsXmlContentValue; 039 040import java.util.Arrays; 041import java.util.List; 042import java.util.Locale; 043 044import org.apache.commons.logging.Log; 045 046/** 047 * Provides a standard HTML form input widget, for use on a widget dialog.<p> 048 * 049 * @since 6.0.0 050 */ 051public class CmsInputWidget extends A_CmsWidget implements I_CmsADEWidget { 052 053 /** Config value. */ 054 public static final String CONF_AUTO_TYPOGRAPHY = "auto-typography"; 055 056 /** Config value. */ 057 public static final String CONF_TYPOGRAPHY = "typography"; 058 059 /** Logger instance for this class. */ 060 private static final Log LOG = CmsLog.getLog(CmsInputWidget.class); 061 062 /** 063 * Creates a new input widget.<p> 064 */ 065 public CmsInputWidget() { 066 067 // empty constructor is required for class registration 068 this(""); 069 } 070 071 /** 072 * Creates a new input widget with the given configuration.<p> 073 * 074 * @param configuration the configuration to use 075 */ 076 public CmsInputWidget(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 String configStr = getConfiguration(); 092 if (configStr == null) { 093 configStr = ""; 094 } 095 String[] tokens = configStr.split("\\|"); 096 JSONObject json = new JSONObject(); 097 String typografLocale = CmsTextareaWidget.getTypografLocale(contentLocale); 098 for (String token : tokens) { 099 if (Arrays.asList(CONF_TYPOGRAPHY, CONF_AUTO_TYPOGRAPHY).contains(token)) { 100 try { 101 json.put(CmsGwtConstants.JSON_INPUT_TYPOGRAF, CONF_AUTO_TYPOGRAPHY.equals(token) ? "auto" : "true"); 102 json.put(CmsGwtConstants.JSON_INPUT_LOCALE, typografLocale); 103 } catch (Exception e) { 104 LOG.debug(e.getMessage(), e); 105 106 } 107 } 108 } 109 return json.toString(); 110 } 111 112 /** 113 * @see org.opencms.widgets.I_CmsADEWidget#getCssResourceLinks(org.opencms.file.CmsObject) 114 */ 115 public List<String> getCssResourceLinks(CmsObject cms) { 116 117 // not needed for internal widget 118 return null; 119 } 120 121 /** 122 * @see org.opencms.widgets.I_CmsADEWidget#getDefaultDisplayType() 123 */ 124 public DisplayType getDefaultDisplayType() { 125 126 return DisplayType.singleline; 127 } 128 129 /** 130 * @see org.opencms.widgets.I_CmsWidget#getDialogWidget(org.opencms.file.CmsObject, org.opencms.widgets.I_CmsWidgetDialog, org.opencms.widgets.I_CmsWidgetParameter) 131 */ 132 public String getDialogWidget(CmsObject cms, I_CmsWidgetDialog widgetDialog, I_CmsWidgetParameter param) { 133 134 String id = param.getId(); 135 136 StringBuffer result = new StringBuffer(16); 137 138 result.append("<td class=\"xmlTd\">"); 139 result.append("<input class=\"xmlInput textInput"); 140 if (param.hasError()) { 141 result.append(" xmlInputError"); 142 } 143 result.append("\""); 144 result.append(" name=\""); 145 result.append(id); 146 result.append("\" id=\""); 147 result.append(id); 148 result.append("\" value=\""); 149 result.append(CmsEncoder.escapeXml(param.getStringValue(cms))); 150 result.append("\">"); 151 result.append("</td>"); 152 153 return result.toString(); 154 } 155 156 /** 157 * @see org.opencms.widgets.I_CmsADEWidget#getInitCall() 158 */ 159 public String getInitCall() { 160 161 // not needed for internal widget 162 return null; 163 } 164 165 /** 166 * @see org.opencms.widgets.I_CmsADEWidget#getJavaScriptResourceLinks(org.opencms.file.CmsObject) 167 */ 168 public List<String> getJavaScriptResourceLinks(CmsObject cms) { 169 170 // not needed for internal widget 171 return null; 172 } 173 174 /** 175 * @see org.opencms.widgets.I_CmsADEWidget#getWidgetName() 176 */ 177 public String getWidgetName() { 178 179 return CmsInputWidget.class.getName(); 180 } 181 182 /** 183 * @see org.opencms.widgets.I_CmsADEWidget#isInternal() 184 */ 185 public boolean isInternal() { 186 187 return true; 188 } 189 190 /** 191 * @see org.opencms.widgets.I_CmsWidget#newInstance() 192 */ 193 public I_CmsWidget newInstance() { 194 195 return new CmsInputWidget(getConfiguration()); 196 } 197}