1 31 32 package org.opencms.widgets; 33 34 import org.opencms.main.OpenCms; 35 import org.opencms.util.CmsStringUtil; 36 37 import java.util.ArrayList ; 38 import java.util.Iterator ; 39 import java.util.List ; 40 41 74 public class CmsHtmlWidgetOption { 75 76 77 public static final String EDITOR_DEFAULTHEIGHT = "260px"; 78 79 80 public static final String OPTION_ANCHOR = "anchor"; 81 82 83 public static final String OPTION_CSS = "css:"; 84 85 86 public static final String OPTION_DELIMITER = ","; 87 88 89 public static final String OPTION_FORMATSELECT = "formatselect"; 90 91 92 public static final String OPTION_HEIGHT = "height:"; 93 94 95 public static final String OPTION_IMAGE = "image"; 96 97 98 public static final String OPTION_LINK = "link"; 99 100 101 public static final String OPTION_SOURCE = "source"; 102 103 104 public static final String OPTION_STYLES = "stylesxml:"; 105 106 107 public static final String OPTION_TABLE = "table"; 108 109 private String m_cssPath; 110 private List m_displayGalleries; 111 private String m_editorHeight; 112 private boolean m_showAnchorDialog; 113 private boolean m_showFormatSelect; 114 private boolean m_showImageDialog; 115 private boolean m_showLinkDialog; 116 private boolean m_showSourceEditor; 117 private boolean m_showTableDialog; 118 private String m_stylesXmlPath; 119 120 123 public CmsHtmlWidgetOption() { 124 125 m_displayGalleries = new ArrayList (); 127 m_editorHeight = EDITOR_DEFAULTHEIGHT; 128 } 129 130 135 public CmsHtmlWidgetOption(String configuration) { 136 137 m_displayGalleries = new ArrayList (); 139 m_editorHeight = EDITOR_DEFAULTHEIGHT; 140 parseOptions(configuration); 141 } 142 143 150 public static String createConfigurationString(CmsHtmlWidgetOption option) { 151 152 StringBuffer result = new StringBuffer (512); 153 boolean added = false; 154 if (!option.getEditorHeight().equals(EDITOR_DEFAULTHEIGHT)) { 155 result.append(OPTION_HEIGHT); 157 result.append(option.getEditorHeight()); 158 added = true; 159 } 160 if (option.showAnchorDialog()) { 161 if (added) { 163 result.append(OPTION_DELIMITER); 164 } 165 result.append(OPTION_ANCHOR); 166 added = true; 167 } 168 if (option.showLinkDialog()) { 169 if (added) { 171 result.append(OPTION_DELIMITER); 172 } 173 result.append(OPTION_LINK); 174 added = true; 175 } 176 if (option.showFormatSelect()) { 177 if (added) { 179 result.append(OPTION_DELIMITER); 180 } 181 result.append(OPTION_FORMATSELECT); 182 added = true; 183 } 184 if (option.showSourceEditor()) { 185 if (added) { 187 result.append(OPTION_DELIMITER); 188 } 189 result.append(OPTION_SOURCE); 190 added = true; 191 } 192 if (option.showTableDialog()) { 193 if (added) { 195 result.append(OPTION_DELIMITER); 196 } 197 result.append(OPTION_TABLE); 198 added = true; 199 } 200 if (option.showImageDialog()) { 201 if (added) { 203 result.append(OPTION_DELIMITER); 204 } 205 result.append(OPTION_IMAGE); 206 added = true; 207 } 208 if (option.useCss()) { 209 if (added) { 211 result.append(OPTION_DELIMITER); 212 } 213 result.append(OPTION_CSS); 214 result.append(option.getCssPath()); 215 added = true; 216 } 217 if (option.showStylesXml()) { 218 if (added) { 220 result.append(OPTION_DELIMITER); 221 } 222 result.append(OPTION_STYLES); 223 result.append(option.getStylesXmlPath()); 224 added = true; 225 } 226 227 boolean isFirst = true; 228 for (int i = 0; i < option.getDisplayGalleries().size(); i++) { 229 String gallery = (String )option.getDisplayGalleries().get(i); 231 if (added || !isFirst) { 232 result.append(OPTION_DELIMITER); 233 } 234 result.append(gallery); 235 isFirst = false; 236 } 237 238 return result.toString(); 239 } 240 241 246 public String getCssPath() { 247 248 return m_cssPath; 249 } 250 251 256 public List getDisplayGalleries() { 257 258 return m_displayGalleries; 259 } 260 261 266 public String getEditorHeight() { 267 268 return m_editorHeight; 269 } 270 271 276 public String getStylesXmlPath() { 277 278 return m_stylesXmlPath; 279 } 280 281 286 public void setCssPath(String cssPath) { 287 288 m_cssPath = cssPath; 289 } 290 291 296 public void setDisplayGalleries(List displayGalleries) { 297 298 m_displayGalleries = displayGalleries; 299 } 300 301 306 public void setEditorHeight(String editorHeight) { 307 308 m_editorHeight = editorHeight; 309 } 310 311 316 public void setShowAnchorDialog(boolean showAnchorDialog) { 317 318 m_showAnchorDialog = showAnchorDialog; 319 } 320 321 326 public void setShowFormatSelect(boolean showFormatSelect) { 327 328 m_showFormatSelect = showFormatSelect; 329 } 330 331 336 public void setShowImageDialog(boolean showImageDialog) { 337 338 m_showImageDialog = showImageDialog; 339 } 340 341 346 public void setShowLinkDialog(boolean showLinkDialog) { 347 348 m_showLinkDialog = showLinkDialog; 349 } 350 351 356 public void setShowSourceEditor(boolean showSourceEditor) { 357 358 m_showSourceEditor = showSourceEditor; 359 } 360 361 366 public void setShowTableDialog(boolean showTableDialog) { 367 368 m_showTableDialog = showTableDialog; 369 } 370 371 376 public void setStylesXmlPath(String stylesXmlPath) { 377 378 m_stylesXmlPath = stylesXmlPath; 379 } 380 381 386 public boolean showAnchorDialog() { 387 388 return m_showAnchorDialog; 389 } 390 391 396 public boolean showFormatSelect() { 397 398 return m_showFormatSelect; 399 } 400 401 407 public boolean showGalleryDialog(String galleryType) { 408 409 return getDisplayGalleries().contains(galleryType); 410 } 411 412 417 public boolean showImageDialog() { 418 419 return m_showImageDialog; 420 } 421 422 427 public boolean showLinkDialog() { 428 429 return m_showLinkDialog; 430 } 431 432 437 public boolean showSourceEditor() { 438 439 return m_showSourceEditor; 440 } 441 442 447 public boolean showStylesXml() { 448 449 return CmsStringUtil.isNotEmpty(getStylesXmlPath()); 450 } 451 452 457 public boolean showTableDialog() { 458 459 return m_showTableDialog; 460 } 461 462 467 public boolean useCss() { 468 469 return CmsStringUtil.isNotEmpty(getCssPath()); 470 } 471 472 477 protected void parseOptions(String configuration) { 478 479 if (CmsStringUtil.isNotEmpty(configuration)) { 480 List options = CmsStringUtil.splitAsList(configuration, OPTION_DELIMITER, true); 481 Iterator i = options.iterator(); 482 while (i.hasNext()) { 483 String option = (String )i.next(); 484 if (OPTION_LINK.equals(option)) { 485 setShowLinkDialog(true); 487 } else if (OPTION_ANCHOR.equals(option)) { 488 setShowAnchorDialog(true); 490 } else if (OPTION_SOURCE.equals(option)) { 491 setShowSourceEditor(true); 493 } else if (OPTION_FORMATSELECT.equals(option)) { 494 setShowFormatSelect(true); 496 } else if (OPTION_IMAGE.equals(option)) { 497 setShowImageDialog(true); 499 } else if (OPTION_TABLE.equals(option)) { 500 setShowTableDialog(true); 502 } else if (option.startsWith(OPTION_HEIGHT)) { 503 option = option.substring(OPTION_HEIGHT.length()); 505 if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(option)) { 506 setEditorHeight(option); 507 } 508 } else if (option.startsWith(OPTION_CSS)) { 509 option = option.substring(OPTION_CSS.length()); 511 setCssPath(option); 512 } else if (option.startsWith(OPTION_STYLES)) { 513 option = option.substring(OPTION_STYLES.length()); 515 setStylesXmlPath(option); 516 } else { 517 if (OpenCms.getWorkplaceManager().getGalleries().get(option) != null) { 519 m_displayGalleries.add(option); 521 } 522 } 523 } 524 } 525 } 526 527 } | Popular Tags |