1 31 32 package org.opencms.widgets; 33 34 import org.opencms.file.CmsObject; 35 import org.opencms.i18n.CmsEncoder; 36 import org.opencms.main.CmsLog; 37 import org.opencms.main.OpenCms; 38 import org.opencms.util.CmsStringUtil; 39 40 import java.util.Map ; 41 42 import org.apache.commons.logging.Log; 43 44 55 public class CmsHtmlWidget extends A_CmsHtmlWidget { 56 57 58 private static final Log LOG = CmsLog.getLog(CmsHtmlWidget.class); 59 60 61 private I_CmsWidget m_editorWidget; 62 63 66 public CmsHtmlWidget() { 67 68 this(""); 70 } 71 72 77 public CmsHtmlWidget(CmsHtmlWidgetOption configuration) { 78 79 super(configuration); 80 } 81 82 87 public CmsHtmlWidget(String configuration) { 88 89 super(configuration); 90 } 91 92 95 public String getDialogIncludes(CmsObject cms, I_CmsWidgetDialog widgetDialog) { 96 97 return getEditorWidget(cms, widgetDialog).getDialogIncludes(cms, widgetDialog); 98 } 99 100 103 public String getDialogInitCall(CmsObject cms, I_CmsWidgetDialog widgetDialog) { 104 105 return getEditorWidget(cms, widgetDialog).getDialogInitCall(cms, widgetDialog); 106 } 107 108 111 public String getDialogInitMethod(CmsObject cms, I_CmsWidgetDialog widgetDialog) { 112 113 return getEditorWidget(cms, widgetDialog).getDialogInitMethod(cms, widgetDialog); 114 } 115 116 119 public String getDialogWidget(CmsObject cms, I_CmsWidgetDialog widgetDialog, I_CmsWidgetParameter param) { 120 121 return getEditorWidget(cms, widgetDialog).getDialogWidget(cms, widgetDialog, param); 122 } 123 124 127 public I_CmsWidget newInstance() { 128 129 return new CmsHtmlWidget(getConfiguration()); 130 } 131 132 135 public void setEditorValue( 136 CmsObject cms, 137 Map formParameters, 138 I_CmsWidgetDialog widgetDialog, 139 I_CmsWidgetParameter param) { 140 141 String [] values = (String [])formParameters.get(param.getId()); 142 if ((values != null) && (values.length > 0)) { 143 String val = CmsEncoder.decode(values[0], CmsEncoder.ENCODING_UTF_8); 144 param.setStringValue(cms, val); 145 } 146 } 147 148 155 private I_CmsWidget getEditorWidget(CmsObject cms, I_CmsWidgetDialog widgetDialog) { 156 157 if (m_editorWidget == null) { 158 String widgetClassName = OpenCms.getWorkplaceManager().getWorkplaceEditorManager().getWidgetEditor( 160 cms.getRequestContext(), 161 widgetDialog.getUserAgent()); 162 boolean foundWidget = true; 163 if (CmsStringUtil.isEmpty(widgetClassName)) { 164 widgetClassName = CmsTextareaWidget.class.getName(); 166 foundWidget = false; 167 } 168 try { 169 if (foundWidget) { 170 Class widgetClass = Class.forName(widgetClassName); 172 A_CmsHtmlWidget editorWidget = (A_CmsHtmlWidget)widgetClass.newInstance(); 173 editorWidget.setHtmlWidgetOption(getHtmlWidgetOption()); 174 m_editorWidget = editorWidget; 175 } else { 176 Class widgetClass = Class.forName(widgetClassName); 178 I_CmsWidget editorWidget = (I_CmsWidget)widgetClass.newInstance(); 179 editorWidget.setConfiguration("15"); 180 m_editorWidget = editorWidget; 181 } 182 } catch (Exception e) { 183 LOG.error(Messages.get().container(Messages.LOG_CREATE_HTMLWIDGET_INSTANCE_FAILED_1, widgetClassName).key()); 185 } 186 187 } 188 return m_editorWidget; 189 } 190 } | Popular Tags |