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