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