001/* 002 * This library is part of OpenCms - 003 * the Open Source Content Management System 004 * 005 * Copyright (c) Alkacon Software GmbH & Co. KG (https://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, please see the 018 * company website: https://www.alkacon.com 019 * 020 * For further information about OpenCms, please see the 021 * project website: https://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.ade.containerpage.shared; 029 030import org.opencms.gwt.shared.CmsPermissionInfo; 031import org.opencms.gwt.shared.I_CmsHasIconClasses; 032import org.opencms.util.CmsUUID; 033 034import com.google.gwt.user.client.rpc.IsSerializable; 035 036/** 037 * Bean holding basic container element information.<p> 038 * 039 * @since 8.0.0 040 */ 041public class CmsContainerElement implements IsSerializable, I_CmsHasIconClasses { 042 043 /** The model group states. */ 044 public static enum ModelGroupState { 045 046 /** Is model group state. */ 047 isModelGroup, 048 049 /** No model group what so ever. */ 050 noGroup, 051 052 /** Former copy model group. */ 053 wasModelGroup; 054 055 /** 056 * Evaluates the given state string.<p> 057 * 058 * @param state the state 059 * 060 * @return the model group state 061 */ 062 public static ModelGroupState evaluate(String state) { 063 064 ModelGroupState result = null; 065 if (state != null) { 066 try { 067 result = ModelGroupState.valueOf(state); 068 } catch (IllegalArgumentException e) { 069 // ignore 070 } 071 } 072 if (result == null) { 073 result = noGroup; 074 } 075 return result; 076 } 077 } 078 079 /** HTML class used to identify containers. */ 080 public static final String CLASS_CONTAINER = "oc-container"; 081 082 /** HTML class used to identify container elements. */ 083 public static final String CLASS_CONTAINER_ELEMENT_END_MARKER = "oc-element-end"; 084 085 /** HTML class used to identify container elements. */ 086 public static final String CLASS_CONTAINER_ELEMENT_START_MARKER = "oc-element-start"; 087 088 /** HTML class used to identify error message for elements where rendering failed to render. */ 089 public static final String CLASS_ELEMENT_ERROR = "oc-element-error"; 090 091 /** HTML class used to identify group container elements. */ 092 public static final String CLASS_GROUP_CONTAINER_ELEMENT_MARKER = "oc-groupcontainer"; 093 094 /** The create as new setting key. */ 095 public static final String CREATE_AS_NEW = "create_as_new"; 096 097 /** The element instance id settings key. */ 098 public static final String ELEMENT_INSTANCE_ID = "element_instance_id"; 099 100 /** The group container resource type name. */ 101 public static final String GROUP_CONTAINER_TYPE_NAME = "groupcontainer"; 102 103 /** The resource type name for inherited container references. */ 104 public static final String INHERIT_CONTAINER_TYPE_NAME = "inheritance_group"; 105 106 /** The is model group always replace element setting key. */ 107 public static final String IS_MODEL_GROUP_ALWAYS_REPLACE = "is_model_group_always_replace"; 108 109 /** The container id marking the edit menus. */ 110 public static final String MENU_CONTAINER_ID = "cms_edit_menu_container"; 111 112 /** The model group id setting key. */ 113 public static final String MODEL_GROUP_ID = "model_group_id"; 114 115 /** Prefix for new system element settings. */ 116 public static final String SYSTEM_SETTING_PREFIX = "SYSTEM::"; 117 118 /** The is model group element setting key. */ 119 public static final String MODEL_GROUP_STATE = "model_group_state"; 120 121 /** Key for the setting that replaces the CreateNew element. */ 122 public static final String SETTING_CREATE_NEW = "SYSTEM::create_new"; 123 124 /** 125 * Key for the setting used to identify which page this element was read from originally. 126 * 127 * <p>This setting is not stored when saving a container page. 128 **/ 129 public static final String SETTING_PAGE_ID = "SYSTEM::pageId"; 130 131 /** The use as copy model setting key. */ 132 public static final String USE_AS_COPY_MODEL = "use_as_copy_model"; 133 134 private CmsElementLockInfo m_lockInfo = new CmsElementLockInfo(null, false); 135 136 /** The element client id. */ 137 private String m_clientId; 138 139 /** The copy in models flag. */ 140 private boolean m_copyInModels; 141 142 /** The 'create new' status of the element. */ 143 private boolean m_createNew; 144 145 /** The element view this element belongs to by it's type. */ 146 private CmsUUID m_elementView; 147 148 /** Indicates an edit handler is configured for the given resource type. */ 149 private boolean m_hasEditHandler; 150 151 /** Flag to indicate that this element may have settings. */ 152 private boolean m_hasSettings; 153 154 /** The resource type icon CSS classes. */ 155 private String m_iconClasses; 156 157 /** The inheritance info for this element. */ 158 private CmsInheritanceInfo m_inheritanceInfo; 159 160 /** The model group always replace flag. */ 161 private boolean m_isModelGroupAlwaysReplace; 162 163 /** The model group id or null. */ 164 private CmsUUID m_modelGroupId; 165 166 /** Flag indicating a new element. */ 167 private boolean m_new; 168 169 /** Flag which controls whether the new editor is disabled for this element. */ 170 private boolean m_newEditorDisabled; 171 172 /** The permission info for the element resource. */ 173 private CmsPermissionInfo m_permissionInfo; 174 175 /** Flag indicating if the given resource is released and not expired. */ 176 private boolean m_releasedAndNotExpired = true; 177 178 /** The resource type for new elements. If this field is not empty, the element is regarded as new and not created yet. */ 179 private String m_resourceType; 180 181 /** The full site path. */ 182 private String m_sitePath; 183 184 /** The sub title. */ 185 private String m_subTitle; 186 187 /** The title. */ 188 private String m_title; 189 190 /** The former copy model status. */ 191 private boolean m_wasModelGroup; 192 193 /** True if the element is marked as 'reused'. */ 194 private boolean m_reused; 195 196 /** True if the element has the name pattern property. */ 197 private boolean m_hasNamePatternProperty; 198 199 /** 200 * Default constructor.<p> 201 */ 202 public CmsContainerElement() { 203 204 // empty 205 } 206 207 /** 208 * Copies the container element.<p> 209 * 210 * @return the new copy of the container element 211 */ 212 public CmsContainerElement copy() { 213 214 CmsContainerElement result = new CmsContainerElement(); 215 result.m_clientId = m_clientId; 216 result.m_hasSettings = m_hasSettings; 217 result.m_inheritanceInfo = m_inheritanceInfo; 218 result.m_new = m_new; 219 result.m_newEditorDisabled = m_newEditorDisabled; 220 result.m_permissionInfo = new CmsPermissionInfo( 221 m_permissionInfo.hasViewPermission(), 222 m_permissionInfo.hasWritePermission(), 223 m_permissionInfo.getNoEditReason()); 224 result.m_releasedAndNotExpired = m_releasedAndNotExpired; 225 result.m_resourceType = m_resourceType; 226 result.m_iconClasses = m_iconClasses; 227 result.m_sitePath = m_sitePath; 228 result.m_subTitle = m_subTitle; 229 result.m_title = m_title; 230 result.m_elementView = m_elementView; 231 result.m_modelGroupId = m_modelGroupId; 232 result.m_wasModelGroup = m_wasModelGroup; 233 result.m_isModelGroupAlwaysReplace = m_isModelGroupAlwaysReplace; 234 result.m_reused = m_reused; 235 result.m_hasNamePatternProperty = m_hasNamePatternProperty; 236 return result; 237 } 238 239 /** 240 * Returns the resource type icon CSS rules.<p> 241 * 242 * @return the resource type icon CSS rules 243 */ 244 public String getBigIconClasses() { 245 246 return m_iconClasses; 247 } 248 249 /** 250 * Returns the client id.<p> 251 * 252 * @return the client id 253 */ 254 public String getClientId() { 255 256 return m_clientId; 257 } 258 259 /** 260 * Returns the element view this element belongs to by it's type.<p> 261 * 262 * @return the element view 263 */ 264 public CmsUUID getElementView() { 265 266 return m_elementView; 267 } 268 269 /** 270 * Returns the inheritance info for this element.<p> 271 * 272 * @return the inheritance info for this element 273 */ 274 public CmsInheritanceInfo getInheritanceInfo() { 275 276 return m_inheritanceInfo; 277 } 278 279 public CmsElementLockInfo getLockInfo() { 280 281 return m_lockInfo; 282 } 283 284 /** 285 * Returns the model group id.<p> 286 * 287 * @return the model group id 288 */ 289 public CmsUUID getModelGroupId() { 290 291 return m_modelGroupId; 292 } 293 294 /** 295 * Returns the no edit reason. If empty editing is allowed.<p> 296 * 297 * @return the no edit reason 298 */ 299 public String getNoEditReason() { 300 301 return m_permissionInfo.getNoEditReason(); 302 } 303 304 /** 305 * Returns the resource type name for elements.<p> 306 * 307 * @return the resource type name 308 */ 309 public String getResourceType() { 310 311 return m_resourceType; 312 } 313 314 /** 315 * Returns the site path.<p> 316 * 317 * @return the site path 318 */ 319 public String getSitePath() { 320 321 return m_sitePath; 322 } 323 324 /** 325 * @see org.opencms.gwt.shared.I_CmsHasIconClasses#getSmallIconClasses() 326 */ 327 public String getSmallIconClasses() { 328 329 // not needed 330 return null; 331 } 332 333 /** 334 * Returns the sub title.<p> 335 * 336 * @return the sub title 337 */ 338 public String getSubTitle() { 339 340 return m_subTitle; 341 } 342 343 /** 344 * Returns the title.<p> 345 * 346 * @return the title 347 */ 348 public String getTitle() { 349 350 return m_title; 351 } 352 353 /** 354 * Returns if an edit handler is configured for the given resource type.<p> 355 * 356 * @return <code>true</code> if an edit handler is configured for the given resource type 357 */ 358 public boolean hasEditHandler() { 359 360 return m_hasEditHandler; 361 } 362 363 /** 364 * Checks if the element has the name pattern property. 365 * 366 * @return true if the element has the name pattern property 367 */ 368 public boolean hasNamePatternProperty() { 369 370 return m_hasNamePatternProperty; 371 } 372 373 /** 374 * Returns if the element may have settings.<p> 375 * 376 * @param containerId the container id 377 * 378 * @return <code>true</code> if the element may have settings 379 */ 380 public boolean hasSettings(String containerId) { 381 382 return m_hasSettings; 383 } 384 385 /** 386 * Returns if the current user has view permissions for the element resource.<p> 387 * 388 * @return <code>true</code> if the current user has view permissions for the element resource 389 */ 390 public boolean hasViewPermission() { 391 392 return m_permissionInfo.hasViewPermission(); 393 } 394 395 /** 396 * Returns if the user has write permission.<p> 397 * 398 * @return <code>true</code> if the user has write permission 399 */ 400 public boolean hasWritePermission() { 401 402 return m_permissionInfo.hasWritePermission(); 403 } 404 405 /** 406 * Returns the copy in models flag.<p> 407 * 408 * @return the copy in models flag 409 */ 410 public boolean isCopyInModels() { 411 412 return m_copyInModels; 413 } 414 415 /** 416 * Reads the 'create new' status of the element.<p> 417 * 418 * When the page containing the element is used a model page, this flag determines whether a copy of the element 419 * is created when creating a new page from that model page.<p> 420 * 421 * @return the 'create new' status of the element 422 */ 423 public boolean isCreateNew() { 424 425 return m_createNew; 426 } 427 428 /** 429 * Returns if the given element is of the type group container.<p> 430 * 431 * @return <code>true</code> if the given element is of the type group container 432 */ 433 public boolean isGroupContainer() { 434 435 return GROUP_CONTAINER_TYPE_NAME.equals(m_resourceType); 436 } 437 438 /** 439 * Returns if the given element is of the type inherit container.<p> 440 * 441 * @return <code>true</code> if the given element is of the type inherit container 442 */ 443 public boolean isInheritContainer() { 444 445 return INHERIT_CONTAINER_TYPE_NAME.equals(m_resourceType); 446 } 447 448 /** 449 * Returns if the element is a model group.<p> 450 * 451 * @return <code>true</code> if the element is a model group 452 */ 453 public boolean isModelGroup() { 454 455 return m_modelGroupId != null; 456 } 457 458 /** 459 * Returns if all instances of this element should be replaced within a model group.<p> 460 * 461 * @return <code>true</code> if all instances of this element should be replaced within a model group 462 */ 463 public boolean isModelGroupAlwaysReplace() { 464 465 return m_isModelGroupAlwaysReplace; 466 } 467 468 /** 469 * Returns if the element is new and has not been created in the VFS yet.<p> 470 * 471 * @return <code>true</code> if the element is not created in the VFS yet 472 */ 473 public boolean isNew() { 474 475 return m_new; 476 } 477 478 /** 479 * Returns true if the new editor is disabled for this element.<p> 480 * 481 * @return true if the new editor is disabled for this element 482 */ 483 public boolean isNewEditorDisabled() { 484 485 return m_newEditorDisabled; 486 } 487 488 /** 489 * Returns if the given resource is released and not expired.<p> 490 * 491 * @return <code>true</code> if the given resource is released and not expired 492 */ 493 public boolean isReleasedAndNotExpired() { 494 495 return m_releasedAndNotExpired; 496 } 497 498 /** 499 * True if the element is marked as reused. 500 * 501 * @return true if the element is marked as reused 502 */ 503 public boolean isReused() { 504 505 return m_reused; 506 } 507 508 /** 509 * Returns the former copy model status.<p> 510 * 511 * @return the former copy model status 512 */ 513 public boolean isWasModelGroup() { 514 515 return m_wasModelGroup; 516 } 517 518 /** 519 * Sets the client id.<p> 520 * 521 * @param clientId the client id to set 522 */ 523 public void setClientId(String clientId) { 524 525 m_clientId = clientId; 526 } 527 528 /** 529 * Sets the copy in models flag.<p> 530 * 531 * @param copyInModels the copy in models flag to set 532 */ 533 public void setCopyInModels(boolean copyInModels) { 534 535 m_copyInModels = copyInModels; 536 } 537 538 /** 539 * Sets the 'create new' status of the element.<p> 540 * 541 * @param createNew the new 'create new' status 542 */ 543 public void setCreateNew(boolean createNew) { 544 545 m_createNew = createNew; 546 } 547 548 /** 549 * Sets the element view.<p> 550 * 551 * @param elementView the element view to set 552 */ 553 public void setElementView(CmsUUID elementView) { 554 555 m_elementView = elementView; 556 } 557 558 /** 559 * Sets the if an edit handler is configured for the given resource type.<p> 560 * 561 * @param hasEditHandler if an edit handler is configured for the given resource type 562 */ 563 public void setHasEditHandler(boolean hasEditHandler) { 564 565 m_hasEditHandler = hasEditHandler; 566 } 567 568 /** 569 * Sets/clears the 'has name pattern property' status. 570 * 571 * @param hasNamePatternProperty true if the element has the name pattern property 572 */ 573 public void setHasNamePatternProperty(boolean hasNamePatternProperty) { 574 575 m_hasNamePatternProperty = hasNamePatternProperty; 576 } 577 578 /** 579 * Sets if the element may have settings.<p> 580 * 581 * @param hasSettings <code>true</code> if the element may have settings 582 */ 583 public void setHasSettings(boolean hasSettings) { 584 585 m_hasSettings = hasSettings; 586 } 587 588 /** 589 * Sets the resource type icon CSS rules.<p> 590 * 591 * @param iconRules resource type icon CSS rules to set 592 */ 593 public void setIconClasses(String iconRules) { 594 595 m_iconClasses = iconRules; 596 } 597 598 /** 599 * Sets the inheritance info for this element.<p> 600 * 601 * @param inheritanceInfo the inheritance info for this element to set 602 */ 603 public void setInheritanceInfo(CmsInheritanceInfo inheritanceInfo) { 604 605 m_inheritanceInfo = inheritanceInfo; 606 } 607 608 public void setLockInfo(CmsElementLockInfo lockInfo) { 609 610 m_lockInfo = lockInfo; 611 } 612 613 /** 614 * Sets if all instances of this element should be replaced within a model group.<p> 615 * 616 * @param alwaysReplace if all instances of this element should be replaced within a model group 617 */ 618 public void setModelGroupAlwaysReplace(boolean alwaysReplace) { 619 620 m_isModelGroupAlwaysReplace = alwaysReplace; 621 } 622 623 /** 624 * Sets the model group id.<p> 625 * 626 * @param modelGroupId <code>true</code> if the element is a model group 627 */ 628 public void setModelGroupId(CmsUUID modelGroupId) { 629 630 m_modelGroupId = modelGroupId; 631 } 632 633 /** 634 * Sets the 'new' flag.<p> 635 * 636 * @param isNew <code>true</code> on a new element 637 */ 638 public void setNew(boolean isNew) { 639 640 m_new = isNew; 641 } 642 643 /** 644 * Disables the new editor for this element.<p> 645 * 646 * @param disabled if true, the new editor will be disabled for this element 647 */ 648 public void setNewEditorDisabled(boolean disabled) { 649 650 m_newEditorDisabled = disabled; 651 } 652 653 /** 654 * Sets the permission info.<p> 655 * 656 * @param permissionInfo the permission info to set 657 */ 658 public void setPermissionInfo(CmsPermissionInfo permissionInfo) { 659 660 m_permissionInfo = permissionInfo; 661 } 662 663 /** 664 * Sets if the given resource is released and not expired.<p> 665 * 666 * @param releasedAndNotExpired <code>true</code> if the given resource is released and not expired 667 */ 668 public void setReleasedAndNotExpired(boolean releasedAndNotExpired) { 669 670 m_releasedAndNotExpired = releasedAndNotExpired; 671 } 672 673 /** 674 * Sets the element resource type.<p> 675 * 676 * @param resourceType the element resource type 677 */ 678 public void setResourceType(String resourceType) { 679 680 m_resourceType = resourceType; 681 } 682 683 /** 684 * Sets the 'reused' status. 685 * 686 * @param reused the 'reused' status 687 */ 688 public void setReused(boolean reused) { 689 690 m_reused = reused; 691 } 692 693 /** 694 * Sets the site path.<p> 695 * 696 * @param sitePath the site path to set 697 */ 698 public void setSitePath(String sitePath) { 699 700 m_sitePath = sitePath; 701 } 702 703 /** 704 * Sets the sub title.<p> 705 * 706 * @param subTitle the sub title 707 */ 708 public void setSubTitle(String subTitle) { 709 710 m_subTitle = subTitle; 711 } 712 713 /** 714 * Sets the title.<p> 715 * 716 * @param title the title 717 */ 718 public void setTitle(String title) { 719 720 m_title = title; 721 } 722 723 /** 724 * Sets the was model group flag.<p> 725 * 726 * @param wasModelGroup the was model group flag to set 727 */ 728 public void setWasModelGroup(boolean wasModelGroup) { 729 730 m_wasModelGroup = wasModelGroup; 731 } 732}