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