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.configuration; 029 030import org.opencms.configuration.preferences.CmsBuiltinPreference; 031import org.opencms.configuration.preferences.CmsEditorPreference; 032import org.opencms.configuration.preferences.CmsPreferenceData; 033import org.opencms.configuration.preferences.CmsStartGallleryPreference; 034import org.opencms.configuration.preferences.CmsUserDefinedPreference; 035import org.opencms.configuration.preferences.CmsUserSettingsStringPropertyWrapper; 036import org.opencms.configuration.preferences.CmsWrapperPreference; 037import org.opencms.configuration.preferences.I_CmsPreference; 038import org.opencms.configuration.preferences.PrefMetadata; 039import org.opencms.db.CmsUserSettings; 040import org.opencms.file.CmsResource; 041import org.opencms.file.CmsResource.CmsResourceCopyMode; 042import org.opencms.file.CmsResource.CmsResourceDeleteMode; 043import org.opencms.i18n.CmsLocaleManager; 044import org.opencms.main.CmsLog; 045import org.opencms.util.A_CmsModeStringEnumeration; 046import org.opencms.util.CmsStringUtil; 047import org.opencms.workplace.CmsWorkplaceManager; 048import org.opencms.xml.content.CmsXmlContentProperty; 049 050import java.beans.PropertyDescriptor; 051import java.lang.reflect.Constructor; 052import java.lang.reflect.Method; 053import java.util.ArrayList; 054import java.util.Arrays; 055import java.util.Collections; 056import java.util.HashMap; 057import java.util.LinkedHashMap; 058import java.util.List; 059import java.util.Map; 060 061import org.apache.commons.beanutils.PropertyUtils; 062import org.apache.commons.logging.Log; 063 064/** 065 * Default user workplace settings, used as default values for worklace settings in the 066 * user preferences.<p> 067 * 068 * @since 6.0.0 069 */ 070public class CmsDefaultUserSettings extends CmsUserSettings { 071 072 /** 073 * Enumeration class for defining the publish related resources mode.<p> 074 */ 075 public static final class CmsPublishRelatedResourcesMode extends A_CmsModeStringEnumeration { 076 077 /** Constant for the publish related resources mode, checkbox disabled by default. */ 078 protected static final CmsPublishRelatedResourcesMode MODE_FALSE = new CmsPublishRelatedResourcesMode( 079 CmsStringUtil.FALSE); 080 081 /** 082 * Constant for the publish related resources mode, only {@link org.opencms.security.CmsRole#VFS_MANAGER}s 083 * may publish resources without publishing the related resources. 084 */ 085 protected static final CmsPublishRelatedResourcesMode MODE_FORCE = new CmsPublishRelatedResourcesMode("FORCE"); 086 087 /** Constant for the publish related resources mode, checkbox enabled by default. */ 088 protected static final CmsPublishRelatedResourcesMode MODE_TRUE = new CmsPublishRelatedResourcesMode( 089 CmsStringUtil.TRUE); 090 091 /** The serial version id. */ 092 private static final long serialVersionUID = -2665888243460791770L; 093 094 /** 095 * Default constructor.<p> 096 * 097 * @param mode string representation 098 */ 099 private CmsPublishRelatedResourcesMode(String mode) { 100 101 super(mode); 102 } 103 104 /** 105 * Returns the parsed mode object if the string representation matches, or <code>null</code> if not.<p> 106 * 107 * @param publishRelatedResourcesMode the string representation to parse 108 * 109 * @return the parsed mode object 110 */ 111 public static CmsPublishRelatedResourcesMode valueOf(String publishRelatedResourcesMode) { 112 113 if (publishRelatedResourcesMode == null) { 114 return null; 115 } 116 if (publishRelatedResourcesMode.equalsIgnoreCase(MODE_FALSE.getMode())) { 117 return MODE_FALSE; 118 } 119 if (publishRelatedResourcesMode.equalsIgnoreCase(MODE_TRUE.getMode())) { 120 return MODE_TRUE; 121 } 122 if (publishRelatedResourcesMode.equalsIgnoreCase(MODE_FORCE.getMode())) { 123 return MODE_FORCE; 124 } 125 return null; 126 } 127 } 128 129 /** 130 * Enum for the subsitemap creation mode.<p> 131 */ 132 public enum SubsitemapCreationMode { 133 /** In this mode, existing folders are converted into subsitemaps. */ 134 convert, 135 136 /** In this mode, new subsitemap folders are created, giving the user a choice of which folder type they want to use. */ 137 createfolder 138 } 139 140 /** The current default user settings. */ 141 public static CmsDefaultUserSettings CURRENT_DEFAULT_SETTINGS; 142 143 /** Constant for the publish related resources mode, checkbox disabled by default. */ 144 public static final CmsPublishRelatedResourcesMode PUBLISH_RELATED_RESOURCES_MODE_FALSE = CmsPublishRelatedResourcesMode.MODE_FALSE; 145 146 /** 147 * Constant for the publish related resources mode, only {@link org.opencms.security.CmsRole#VFS_MANAGER}s 148 * may publish resources without publishing the related resources. 149 */ 150 public static final CmsPublishRelatedResourcesMode PUBLISH_RELATED_RESOURCES_MODE_FORCE = CmsPublishRelatedResourcesMode.MODE_FORCE; 151 152 /** Constant for the publish related resources mode, checkbox enabled by default. */ 153 public static final CmsPublishRelatedResourcesMode PUBLISH_RELATED_RESOURCES_MODE_TRUE = CmsPublishRelatedResourcesMode.MODE_TRUE; 154 155 /** Publish button appearance: show always. */ 156 public static final String PUBLISHBUTTON_SHOW_ALWAYS = "always"; 157 158 /** Publish button appearance: show auto (only if user has publish permissions). */ 159 public static final String PUBLISHBUTTON_SHOW_AUTO = "auto"; 160 161 /** Publish button appearance: show never. */ 162 public static final String PUBLISHBUTTON_SHOW_NEVER = "never"; 163 164 /** Array list for fast lookup of "button styles". */ 165 public static final List<String> BUTTON_STYLES_LIST = Collections.unmodifiableList( 166 Arrays.asList(new String[] {"image", "textimage", "text"})); 167 168 /** Parameter for buttonstyle text & image. */ 169 private static final int BUTTONSTYLE_TEXTIMAGE = 1; 170 171 /** Value for preserving siblings in copy dialog settings. */ 172 private static final String COPYMODE_PRESERVE = "preservesiblings"; 173 174 /** Value for creating a resource in copy dialog settings. */ 175 private static final String COPYMODE_RESOURCE = "createresource"; 176 177 /** Value for creating a sibling in copy dialog settings. */ 178 private static final String COPYMODE_SIBLING = "createsibling"; 179 180 /** Value for deleting siblings in delete dialog settings. */ 181 private static final String DELETEMODE_DELETE = "deletesiblings"; 182 183 /** Value for preserving siblings in delete dialog settings. */ 184 private static final String DELETEMODE_PRESERVE = "preservesiblings"; 185 186 /** The log object for this class. */ 187 private static final Log LOG = CmsLog.getLog(CmsDefaultUserSettings.class); 188 189 /** Value for publishing only resources in publish dialog settings. */ 190 private static final String PUBLISHMODE_ONLYRESOURCE = "onlyresource"; 191 192 /** Value for publishing siblings in publish dialog settings. */ 193 private static final String PUBLISHMODE_SIBLINGS = "allsiblings"; 194 195 /** The enable relation deletion flag. */ 196 private boolean m_allowBrokenRelations = true; 197 198 /** The configured preference data. */ 199 private List<CmsPreferenceData> m_preferenceData = new ArrayList<CmsPreferenceData>(); 200 201 /** Stores the preference objects, with the preference names as keys, in order. */ 202 private LinkedHashMap<String, I_CmsPreference> m_preferences = new LinkedHashMap<String, I_CmsPreference>(); 203 204 /** The publish related resources mode. */ 205 private CmsPublishRelatedResourcesMode m_publishRelatedResourcesMode; 206 207 /** The subsitemap creation mode. */ 208 private SubsitemapCreationMode m_subsitemapCreationMode; 209 210 /** 211 * Adds a preference.<p> 212 * 213 * @param name the name of the preference 214 * @param value the default value 215 * @param widget the widget to use for the preference 216 * @param widgetConfig the widget configuration 217 * @param niceName the nice name of the preference 218 * @param description the description of the preference 219 * @param ruleRegex the regex used for validation 220 * @param error the validation error message 221 * @param tab the tab to display the preference on 222 */ 223 public void addPreference( 224 String name, 225 String value, 226 String widget, 227 String widgetConfig, 228 String niceName, 229 String description, 230 String ruleRegex, 231 String error, 232 String tab) { 233 234 CmsXmlContentProperty prop = new CmsXmlContentProperty( 235 name, 236 "string", 237 widget, 238 widgetConfig, 239 ruleRegex, 240 null, 241 null, 242 niceName, 243 description, 244 error, 245 null); 246 CmsPreferenceData pref = new CmsPreferenceData(name, value, prop, tab); 247 m_preferenceData.add(pref); 248 } 249 250 /** 251 * Gets the default copy mode when copying a file of the user.<p> 252 * 253 * @return the default copy mode when copying a file of the user 254 */ 255 public String getDialogCopyFileModeString() { 256 257 if (getDialogCopyFileMode() == CmsResource.COPY_AS_NEW) { 258 return COPYMODE_RESOURCE; 259 } else { 260 return COPYMODE_SIBLING; 261 } 262 } 263 264 /** 265 * Gets the default copy mode when copying a folder of the user.<p> 266 * 267 * @return the default copy mode when copying a folder of the user 268 */ 269 public String getDialogCopyFolderModeString() { 270 271 if (getDialogCopyFolderMode() == CmsResource.COPY_AS_NEW) { 272 return COPYMODE_RESOURCE; 273 } else if (getDialogCopyFolderMode() == CmsResource.COPY_AS_SIBLING) { 274 return COPYMODE_SIBLING; 275 } else { 276 return COPYMODE_PRESERVE; 277 } 278 } 279 280 /** 281 * Returns the default setting for file deletion.<p> 282 * 283 * @return the default setting for file deletion 284 */ 285 public String getDialogDeleteFileModeString() { 286 287 if (getDialogDeleteFileMode() == CmsResource.DELETE_REMOVE_SIBLINGS) { 288 return DELETEMODE_DELETE; 289 } else { 290 return DELETEMODE_PRESERVE; 291 } 292 } 293 294 /** 295 * Returns the default setting for expanding inherited permissions in the dialog.<p> 296 * 297 * @return true if inherited permissions should be expanded, otherwise false 298 * 299 * @see #getDialogExpandInheritedPermissions() 300 */ 301 public String getDialogExpandInheritedPermissionsString() { 302 303 return String.valueOf(getDialogExpandInheritedPermissions()); 304 } 305 306 /** 307 * Returns the default setting for expanding the users permissions in the dialog.<p> 308 * 309 * @return true if the users permissions should be expanded, otherwise false 310 * 311 * @see #getDialogExpandUserPermissions() 312 */ 313 public String getDialogExpandUserPermissionsString() { 314 315 return String.valueOf(getDialogExpandUserPermissions()); 316 } 317 318 /** 319 * Returns the default setting for inheriting permissions on folders.<p> 320 * 321 * @return true if permissions should be inherited on folders, otherwise false 322 */ 323 public String getDialogPermissionsInheritOnFolderString() { 324 325 return String.valueOf(getDialogPermissionsInheritOnFolder()); 326 } 327 328 /** 329 * Returns the default setting for direct publishing.<p> 330 * 331 * @return the default setting for direct publishing 332 */ 333 public String getDialogPublishSiblingsString() { 334 335 if (getDialogPublishSiblings()) { 336 return PUBLISHMODE_SIBLINGS; 337 } else { 338 return PUBLISHMODE_ONLYRESOURCE; 339 } 340 } 341 342 /** 343 * Determines if the export settings part of the secure/export dialog should be shown.<p> 344 * 345 * @return true if the export dialog is shown, otherwise false 346 */ 347 public String getDialogShowExportSettingsString() { 348 349 return String.valueOf(getDialogShowExportSettings()); 350 } 351 352 /** 353 * Determines if the lock dialog should be shown.<p> 354 * 355 * @return true if the lock dialog is shown, otherwise false 356 */ 357 public String getDialogShowLockString() { 358 359 return String.valueOf(getDialogShowLock()); 360 } 361 362 /** 363 * Returns a string representation of the direct edit button style.<p> 364 * 365 * @return string representation of the direct edit button style 366 */ 367 public String getDirectEditButtonStyleString() { 368 369 return BUTTON_STYLES_LIST.get(getDirectEditButtonStyle()); 370 } 371 372 /** 373 * Returns a string representation of the editor button style.<p> 374 * 375 * @return string representation of the editor button style 376 */ 377 public String getEditorButtonStyleString() { 378 379 return BUTTON_STYLES_LIST.get(getEditorButtonStyle()); 380 } 381 382 /** 383 * Returns a string representation of the explorer button style.<p> 384 * 385 * @return string representation of the explorer button style 386 */ 387 public String getExplorerButtonStyleString() { 388 389 return BUTTON_STYLES_LIST.get(getExplorerButtonStyle()); 390 } 391 392 /** 393 * Returns a string representation of the list all projects flag.<p> 394 * 395 * @return string representation of the list all projects flag 396 * 397 * @see #getListAllProjects() 398 */ 399 public String getListAllProjectsString() { 400 401 return String.valueOf(getShowPublishNotification()); 402 } 403 404 /** 405 * Gets the map of preferences.<p> 406 * 407 * @return the map of preferences 408 */ 409 public Map<String, I_CmsPreference> getPreferences() { 410 411 return Collections.unmodifiableMap(m_preferences); 412 } 413 414 /** 415 * Returns the publish related resources mode.<p> 416 * 417 * @return the publish related resources mode 418 */ 419 public CmsPublishRelatedResourcesMode getPublishRelatedResources() { 420 421 return m_publishRelatedResourcesMode; 422 } 423 424 /** 425 * Returns if the explorer view is restricted to the defined site and folder.<p> 426 * 427 * @return true if the explorer view is restricted, otherwise false 428 */ 429 public String getRestrictExplorerViewString() { 430 431 return String.valueOf(getRestrictExplorerView()); 432 } 433 434 /** 435 * Gets if the file creation date should be shown in explorer view.<p> 436 * 437 * @return <code>"true"</code> if the file creation date should be shown, otherwise <code>"false"</code> 438 */ 439 public String getShowExplorerFileDateCreated() { 440 441 return getExplorerSetting(CmsUserSettings.FILELIST_DATE_CREATED); 442 } 443 444 /** 445 * Gets if the file expired by should be shown in explorer view.<p> 446 * 447 * @return <code>"true"</code> if the file date expired by should be shown, otherwise <code>"false"</code> 448 */ 449 public String getShowExplorerFileDateExpired() { 450 451 return getExplorerSetting(CmsUserSettings.FILELIST_DATE_EXPIRED); 452 } 453 454 /** 455 * Gets if the file last modified date should be shown in explorer view.<p> 456 * 457 * @return <code>"true"</code> if the file last modified date should be shown, otherwise <code>"false"</code> 458 */ 459 public String getShowExplorerFileDateLastModified() { 460 461 return getExplorerSetting(CmsUserSettings.FILELIST_DATE_LASTMODIFIED); 462 } 463 464 /** 465 * Gets if the file released by should be shown in explorer view.<p> 466 * 467 * @return <code>"true"</code> if the file date released by should be shown, otherwise <code>"false"</code> 468 */ 469 public String getShowExplorerFileDateReleased() { 470 471 return getExplorerSetting(CmsUserSettings.FILELIST_DATE_RELEASED); 472 } 473 474 /** 475 * Gets if the file locked by should be shown in explorer view.<p> 476 * 477 * @return <code>"true"</code> if the file locked by should be shown, otherwise <code>"false"</code> 478 */ 479 public String getShowExplorerFileLockedBy() { 480 481 return getExplorerSetting(CmsUserSettings.FILELIST_LOCKEDBY); 482 } 483 484 /** 485 * Gets if the file navtext should be shown in explorer view.<p> 486 * 487 * @return <code>"true"</code> if the file navtext should be shown, otherwise <code>"false"</code> 488 */ 489 public String getShowExplorerFileNavText() { 490 491 return getExplorerSetting(CmsUserSettings.FILELIST_NAVTEXT); 492 } 493 494 /** 495 * Gets if the file permissions should be shown in explorer view.<p> 496 * 497 * @return <code>"true"</code> if the file permissions should be shown, otherwise <code>"false"</code> 498 */ 499 public String getShowExplorerFilePermissions() { 500 501 return getExplorerSetting(CmsUserSettings.FILELIST_PERMISSIONS); 502 } 503 504 /** 505 * Gets if the file size should be shown in explorer view.<p> 506 * 507 * @return <code>"true"</code> if the file size should be shown, otherwise <code>"false"</code> 508 */ 509 public String getShowExplorerFileSize() { 510 511 return getExplorerSetting(CmsUserSettings.FILELIST_SIZE); 512 } 513 514 /** 515 * Gets if the file state should be shown in explorer view.<p> 516 * 517 * @return <code>"true"</code> if the file state should be shown, otherwise <code>"false"</code> 518 */ 519 public String getShowExplorerFileState() { 520 521 return getExplorerSetting(CmsUserSettings.FILELIST_STATE); 522 } 523 524 /** 525 * Gets if the file title should be shown in explorer view.<p> 526 * 527 * @return <code>"true"</code> if the file title should be shown, otherwise <code>"false"</code> 528 */ 529 public String getShowExplorerFileTitle() { 530 531 return getExplorerSetting(CmsUserSettings.FILELIST_TITLE); 532 } 533 534 /** 535 * Gets if the file type should be shown in explorer view.<p> 536 * 537 * @return <code>"true"</code> if the file type should be shown, otherwise <code>"false"</code> 538 */ 539 public String getShowExplorerFileType() { 540 541 return getExplorerSetting(CmsUserSettings.FILELIST_TYPE); 542 } 543 544 /** 545 * Gets if the file creator should be shown in explorer view.<p> 546 * 547 * @return <code>"true"</code> if the file creator should be shown, otherwise <code>"false"</code> 548 */ 549 public String getShowExplorerFileUserCreated() { 550 551 return getExplorerSetting(CmsUserSettings.FILELIST_USER_CREATED); 552 } 553 554 /** 555 * Gets if the file last modified by should be shown in explorer view.<p> 556 * 557 * @return <code>"true"</code> if the file last modified by should be shown, otherwise <code>"false"</code> 558 */ 559 public String getShowExplorerFileUserLastModified() { 560 561 return getExplorerSetting(CmsUserSettings.FILELIST_USER_LASTMODIFIED); 562 } 563 564 /** 565 * Returns a string representation of the show file upload button flag.<p> 566 * 567 * @return string representation of the show file upload button flag 568 * 569 * @see #getShowFileUploadButton() 570 */ 571 public String getShowFileUploadButtonString() { 572 573 return String.valueOf(getShowFileUploadButton()); 574 } 575 576 /** 577 * Returns a string representation of the publish notification flag.<p> 578 * 579 * @return string representation of the publish notification flag 580 * 581 * @see #getShowPublishNotification() 582 */ 583 public String getShowPublishNotificationString() { 584 585 return String.valueOf(getShowPublishNotification()); 586 } 587 588 /** 589 * Gets the subsitemap creation mode to use for the sitemap editor.<p> 590 * 591 * @return the subsitemap creation mode to use for the sitemap editor 592 */ 593 public SubsitemapCreationMode getSubsitemapCreationMode() { 594 595 return getSubsitemapCreationMode(SubsitemapCreationMode.convert); 596 } 597 598 /** 599 * Gets the subsitemap creation mode, or returns a default value given as a parameter if the mode is not set.<p> 600 * 601 * @param defaultValue the value to return when the subsitemap creation mode is not set 602 * 603 * @return the subsitemap creation mode 604 */ 605 public SubsitemapCreationMode getSubsitemapCreationMode(SubsitemapCreationMode defaultValue) { 606 607 if (m_subsitemapCreationMode != null) { 608 return m_subsitemapCreationMode; 609 } 610 return defaultValue; 611 } 612 613 /** 614 * Returns a string representation of the workplace button style.<p> 615 * 616 * @return string representation of the workplace button style 617 * 618 * @see #getWorkplaceButtonStyle() 619 */ 620 public String getWorkplaceButtonStyleString() { 621 622 return BUTTON_STYLES_LIST.get(getWorkplaceButtonStyle()); 623 } 624 625 /** 626 * Initializes the preference configuration.<p> 627 * 628 * Note that this method should only be called once the resource types have been initialized, but after addPreference has been called for all configured preferences. 629 * 630 * @param wpManager the active workplace manager 631 */ 632 public void initPreferences(CmsWorkplaceManager wpManager) { 633 634 CURRENT_DEFAULT_SETTINGS = this; 635 Class<?> accessorClass = CmsUserSettingsStringPropertyWrapper.class; 636 637 // first initialize all built-in preferences. these are: 638 // a) Bean properties of CmsUserSettingsStringPropertyWrapper 639 // b) Editor setting preferences 640 // c) Gallery setting preferences 641 PropertyDescriptor[] propDescs = PropertyUtils.getPropertyDescriptors(accessorClass); 642 for (PropertyDescriptor descriptor : propDescs) { 643 String name = descriptor.getName(); 644 Method getter = descriptor.getReadMethod(); 645 Method setter = descriptor.getWriteMethod(); 646 if ((getter == null) || (setter == null)) { 647 continue; 648 } 649 650 PrefMetadata metadata = getter.getAnnotation(PrefMetadata.class); 651 if (metadata == null) { 652 CmsBuiltinPreference preference = new CmsBuiltinPreference(name); 653 m_preferences.put(preference.getName(), preference); 654 } else { 655 try { 656 Constructor<?> constructor = metadata.type().getConstructor(String.class); 657 I_CmsPreference pref = (I_CmsPreference)constructor.newInstance(name); 658 m_preferences.put(pref.getName(), pref); 659 } catch (Exception e) { 660 throw new RuntimeException(e); 661 } 662 } 663 } 664 665 Map<String, String> editorValues = getEditorSettings(); 666 if (wpManager.getWorkplaceEditorManager() != null) { 667 for (String resType : wpManager.getWorkplaceEditorManager().getConfigurableEditors().keySet()) { 668 if (!editorValues.containsKey(resType)) { 669 editorValues.put(resType, null); 670 } 671 } 672 } 673 for (Map.Entry<String, String> editorSettingEntry : editorValues.entrySet()) { 674 CmsEditorPreference pref = new CmsEditorPreference( 675 editorSettingEntry.getKey(), 676 editorSettingEntry.getValue()); 677 m_preferences.put(pref.getName(), pref); 678 } 679 680 Map<String, String> galleryValues = new HashMap<String, String>(getStartGalleriesSettings()); 681 for (String key : wpManager.getGalleries().keySet()) { 682 if (!galleryValues.containsKey(key)) { 683 galleryValues.put(key, null); 684 } 685 } 686 for (Map.Entry<String, String> galleryEntry : galleryValues.entrySet()) { 687 CmsStartGallleryPreference pref = new CmsStartGallleryPreference( 688 galleryEntry.getKey(), 689 galleryEntry.getValue()); 690 m_preferences.put(pref.getName(), pref); 691 } 692 693 // Now process configured preferences. Each configuration entry is either 694 // for a built-in preference, in which case we create a wrapper around the existing preference, 695 // or for a custom user-defined preference. 696 for (CmsPreferenceData prefData : m_preferenceData) { 697 String name = prefData.getName(); 698 I_CmsPreference pref = null; 699 if (m_preferences.containsKey(name)) { 700 // we first remove the existing preference, because in a LinkedHashMap, put(key, value) will not 701 // update the position of the entry if the key already exists 702 pref = new CmsWrapperPreference(prefData, m_preferences.remove(name)); 703 } else { 704 pref = new CmsUserDefinedPreference( 705 prefData.getName(), 706 prefData.getDefaultValue(), 707 prefData.getPropertyDefinition(), 708 prefData.getTab()); 709 } 710 m_preferences.put(pref.getName(), pref); 711 pref.setValue(this, prefData.getDefaultValue()); 712 } 713 } 714 715 /** 716 * Returns if the deletion of relation targets is enabled.<p> 717 * 718 * @return <code>true</code> if the deletion of relation targets is enabled, otherwise <code>false</code> 719 */ 720 public boolean isAllowBrokenRelations() { 721 722 return m_allowBrokenRelations; 723 } 724 725 /** 726 * Sets if the deletion of relation targets is enabled.<p> 727 * 728 * @param allowBrokenRelations <code>true</code> if relation deletion should be enabled, otherwise <code>false</code> 729 */ 730 public void setAllowBrokenRelations(String allowBrokenRelations) { 731 732 m_allowBrokenRelations = Boolean.valueOf(allowBrokenRelations).booleanValue(); 733 if (CmsLog.INIT.isInfoEnabled()) { 734 CmsLog.INIT.info( 735 Messages.get().getBundle().key( 736 m_allowBrokenRelations 737 ? Messages.INIT_RELATION_DELETION_ENABLED_0 738 : Messages.INIT_RELATION_DELETION_DISABLED_0)); 739 } 740 } 741 742 /** 743 * Sets the default copy mode when copying a file of the user.<p> 744 * 745 * @param mode the default copy mode when copying a file of the user 746 */ 747 public void setDialogCopyFileMode(String mode) { 748 749 CmsResourceCopyMode copyMode = CmsResource.COPY_AS_NEW; 750 if (mode.equalsIgnoreCase(COPYMODE_SIBLING)) { 751 copyMode = CmsResource.COPY_AS_SIBLING; 752 } 753 setDialogCopyFileMode(copyMode); 754 } 755 756 /** 757 * Sets the default copy mode when copying a folder of the user.<p> 758 * 759 * @param mode the default copy mode when copying a folder of the user 760 */ 761 public void setDialogCopyFolderMode(String mode) { 762 763 CmsResourceCopyMode copyMode = CmsResource.COPY_AS_NEW; 764 if (mode.equalsIgnoreCase(COPYMODE_SIBLING)) { 765 copyMode = CmsResource.COPY_AS_SIBLING; 766 } else if (mode.equalsIgnoreCase(COPYMODE_PRESERVE)) { 767 copyMode = CmsResource.COPY_PRESERVE_SIBLING; 768 } 769 setDialogCopyFolderMode(copyMode); 770 } 771 772 /** 773 * Sets the default setting for file deletion.<p> 774 * 775 * @param mode the default setting for file deletion 776 */ 777 public void setDialogDeleteFileMode(String mode) { 778 779 CmsResourceDeleteMode deleteMode = CmsResource.DELETE_PRESERVE_SIBLINGS; 780 if (mode.equalsIgnoreCase(DELETEMODE_DELETE)) { 781 deleteMode = CmsResource.DELETE_REMOVE_SIBLINGS; 782 } 783 setDialogDeleteFileMode(deleteMode); 784 } 785 786 /** 787 * Sets the default setting for expanding inherited permissions in the dialog.<p> 788 * 789 * @param dialogExpandInheritedPermissions the default setting for expanding inherited permissions in the dialog 790 */ 791 public void setDialogExpandInheritedPermissions(String dialogExpandInheritedPermissions) { 792 793 setDialogExpandInheritedPermissions(Boolean.valueOf(dialogExpandInheritedPermissions).booleanValue()); 794 } 795 796 /** 797 * Sets the default setting for expanding the users permissions in the dialog.<p> 798 * 799 * @param dialogExpandUserPermissions the default setting for expanding the users permissions in the dialog 800 */ 801 public void setDialogExpandUserPermissions(String dialogExpandUserPermissions) { 802 803 setDialogExpandUserPermissions(Boolean.valueOf(dialogExpandUserPermissions).booleanValue()); 804 } 805 806 /** 807 * Sets the default setting for inheriting permissions on folders.<p> 808 * 809 * @param dialogPermissionsInheritOnFolder the default setting for inheriting permissions on folders 810 */ 811 public void setDialogPermissionsInheritOnFolder(String dialogPermissionsInheritOnFolder) { 812 813 setDialogPermissionsInheritOnFolder(Boolean.valueOf(dialogPermissionsInheritOnFolder).booleanValue()); 814 } 815 816 /** 817 * Sets the default setting for direct publishing.<p> 818 * 819 * @param mode the default setting for direct publishing 820 */ 821 public void setDialogPublishSiblings(String mode) { 822 823 boolean publishSiblings = false; 824 if (mode.equalsIgnoreCase(PUBLISHMODE_SIBLINGS)) { 825 publishSiblings = true; 826 } 827 setDialogPublishSiblings(publishSiblings); 828 } 829 830 /** 831 * Sets the style of the direct edit buttons of the user.<p> 832 * 833 * @param buttonstyle the style of the direct edit buttons of the user 834 */ 835 public void setDirectEditButtonStyle(String buttonstyle) { 836 837 int buttonstyleValue = BUTTONSTYLE_TEXTIMAGE; 838 try { 839 if (buttonstyle != null) { 840 buttonstyleValue = BUTTON_STYLES_LIST.indexOf(buttonstyle); 841 } 842 } catch (Exception e) { 843 // do nothing, use the default value 844 } 845 setDirectEditButtonStyle(buttonstyleValue); 846 } 847 848 /** 849 * Sets the style of the editor buttons of the user.<p> 850 * 851 * @param buttonstyle the style of the editor buttons of the user 852 */ 853 public void setEditorButtonStyle(String buttonstyle) { 854 855 int buttonstyleValue = BUTTONSTYLE_TEXTIMAGE; 856 try { 857 if (buttonstyle != null) { 858 buttonstyleValue = BUTTON_STYLES_LIST.indexOf(buttonstyle); 859 } 860 } catch (Exception e) { 861 // do nothing, use the default value 862 } 863 setEditorButtonStyle(buttonstyleValue); 864 } 865 866 /** 867 * Sets the style of the explorer workplace buttons of the user.<p> 868 * 869 * @param buttonstyle the style of the explorer workplace buttons of the user 870 */ 871 public void setExplorerButtonStyle(String buttonstyle) { 872 873 int buttonstyleValue = BUTTONSTYLE_TEXTIMAGE; 874 try { 875 if (buttonstyle != null) { 876 buttonstyleValue = BUTTON_STYLES_LIST.indexOf(buttonstyle); 877 } 878 } catch (Exception e) { 879 // do nothing, use the default value 880 } 881 setExplorerButtonStyle(buttonstyleValue); 882 } 883 884 /** 885 * Sets the number of displayed files per page of the user.<p> 886 * 887 * @param entries the number of displayed files per page of the user 888 */ 889 public void setExplorerFileEntries(String entries) { 890 891 try { 892 setExplorerFileEntries(Integer.parseInt(entries)); 893 } catch (Throwable t) { 894 // ignore this exception 895 } 896 } 897 898 /** 899 * Sets if all projects should be shown for the user.<p> 900 * 901 * @param listAllProjects <code>"true"</code> or <code>"false"</code> 902 */ 903 public void setListAllProjects(String listAllProjects) { 904 905 setListAllProjects(Boolean.valueOf(listAllProjects).booleanValue()); 906 } 907 908 /** 909 * Sets the workplace locale.<p> 910 * 911 * @param locale the workplace language default 912 */ 913 public void setLocale(String locale) { 914 915 // set the language 916 setLocale(CmsLocaleManager.getLocale(locale)); 917 } 918 919 /** 920 * Digester support method for configuration if the "create index page" checkbox in the new folder 921 * dialog should be initially be checked or not. <p> 922 * 923 * The given <code>String</code> value is interpreted as a {@link Boolean} by the means 924 * of <code>{@link Boolean#valueOf(String)}</code>. <p> 925 * 926 * @param booleanValue a <code>String</code> that is interpred as a {@link Boolean} by the means 927 * of <code>{@link Boolean#valueOf(String)}</code> 928 */ 929 public void setNewFolderCreateIndexPage(String booleanValue) { 930 931 setNewFolderCreateIndexPage(Boolean.valueOf(booleanValue)); 932 } 933 934 /** 935 * Digester support method for configuration if the "edit properties" checkbox in the new folder 936 * dialog should be initially be checked or not. <p> 937 * 938 * The given <code>String</code> value is interpreted as a {@link Boolean} by the means 939 * of <code>{@link Boolean#valueOf(String)}</code>. <p> 940 * 941 * @param booleanValue a <code>String</code> that is interpreted as a <code> {@link Boolean}</code> 942 * by the means of <code>{@link Boolean#valueOf(String)}</code> 943 */ 944 public void setNewFolderEditProperties(String booleanValue) { 945 946 setNewFolderEditPropertes(Boolean.valueOf(booleanValue)); 947 } 948 949 /** 950 * Sets the publish related resources mode.<p> 951 * 952 * @param publishRelatedResourcesMode the publish related resources mode to set 953 */ 954 public void setPublishRelatedResourcesMode(String publishRelatedResourcesMode) { 955 956 m_publishRelatedResourcesMode = CmsPublishRelatedResourcesMode.valueOf(publishRelatedResourcesMode); 957 if ((m_publishRelatedResourcesMode != null) && CmsLog.INIT.isInfoEnabled()) { 958 CmsLog.INIT.info( 959 Messages.get().getBundle().key( 960 Messages.INIT_PUBLISH_RELATED_RESOURCES_MODE_1, 961 m_publishRelatedResourcesMode.toString())); 962 } 963 } 964 965 /** 966 * Sets if the explorer view is restricted to the defined site and folder.<p> 967 * 968 * @param restrict true if the explorer view is restricted, otherwise false 969 */ 970 public void setRestrictExplorerView(String restrict) { 971 972 setRestrictExplorerView(Boolean.valueOf(restrict).booleanValue()); 973 } 974 975 /** 976 * Sets if the file creation date should be shown in explorer view.<p> 977 * 978 * @param show true if the file creation date should be shown, otherwise false 979 */ 980 public void setShowExplorerFileDateCreated(String show) { 981 982 setShowExplorerFileDateCreated(Boolean.valueOf(show).booleanValue()); 983 } 984 985 /** 986 * Sets if the file expire date should be shown in explorer view.<p> 987 * 988 * @param show true if the file expire date should be shown, otherwise false 989 */ 990 public void setShowExplorerFileDateExpired(String show) { 991 992 setShowExplorerFileDateExpired(Boolean.valueOf(show).booleanValue()); 993 } 994 995 /** 996 * Sets if the file last modified date should be shown in explorer view.<p> 997 * 998 * @param show true if the file last modified date should be shown, otherwise false 999 */ 1000 public void setShowExplorerFileDateLastModified(String show) { 1001 1002 setShowExplorerFileDateLastModified(Boolean.valueOf(show).booleanValue()); 1003 } 1004 1005 /** 1006 * Sets if the file release date should be shown in explorer view.<p> 1007 * 1008 * @param show true if the file release date should be shown, otherwise false 1009 */ 1010 public void setShowExplorerFileDateReleased(String show) { 1011 1012 setShowExplorerFileDateReleased(Boolean.valueOf(show).booleanValue()); 1013 } 1014 1015 /** 1016 * Sets if the file locked by should be shown in explorer view.<p> 1017 * 1018 * @param show true if the file locked by should be shown, otherwise false 1019 */ 1020 public void setShowExplorerFileLockedBy(String show) { 1021 1022 setShowExplorerFileLockedBy(Boolean.valueOf(show).booleanValue()); 1023 } 1024 1025 /** 1026 * Sets if the file navtext should be shown in explorer view.<p> 1027 * 1028 * @param show true if the file locked by should be shown, otherwise false 1029 */ 1030 public void setShowExplorerFileNavText(String show) { 1031 1032 setShowExplorerFileNavText(Boolean.valueOf(show).booleanValue()); 1033 } 1034 1035 /** 1036 * Sets if the file permissions should be shown in explorer view.<p> 1037 * 1038 * @param show true if the file permissions should be shown, otherwise false 1039 */ 1040 public void setShowExplorerFilePermissions(String show) { 1041 1042 setShowExplorerFilePermissions(Boolean.valueOf(show).booleanValue()); 1043 } 1044 1045 /** 1046 * Sets if the file size should be shown in explorer view.<p> 1047 * 1048 * @param show true if the file size should be shown, otherwise false 1049 */ 1050 public void setShowExplorerFileSize(String show) { 1051 1052 setShowExplorerFileSize(Boolean.valueOf(show).booleanValue()); 1053 } 1054 1055 /** 1056 * Sets if the file state should be shown in explorer view.<p> 1057 * 1058 * @param show true if the state size should be shown, otherwise false 1059 */ 1060 public void setShowExplorerFileState(String show) { 1061 1062 setShowExplorerFileState(Boolean.valueOf(show).booleanValue()); 1063 } 1064 1065 /** 1066 * Sets if the file title should be shown in explorer view.<p> 1067 * 1068 * @param show true if the file title should be shown, otherwise false 1069 */ 1070 public void setShowExplorerFileTitle(String show) { 1071 1072 setShowExplorerFileTitle(Boolean.valueOf(show).booleanValue()); 1073 } 1074 1075 /** 1076 * Sets if the file type should be shown in explorer view.<p> 1077 * 1078 * @param show true if the file type should be shown, otherwise false 1079 */ 1080 public void setShowExplorerFileType(String show) { 1081 1082 setShowExplorerFileType(Boolean.valueOf(show).booleanValue()); 1083 } 1084 1085 /** 1086 * Sets if the file creator should be shown in explorer view.<p> 1087 * 1088 * @param show true if the file creator should be shown, otherwise false 1089 */ 1090 public void setShowExplorerFileUserCreated(String show) { 1091 1092 setShowExplorerFileUserCreated(Boolean.valueOf(show).booleanValue()); 1093 } 1094 1095 /** 1096 * Sets if the file last modified by should be shown in explorer view.<p> 1097 * 1098 * @param show true if the file last modified by should be shown, otherwise false 1099 */ 1100 public void setShowExplorerFileUserLastModified(String show) { 1101 1102 setShowExplorerFileUserLastModified(Boolean.valueOf(show).booleanValue()); 1103 } 1104 1105 /** 1106 * Sets if the export part of the secure/export dialog should be shown.<p> 1107 * 1108 * @param mode true if the export dialog should be shown, otherwise false 1109 */ 1110 public void setShowExportSettingsDialog(String mode) { 1111 1112 setDialogShowExportSettings(Boolean.valueOf(mode).booleanValue()); 1113 } 1114 1115 /** 1116 * Controls whether to display a file upload icon or not.<p> 1117 * 1118 * @param flag <code>"true"</code> or <code>"false"</code> to flag the use of the file upload button 1119 */ 1120 public void setShowFileUploadButton(String flag) { 1121 1122 setShowFileUploadButton(Boolean.valueOf(flag).booleanValue()); 1123 } 1124 1125 /** 1126 * Sets if the lock dialog should be shown.<p> 1127 * 1128 * @param mode true if the lock dialog should be shown, otherwise false 1129 */ 1130 public void setShowLockDialog(String mode) { 1131 1132 setDialogShowLock(Boolean.valueOf(mode).booleanValue()); 1133 } 1134 1135 /** 1136 * Sets if the publish notification should be shown for the user.<p> 1137 * 1138 * @param notification <code>"true"</code> or <code>"false"</code> to flag the notification 1139 */ 1140 public void setShowPublishNotification(String notification) { 1141 1142 // set if the publish notification should be shown 1143 setShowPublishNotification(Boolean.valueOf(notification).booleanValue()); 1144 } 1145 1146 /** 1147 * Digester support method for configuration if the resource type selection checkbox should 1148 * show up when uploading a new file in non-applet mode.<p> 1149 * 1150 * The given <code>String</code> value is interpreted as a {@link Boolean} by the means 1151 * of <code>{@link Boolean#valueOf(String)}</code>. <p> 1152 * 1153 * @param booleanValue a <code>String</code> that is interpreted as a {@link Boolean} by the means 1154 * of <code>{@link Boolean#valueOf(String)}</code> 1155 */ 1156 public void setShowUploadTypeDialog(String booleanValue) { 1157 1158 setShowUploadTypeDialog(Boolean.valueOf(booleanValue)); 1159 } 1160 1161 /** 1162 * Sets the subsitemap creation mode.<p> 1163 * 1164 * @param mode the string value of the subsitemap creation mode 1165 */ 1166 public void setSubsitemapCreationMode(String mode) { 1167 1168 try { 1169 m_subsitemapCreationMode = SubsitemapCreationMode.valueOf(mode); 1170 } catch (Exception e) { 1171 LOG.warn("Invalid value for subsitemap creation mode was ignored: " + mode); 1172 } 1173 } 1174 1175 /** 1176 * Sets the style of the workplace buttons of the user.<p> 1177 * 1178 * @param buttonstyle the style of the workplace buttons of the user 1179 */ 1180 public void setWorkplaceButtonStyle(String buttonstyle) { 1181 1182 int buttonstyleValue = BUTTONSTYLE_TEXTIMAGE; 1183 try { 1184 if (buttonstyle != null) { 1185 buttonstyleValue = BUTTON_STYLES_LIST.indexOf(buttonstyle); 1186 } 1187 } catch (Exception e) { 1188 // do nothing, use the default value 1189 } 1190 setWorkplaceButtonStyle(buttonstyleValue); 1191 } 1192 1193 /** 1194 * Sets the style of the workplace search default view.<p> 1195 * 1196 * @param viewStyle the style of the workplace search default view 1197 */ 1198 public void setWorkplaceSearchViewStyle(String viewStyle) { 1199 1200 setWorkplaceSearchViewStyle(CmsSearchResultStyle.valueOf(viewStyle)); 1201 } 1202 1203 /** 1204 * Checks if a specific explorer setting depending is set.<p> 1205 * 1206 * @param setting the settings constant value for the explorer settings 1207 * @return <code>"true"</code> if the explorer setting is set, otherwise <code>"false"</code> 1208 */ 1209 private String getExplorerSetting(int setting) { 1210 1211 return String.valueOf((getExplorerSettings() & setting) > 0); 1212 } 1213 1214}