1 31 32 package org.opencms.editors.htmlarea; 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.galleries.A_CmsGallery; 45 46 import java.util.ArrayList ; 47 import java.util.Collections ; 48 import java.util.HashMap ; 49 import java.util.Iterator ; 50 import java.util.List ; 51 import java.util.Locale ; 52 import java.util.Map ; 53 54 64 public class CmsHtmlAreaWidget extends A_CmsHtmlWidget { 65 66 67 public static final String HTMLAREA_LOCALES_VFS = CmsWorkplace.VFS_PATH_WORKPLACE 68 + "resources/editors/htmlarea/lang/"; 69 70 73 public CmsHtmlAreaWidget() { 74 75 this(""); 77 } 78 79 84 public CmsHtmlAreaWidget(CmsHtmlWidgetOption configuration) { 85 86 super(configuration); 87 } 88 89 94 public CmsHtmlAreaWidget(String configuration) { 95 96 super(configuration); 97 } 98 99 106 public static Locale getHtmlAreaLocale(CmsObject cms, Locale wantedLocale) { 107 108 if (!cms.existsResource(HTMLAREA_LOCALES_VFS + wantedLocale.toString() + ".js")) { 110 boolean foundLocale = false; 111 Iterator i = OpenCms.getLocaleManager().getDefaultLocales().iterator(); 112 while (i.hasNext()) { 114 wantedLocale = (Locale )i.next(); 115 if (cms.existsResource(HTMLAREA_LOCALES_VFS + wantedLocale.toString() + ".js")) { 116 foundLocale = true; 118 break; 119 } 120 } 121 if (!foundLocale) { 122 wantedLocale = Locale.ENGLISH; 124 } 125 } 126 return wantedLocale; 127 } 128 129 132 public String getDialogIncludes(CmsObject cms, I_CmsWidgetDialog widgetDialog) { 133 134 StringBuffer result = new StringBuffer (16); 135 result.append("<script type=\"text/javascript\">\n<!--\n"); 136 result.append("\tvar _editor_url = \""); 137 result.append(CmsWorkplace.getSkinUri()); 138 result.append("editors/htmlarea/\";\n"); 139 result.append("\tvar _editor_lang = \""); 140 result.append(getHtmlAreaLocale(cms, widgetDialog.getLocale())); 141 result.append("\";\n"); 142 result.append("//-->\n</script>\n"); 143 result.append(getJSIncludeFile(CmsWorkplace.getSkinUri() + "editors/htmlarea/htmlarea.js")); 145 result.append("\n"); 146 result.append(getJSIncludeFile(CmsWorkplace.getSkinUri() + "editors/htmlarea/htmlarea-ocms.js")); 148 result.append("\n"); 149 result.append(getJSIncludeFile(CmsWorkplace.getSkinUri() + "components/widgets/htmlarea.js")); 151 return result.toString(); 152 } 153 154 157 public String getDialogInitCall(CmsObject cms, I_CmsWidgetDialog widgetDialog) { 158 159 return "\tinitHtmlArea();\n"; 161 } 162 163 166 public String getDialogInitMethod(CmsObject cms, I_CmsWidgetDialog widgetDialog) { 167 168 StringBuffer result = new StringBuffer (8); 169 result.append("function initHtmlArea() {\n"); 170 result.append("\tgenerateHtmlAreas();\n"); 171 result.append("}\n\n"); 172 result.append("function configHtmlAreaToolbar(currentConf) {\n"); 174 result.append(buildOpenCmsButtons(widgetDialog)); 175 result.append("}\n"); 176 return result.toString(); 177 } 178 179 182 public String getDialogWidget(CmsObject cms, I_CmsWidgetDialog widgetDialog, I_CmsWidgetParameter param) { 183 184 String id = param.getId(); 185 StringBuffer result = new StringBuffer (128); 186 187 result.append("<td class=\"xmlTd\">"); 188 189 result.append("<textarea class=\"xmlInput maxwidth\" name=\""); 190 result.append(id); 191 result.append("\" id=\""); 192 result.append(id); 193 result.append("\" style=\"height: "); 194 result.append(getHtmlWidgetOption().getEditorHeight()); 195 result.append(";\" rows=\"20\" cols=\"60\">"); 196 result.append(CmsEncoder.escapeXml(param.getStringValue(cms))); 197 result.append("</textarea>"); 198 199 result.append("<script type=\"text/javascript\">\n<!--\n"); 201 result.append("\tconfig = getHtmlAreaConfiguration();\n"); 202 203 if (getHtmlWidgetOption().useCss()) { 205 result.append("config.pageStyle = \"@import url("); 206 result.append(OpenCms.getLinkManager().substituteLink(cms, getHtmlWidgetOption().getCssPath())); 207 result.append(");\";\n"); 208 getHtmlWidgetOption().setCssPath(null); 209 } 210 211 result.append("\tconfigHtmlAreaToolbar(config);\n"); 212 result.append(buildOpenCmsButtonRow()); 214 result.append("\n\thtmlAreaConfigs[\""); 215 result.append(id); 216 result.append("\"] = config;\n"); 217 result.append("//-->\n</script>\n"); 218 219 result.append("</td>"); 220 221 return result.toString(); 222 } 223 224 227 public I_CmsWidget newInstance() { 228 229 return new CmsHtmlAreaWidget(getHtmlWidgetOption()); 230 } 231 232 237 protected String buildOpenCmsButtonRow() { 238 239 StringBuffer result = new StringBuffer (16); 240 241 result.append("\tconfig.toolbar = [\n"); 242 result.append("\t\t[\n"); 243 result.append("\t\t\t\"copy\", \"cut\", \"paste\", \"separator\",\n"); 244 result.append("\t\t\t"); 245 if (getHtmlWidgetOption().showFormatSelect()) { 247 result.append("\"formatblock\", \"space\", "); 248 } 249 result.append("\"bold\", \"italic\", \"underline\", \"separator\",\n"); 250 result.append("\t\t\t\"strikethrough\", \"subscript\", \"superscript\", \"separator\",\n"); 251 result.append("\t\t\t\"justifyleft\", \"justifycenter\", \"justifyright\", \"justifyfull\", \"separator\",\n"); 252 result.append("\t\t\t\"insertorderedlist\", \"insertunorderedlist\", \"outdent\", \"indent\""); 253 254 boolean showLink = false; 256 StringBuffer custom = new StringBuffer (8); 257 if (getHtmlWidgetOption().showLinkDialog()) { 258 custom.append("\"oc-link\""); 259 showLink = true; 260 } 261 if (getHtmlWidgetOption().showAnchorDialog()) { 262 if (showLink) { 263 custom.append(", "); 264 } 265 custom.append("\"oc-anchor\""); 266 showLink = true; 267 } 268 if (showLink) { 269 result.append(", \"separator\",\n\t\t\t"); 270 result.append(custom); 271 } 272 273 Map galleryMap = OpenCms.getWorkplaceManager().getGalleries(); 275 List galleries = new ArrayList (galleryMap.size()); 276 Map typeMap = new HashMap (galleryMap.size()); 277 278 Iterator i = galleryMap.entrySet().iterator(); 279 while (i.hasNext()) { 280 Map.Entry entry = (Map.Entry )i.next(); 281 String key = (String )entry.getKey(); 282 A_CmsGallery currGallery = (A_CmsGallery)entry.getValue(); 283 galleries.add(currGallery); 284 typeMap.put(currGallery, key); 286 } 287 288 Collections.sort(galleries); 290 291 StringBuffer galleryResult = new StringBuffer (8); 292 boolean showGallery = false; 293 for (int k = 0; k < galleries.size(); k++) { 294 A_CmsGallery currGallery = (A_CmsGallery)galleries.get(k); 295 String galleryType = (String )typeMap.get(currGallery); 296 if (getHtmlWidgetOption().showGalleryDialog(galleryType)) { 297 if (galleryResult.length() > 0) { 299 galleryResult.append(", "); 300 } 301 galleryResult.append("\""); 302 galleryResult.append(galleryType); 303 galleryResult.append("\""); 304 showGallery = true; 305 } 306 } 307 308 if (showGallery) { 309 result.append(", \"separator\",\n\t\t\t"); 310 result.append(galleryResult); 311 } 312 313 if (getHtmlWidgetOption().showImageDialog()) { 315 result.append(", \"separator\",\n\t\t\t\"insertimage\"\n"); 316 } 317 318 if (getHtmlWidgetOption().showTableDialog()) { 320 result.append(", \"separator\",\n\t\t\t\"inserttable\"\n"); 321 } 322 323 if (getHtmlWidgetOption().showSourceEditor()) { 325 result.append(", \"separator\",\n\t\t\t\"htmlmode\"\n"); 326 } 327 328 result.append("\t\t]\n\t];"); 329 return result.toString(); 330 } 331 332 338 protected String buildOpenCmsButtons(I_CmsWidgetDialog widgetDialog) { 339 340 StringBuffer result = new StringBuffer (); 341 342 result.append("\tconfig.registerButton(\""); 344 result.append("oc-link"); 345 result.append("\", \""); 346 result.append(widgetDialog.getMessages().key("button.linkto")); 347 result.append("\", _editor_url + \"../../buttons/link.png"); 348 result.append("\", false, function(e) { setActiveEditor(e); openLinkDialog(\'"); 349 result.append(widgetDialog.getMessages().key("editor.message.noselection")); 350 result.append("\'); });\n"); 351 352 result.append("\tconfig.registerButton(\""); 354 result.append("oc-anchor"); 355 result.append("\", \""); 356 result.append(widgetDialog.getMessages().key("button.anchor")); 357 result.append("\", _editor_url + \"../../buttons/anchor.png"); 358 result.append("\", false, function(e) { setActiveEditor(e); openAnchorDialog(\'"); 359 result.append(widgetDialog.getMessages().key("editor.message.noselection")); 360 result.append("\'); });\n"); 361 362 Iterator i = OpenCms.getWorkplaceManager().getGalleries().keySet().iterator(); 364 while (i.hasNext()) { 365 String galleryType = (String )i.next(); 366 String galleryName = CmsStringUtil.substitute(galleryType, "gallery", ""); 367 result.append("\tconfig.registerButton(\""); 369 result.append(galleryType); 370 result.append("\", \""); 371 result.append(widgetDialog.getMessages().key("button." + galleryName + "list")); 372 result.append("\", _editor_url + \"/images/opencms/"); 373 result.append(galleryType); 374 result.append(".gif\", false, function(e) { setActiveEditor(e); openGallery(\'"); 375 result.append(galleryType); 376 result.append("\'); });\n"); 377 } 378 379 return result.toString(); 380 } 381 } | Popular Tags |