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, 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.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    /**
197     * Default constructor.<p>
198     */
199    public CmsContainerElement() {
200
201        // empty
202    }
203
204    /**
205     * Copies the container element.<p>
206     *
207     * @return the new copy of the container element
208     */
209    public CmsContainerElement copy() {
210
211        CmsContainerElement result = new CmsContainerElement();
212        result.m_clientId = m_clientId;
213        result.m_hasSettings = m_hasSettings;
214        result.m_inheritanceInfo = m_inheritanceInfo;
215        result.m_new = m_new;
216        result.m_newEditorDisabled = m_newEditorDisabled;
217        result.m_permissionInfo = new CmsPermissionInfo(
218            m_permissionInfo.hasViewPermission(),
219            m_permissionInfo.hasWritePermission(),
220            m_permissionInfo.getNoEditReason());
221        result.m_releasedAndNotExpired = m_releasedAndNotExpired;
222        result.m_resourceType = m_resourceType;
223        result.m_iconClasses = m_iconClasses;
224        result.m_sitePath = m_sitePath;
225        result.m_subTitle = m_subTitle;
226        result.m_title = m_title;
227        result.m_elementView = m_elementView;
228        result.m_modelGroupId = m_modelGroupId;
229        result.m_wasModelGroup = m_wasModelGroup;
230        result.m_isModelGroupAlwaysReplace = m_isModelGroupAlwaysReplace;
231        result.m_reused = m_reused;
232        return result;
233    }
234
235    /**
236     * Returns the resource type icon CSS rules.<p>
237     *
238     * @return the resource type icon CSS rules
239     */
240    public String getBigIconClasses() {
241
242        return m_iconClasses;
243    }
244
245    /**
246     * Returns the client id.<p>
247     *
248     * @return the client id
249     */
250    public String getClientId() {
251
252        return m_clientId;
253    }
254
255    /**
256     * Returns the element view this element belongs to by it's type.<p>
257     *
258     * @return the element view
259     */
260    public CmsUUID getElementView() {
261
262        return m_elementView;
263    }
264
265    /**
266     * Returns the inheritance info for this element.<p>
267     *
268     * @return the inheritance info for this element
269     */
270    public CmsInheritanceInfo getInheritanceInfo() {
271
272        return m_inheritanceInfo;
273    }
274
275    public CmsElementLockInfo getLockInfo() {
276
277        return m_lockInfo;
278    }
279
280    /**
281     * Returns the model group id.<p>
282     *
283     * @return the model group id
284     */
285    public CmsUUID getModelGroupId() {
286
287        return m_modelGroupId;
288    }
289
290    /**
291     * Returns the no edit reason. If empty editing is allowed.<p>
292     *
293     * @return the no edit reason
294     */
295    public String getNoEditReason() {
296
297        return m_permissionInfo.getNoEditReason();
298    }
299
300    /**
301     * Returns the resource type name for elements.<p>
302     *
303     * @return the resource type name
304     */
305    public String getResourceType() {
306
307        return m_resourceType;
308    }
309
310    /**
311     * Returns the site path.<p>
312     *
313     * @return the site path
314     */
315    public String getSitePath() {
316
317        return m_sitePath;
318    }
319
320    /**
321     * @see org.opencms.gwt.shared.I_CmsHasIconClasses#getSmallIconClasses()
322     */
323    public String getSmallIconClasses() {
324
325        // not needed
326        return null;
327    }
328
329    /**
330     * Returns the sub title.<p>
331     *
332     * @return the sub title
333     */
334    public String getSubTitle() {
335
336        return m_subTitle;
337    }
338
339    /**
340     * Returns the title.<p>
341     *
342     * @return the title
343     */
344    public String getTitle() {
345
346        return m_title;
347    }
348
349    /**
350     * Returns if an edit handler is configured for the given resource type.<p>
351     *
352     * @return <code>true</code> if an edit handler is configured for the given resource type
353     */
354    public boolean hasEditHandler() {
355
356        return m_hasEditHandler;
357    }
358
359    /**
360     * Returns if the element may have settings.<p>
361     *
362     * @param containerId the container id
363     *
364     * @return <code>true</code> if the element may have settings
365     */
366    public boolean hasSettings(String containerId) {
367
368        return m_hasSettings;
369    }
370
371    /**
372     * Returns if the current user has view permissions for the element resource.<p>
373     *
374     * @return <code>true</code> if the current user has view permissions for the element resource
375     */
376    public boolean hasViewPermission() {
377
378        return m_permissionInfo.hasViewPermission();
379    }
380
381    /**
382     * Returns if the user has write permission.<p>
383     *
384     * @return <code>true</code> if the user has write permission
385     */
386    public boolean hasWritePermission() {
387
388        return m_permissionInfo.hasWritePermission();
389    }
390
391    /**
392     * Returns the copy in models flag.<p>
393     *
394     * @return the copy in models flag
395     */
396    public boolean isCopyInModels() {
397
398        return m_copyInModels;
399    }
400
401    /**
402     * Reads the 'create new' status of the element.<p>
403     *
404     * When the page containing the element is used a model page, this flag determines whether a copy of the element
405     * is created when creating a new page from that model page.<p>
406     *
407     * @return the 'create new' status of the element
408     */
409    public boolean isCreateNew() {
410
411        return m_createNew;
412    }
413
414    /**
415     * Returns if the given element is of the type group container.<p>
416     *
417     * @return <code>true</code> if the given element is of the type group container
418     */
419    public boolean isGroupContainer() {
420
421        return GROUP_CONTAINER_TYPE_NAME.equals(m_resourceType);
422    }
423
424    /**
425     * Returns if the given element is of the type inherit container.<p>
426     *
427     * @return <code>true</code> if the given element is of the type inherit container
428     */
429    public boolean isInheritContainer() {
430
431        return INHERIT_CONTAINER_TYPE_NAME.equals(m_resourceType);
432    }
433
434    /**
435     * Returns if the element is a model group.<p>
436     *
437     * @return <code>true</code> if the element is a model group
438     */
439    public boolean isModelGroup() {
440
441        return m_modelGroupId != null;
442    }
443
444    /**
445     * Returns if all instances of this element should be replaced within a model group.<p>
446     *
447     * @return <code>true</code> if all instances of this element should be replaced within a model group
448     */
449    public boolean isModelGroupAlwaysReplace() {
450
451        return m_isModelGroupAlwaysReplace;
452    }
453
454    /**
455     * Returns if the element is new and has not been created in the VFS yet.<p>
456     *
457     * @return <code>true</code> if the element is not created in the VFS yet
458     */
459    public boolean isNew() {
460
461        return m_new;
462    }
463
464    /**
465     * Returns true if the new editor is disabled for this element.<p>
466     *
467     * @return true if the new editor is disabled for this element
468     */
469    public boolean isNewEditorDisabled() {
470
471        return m_newEditorDisabled;
472    }
473
474    /**
475     * Returns if the given resource is released and not expired.<p>
476     *
477     * @return <code>true</code> if the given resource is released and not expired
478     */
479    public boolean isReleasedAndNotExpired() {
480
481        return m_releasedAndNotExpired;
482    }
483
484    /**
485     * True if the element is marked as reused.
486     *
487     * @return true if the element is marked as reused
488     */
489    public boolean isReused() {
490
491        return m_reused;
492    }
493
494    /**
495     * Returns the former copy model status.<p>
496     *
497     * @return the former copy model status
498     */
499    public boolean isWasModelGroup() {
500
501        return m_wasModelGroup;
502    }
503
504    /**
505     * Sets the client id.<p>
506     *
507     * @param clientId the client id to set
508     */
509    public void setClientId(String clientId) {
510
511        m_clientId = clientId;
512    }
513
514    /**
515     * Sets the copy in models flag.<p>
516     *
517     * @param copyInModels the copy in models flag to set
518     */
519    public void setCopyInModels(boolean copyInModels) {
520
521        m_copyInModels = copyInModels;
522    }
523
524    /**
525     * Sets the 'create new' status of the element.<p>
526     *
527     * @param createNew the new 'create new' status
528     */
529    public void setCreateNew(boolean createNew) {
530
531        m_createNew = createNew;
532    }
533
534    /**
535     * Sets the element view.<p>
536     *
537     * @param elementView the element view to set
538     */
539    public void setElementView(CmsUUID elementView) {
540
541        m_elementView = elementView;
542    }
543
544    /**
545     * Sets the if an edit handler is configured for the given resource type.<p>
546     *
547     * @param hasEditHandler if an edit handler is configured for the given resource type
548     */
549    public void setHasEditHandler(boolean hasEditHandler) {
550
551        m_hasEditHandler = hasEditHandler;
552    }
553
554    /**
555     * Sets if the element may have settings.<p>
556     *
557     * @param hasSettings <code>true</code> if the element may have settings
558     */
559    public void setHasSettings(boolean hasSettings) {
560
561        m_hasSettings = hasSettings;
562    }
563
564    /**
565     * Sets the resource type icon CSS rules.<p>
566     *
567     * @param iconRules resource type icon CSS rules to set
568     */
569    public void setIconClasses(String iconRules) {
570
571        m_iconClasses = iconRules;
572    }
573
574    /**
575     * Sets the inheritance info for this element.<p>
576     *
577     * @param inheritanceInfo the inheritance info for this element to set
578     */
579    public void setInheritanceInfo(CmsInheritanceInfo inheritanceInfo) {
580
581        m_inheritanceInfo = inheritanceInfo;
582    }
583
584    public void setLockInfo(CmsElementLockInfo lockInfo) {
585
586        m_lockInfo = lockInfo;
587    }
588
589    /**
590     * Sets if all instances of this element should be replaced within a model group.<p>
591     *
592     * @param alwaysReplace if all instances of this element should be replaced within a model group
593     */
594    public void setModelGroupAlwaysReplace(boolean alwaysReplace) {
595
596        m_isModelGroupAlwaysReplace = alwaysReplace;
597    }
598
599    /**
600     * Sets the model group id.<p>
601     *
602     * @param modelGroupId <code>true</code> if the element is a model group
603     */
604    public void setModelGroupId(CmsUUID modelGroupId) {
605
606        m_modelGroupId = modelGroupId;
607    }
608
609    /**
610     * Sets the 'new' flag.<p>
611     *
612     * @param isNew <code>true</code> on a new element
613     */
614    public void setNew(boolean isNew) {
615
616        m_new = isNew;
617    }
618
619    /**
620     * Disables the new editor for this element.<p>
621     *
622     * @param disabled if true, the new editor will be disabled for this element
623     */
624    public void setNewEditorDisabled(boolean disabled) {
625
626        m_newEditorDisabled = disabled;
627    }
628
629    /**
630     * Sets the permission info.<p>
631     *
632     * @param permissionInfo the permission info to set
633     */
634    public void setPermissionInfo(CmsPermissionInfo permissionInfo) {
635
636        m_permissionInfo = permissionInfo;
637    }
638
639    /**
640     * Sets if the given resource is released and not expired.<p>
641     *
642     * @param releasedAndNotExpired <code>true</code> if the given resource is released and not expired
643     */
644    public void setReleasedAndNotExpired(boolean releasedAndNotExpired) {
645
646        m_releasedAndNotExpired = releasedAndNotExpired;
647    }
648
649    /**
650     * Sets the element resource type.<p>
651     *
652     * @param resourceType the element resource type
653     */
654    public void setResourceType(String resourceType) {
655
656        m_resourceType = resourceType;
657    }
658
659    /**
660     * Sets the 'reused' status.
661     *
662     * @param reused the 'reused' status
663     */
664    public void setReused(boolean reused) {
665
666        m_reused = reused;
667    }
668
669    /**
670     * Sets the site path.<p>
671     *
672     * @param sitePath the site path to set
673     */
674    public void setSitePath(String sitePath) {
675
676        m_sitePath = sitePath;
677    }
678
679    /**
680     * Sets the sub title.<p>
681     *
682     * @param subTitle the sub title
683     */
684    public void setSubTitle(String subTitle) {
685
686        m_subTitle = subTitle;
687    }
688
689    /**
690     * Sets the title.<p>
691     *
692     * @param title the title
693     */
694    public void setTitle(String title) {
695
696        m_title = title;
697    }
698
699    /**
700     * Sets the was model group flag.<p>
701     *
702     * @param wasModelGroup the was model group flag to set
703     */
704    public void setWasModelGroup(boolean wasModelGroup) {
705
706        m_wasModelGroup = wasModelGroup;
707    }
708}