1 31 32 package org.opencms.editors.fckeditor; 33 34 import org.opencms.file.CmsObject; 35 import org.opencms.i18n.CmsEncoder; 36 import org.opencms.main.OpenCms; 37 import org.opencms.util.CmsStringUtil; 38 import org.opencms.widgets.A_CmsHtmlWidget; 39 import org.opencms.widgets.CmsHtmlWidgetOption; 40 import org.opencms.widgets.I_CmsWidget; 41 import org.opencms.widgets.I_CmsWidgetDialog; 42 import org.opencms.widgets.I_CmsWidgetParameter; 43 import org.opencms.workplace.CmsWorkplace; 44 import org.opencms.workplace.editors.CmsEditor; 45 import org.opencms.workplace.galleries.A_CmsGallery; 46 47 import java.util.ArrayList ; 48 import java.util.Collections ; 49 import java.util.HashMap ; 50 import java.util.Iterator ; 51 import java.util.List ; 52 import java.util.Map ; 53 54 65 public class CmsFCKEditorWidget extends A_CmsHtmlWidget { 66 67 68 public static final String PARAM_CONFIGURATION = "config"; 69 70 73 public CmsFCKEditorWidget() { 74 75 this(""); 77 } 78 79 84 public CmsFCKEditorWidget(CmsHtmlWidgetOption configuration) { 85 86 super(configuration); 87 } 88 89 94 public CmsFCKEditorWidget(String configuration) { 95 96 super(configuration); 97 } 98 99 106 public static boolean buildOpenCmsButtonRow(StringBuffer toolbar, String widgetOptionsString) { 107 108 boolean buttonRendered = false; 109 110 if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(widgetOptionsString)) { 111 CmsHtmlWidgetOption option = new CmsHtmlWidgetOption(widgetOptionsString); 113 StringBuffer custom = new StringBuffer (512); 114 115 if (option.showSourceEditor()) { 117 custom.append("\"Source\""); 118 buttonRendered = true; 119 } 120 121 boolean showFormatSelect = false; 123 if (option.showFormatSelect()) { 124 if (buttonRendered) { 125 custom.append(",\"-\","); 126 } 127 custom.append("\"FontFormat\""); 128 buttonRendered = true; 129 showFormatSelect = true; 130 } 131 132 if (option.showStylesXml()) { 134 if (!showFormatSelect && buttonRendered) { 135 custom.append(",\"-\","); 136 } else if (buttonRendered) { 137 custom.append(","); 138 } 139 custom.append("\"Style\""); 140 buttonRendered = true; 141 } 142 143 boolean showLink = false; 145 if (option.showLinkDialog()) { 146 if (buttonRendered) { 147 custom.append(","); 148 } 149 custom.append("\"oc-link\""); 150 buttonRendered = true; 151 showLink = true; 152 } 153 if (option.showAnchorDialog()) { 154 if (buttonRendered) { 155 custom.append(","); 156 } 157 custom.append("\"Anchor\""); 158 buttonRendered = true; 159 showLink = true; 160 } 161 if (showLink) { 162 custom.append(", \"Unlink\""); 164 } 165 166 Map galleryMap = OpenCms.getWorkplaceManager().getGalleries(); 168 List galleries = new ArrayList (galleryMap.size()); 169 Map typeMap = new HashMap (galleryMap.size()); 170 171 Iterator i = galleryMap.entrySet().iterator(); 172 while (i.hasNext()) { 173 Map.Entry entry = (Map.Entry )i.next(); 174 String key = (String )entry.getKey(); 175 A_CmsGallery currGallery = (A_CmsGallery)entry.getValue(); 176 galleries.add(currGallery); 177 typeMap.put(currGallery, key); 179 } 180 181 Collections.sort(galleries); 183 184 StringBuffer galleryResult = new StringBuffer (8); 185 boolean showGallery = false; 186 for (int k = 0; k < galleries.size(); k++) { 187 A_CmsGallery currGallery = (A_CmsGallery)galleries.get(k); 188 String galleryType = (String )typeMap.get(currGallery); 189 if (option.getDisplayGalleries().contains(galleryType)) { 190 if (galleryResult.length() > 0) { 192 galleryResult.append(", "); 193 } 194 galleryResult.append("\"oc-"); 195 galleryResult.append(galleryType); 196 galleryResult.append("\""); 197 showGallery = true; 198 } 199 } 200 201 if (showGallery) { 202 if (buttonRendered) { 204 custom.append("],["); 205 } 206 custom.append(galleryResult); 207 buttonRendered = true; 208 } 209 210 if (option.showImageDialog()) { 212 if (buttonRendered) { 213 custom.append(",\"-\","); 214 } 215 custom.append("\"Image\""); 216 buttonRendered = true; 217 } 218 219 if (option.showTableDialog()) { 221 if (buttonRendered) { 222 custom.append(",\"-\","); 223 } 224 custom.append("\"Table\""); 225 buttonRendered = true; 226 } 227 228 if (buttonRendered) { 229 custom.insert(0, ",["); 231 toolbar.append(custom); 233 } 234 235 } 236 237 return buttonRendered; 238 } 239 240 247 protected static boolean showButton(String buttonName, List widgetOptions) { 248 249 return (widgetOptions.contains(buttonName)); 250 } 251 252 255 public String getDialogIncludes(CmsObject cms, I_CmsWidgetDialog widgetDialog) { 256 257 StringBuffer result = new StringBuffer (128); 258 result.append(getJSIncludeFile(CmsWorkplace.getSkinUri() + "editors/fckeditor/fckeditor.js")); 260 result.append("\n"); 261 result.append(getJSIncludeFile(CmsWorkplace.getSkinUri() + "components/widgets/fckeditor.js")); 263 return result.toString(); 264 } 265 266 269 public String getDialogInitCall(CmsObject cms, I_CmsWidgetDialog widgetDialog) { 270 271 return "\tinitFCKeditor();\n"; 273 } 274 275 278 public String getDialogInitMethod(CmsObject cms, I_CmsWidgetDialog widgetDialog) { 279 280 StringBuffer result = new StringBuffer (64); 281 result.append("function initFCKeditor() {\n"); 282 result.append("\tif (navigator.userAgent.toLowerCase().indexOf(\"msie\") != -1) {\n"); 284 result.append("\t\tsetTimeout(\"generateEditors();\", 50);\n"); 285 result.append("\t} else {"); 286 result.append("\t\tgenerateEditors();\n"); 287 result.append("\t}\n"); 288 result.append("}\n"); 289 return result.toString(); 290 } 291 292 295 public String getDialogWidget(CmsObject cms, I_CmsWidgetDialog widgetDialog, I_CmsWidgetParameter param) { 296 297 String id = param.getId(); 298 String value = param.getStringValue(cms); 299 StringBuffer result = new StringBuffer (4096); 300 301 result.append("<td class=\"xmlTd\">"); 302 303 result.append("<textarea class=\"xmlInput maxwidth\" name=\"ta_"); 304 result.append(id); 305 result.append("\" id=\"ta_"); 306 result.append(id); 307 result.append("\" style=\"height: "); 308 result.append(getHtmlWidgetOption().getEditorHeight()); 309 result.append(";\" rows=\"20\" cols=\"60\">"); 310 result.append(CmsEncoder.escapeXml(value)); 311 result.append("</textarea>"); 312 result.append("<input type=\"hidden\" name=\""); 313 result.append(id); 314 result.append("\" id=\""); 315 result.append(id); 316 result.append("\" value=\""); 317 result.append(CmsEncoder.encode(value)); 318 result.append("\">"); 319 320 result.append("<script type=\"text/javascript\">\n"); 322 result.append("var editor = new FCKeditor(\"ta_").append(id).append("\");\n"); 323 result.append("editor.BasePath = \"").append(CmsWorkplace.getSkinUri()).append("editors/fckeditor/\";\n"); 324 325 if (getHtmlWidgetOption().useCss()) { 327 result.append("editor.Config[\"EditorAreaCSS\"] = \""); 328 result.append(OpenCms.getLinkManager().substituteLink(cms, getHtmlWidgetOption().getCssPath())); 329 result.append("\";\n"); 330 getHtmlWidgetOption().setCssPath(null); 332 } 333 334 if (getHtmlWidgetOption().showStylesXml()) { 336 result.append("editor.Config[\"StylesXmlPath\"] = \""); 337 result.append(OpenCms.getLinkManager().substituteLink(cms, getHtmlWidgetOption().getStylesXmlPath())); 338 result.append("\";\n"); 339 getHtmlWidgetOption().setStylesXmlPath("true"); 341 } 342 343 result.append("editor.Width = \"100%\";\n"); 344 result.append("editor.Height = \"").append(getHtmlWidgetOption().getEditorHeight()).append("\";\n"); 345 result.append("editor.ToolbarSet = \"OpenCmsWidget\";\n"); 346 347 StringBuffer configJs = new StringBuffer (128); 349 configJs.append(CmsEditor.PATH_EDITORS); 350 configJs.append("fckeditor/configwidget.js"); 351 configJs.append("?"); 352 configJs.append(PARAM_CONFIGURATION); 353 configJs.append("="); 354 configJs.append(CmsHtmlWidgetOption.createConfigurationString(getHtmlWidgetOption())); 355 result.append("editor.Config[\"CustomConfigurationsPath\"] = \""); 356 result.append(OpenCms.getLinkManager().substituteLink(cms, configJs.toString())); 357 result.append("\";\n"); 358 result.append("editorInstances[editorInstances.length] = editor;\n"); 359 result.append("contentFields[contentFields.length] = document.getElementById(\"").append(id).append("\");\n"); 360 result.append("</script>\n"); 361 362 result.append("</td>"); 363 364 return result.toString(); 365 } 366 367 370 public I_CmsWidget newInstance() { 371 372 return new CmsFCKEditorWidget(getHtmlWidgetOption()); 373 } 374 375 } | Popular Tags |