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.sitemap.shared;
029
030import org.opencms.db.CmsResourceState;
031import org.opencms.file.CmsResource;
032import org.opencms.gwt.shared.CmsClientLock;
033import org.opencms.gwt.shared.CmsPermissionInfo;
034import org.opencms.gwt.shared.property.CmsClientProperty;
035import org.opencms.util.CmsStringUtil;
036import org.opencms.util.CmsUUID;
037
038import java.util.ArrayList;
039import java.util.HashMap;
040import java.util.List;
041import java.util.Map;
042
043import com.google.gwt.user.client.rpc.IsSerializable;
044
045/**
046 * Sitemap entry data.<p>
047 *
048 * @since 8.0.0
049 */
050public class CmsClientSitemapEntry implements IsSerializable {
051
052    /**
053     * An enum for the edit status of the entry.<p>
054     */
055    public enum EditStatus {
056        /** edit status constant. */
057        created,
058        /** edit status constant. */
059        edited,
060        /** edit status constant. */
061        normal
062    }
063
064    /** An enum for the entry type. */
065    public enum EntryType {
066        /** The default type. An entry of type folder may have children. */
067        folder,
068
069        /** An entry of type leaf doesn't have any children. */
070        leaf,
071
072        /** A folder without default file, linking to it's first child entry. */
073        navigationLevel,
074
075        /** A redirect entry. */
076        redirect,
077
078        /** An entry of type sub-sitemap is a reference to a sub-sitemap. */
079        subSitemap
080    }
081
082    /** NavInfo property value to mark hidden navigation entries. */
083    public static final String HIDDEN_NAVIGATION_ENTRY = "ignoreInDefaultNav";
084
085    /** The entry aliases. */
086    private List<String> m_aliases;
087
088    /** The cached export name. */
089    private String m_cachedExportName;
090
091    /** True if the children of this entry have initially been loaded. */
092    private boolean m_childrenLoadedInitially;
093
094    /** The expiration date. */
095    private String m_dateExpired;
096
097    /** The release date. */
098    private String m_dateReleased;
099
100    /** The default file id. */
101    private CmsUUID m_defaultFileId;
102
103    /** The default file properties. */
104    private Map<String, CmsClientProperty> m_defaultFileProperties = new HashMap<String, CmsClientProperty>();
105
106    /** The default file is released and not expired flag. */
107    private boolean m_defaultFileReleased;
108
109    /** The default file resource type name. */
110    private String m_defaultFileType;
111
112    /** The detail page type name. */
113    private String m_detailpageTypeName;
114
115    /** The entry type. */
116    private EntryType m_entryType;
117
118    /** Locked child resources. */
119    private boolean m_hasBlockingLockedChildren;
120
121    /** Indicates if the entry folder is locked by another user. */
122    private boolean m_hasForeignFolderLock;
123
124    /** The entry id. */
125    private CmsUUID m_id;
126
127    /** Flag to indicate if the entry is visible in navigation. */
128    private boolean m_inNavigation;
129
130    /** Indicates if this entry represents the default page of the parent folder. */
131    private boolean m_isFolderDefaultPage;
132
133    /** Flag indicating the resource is released and not expired. */
134    private boolean m_isResleasedAndNotExpired;
135
136    /** The lock of the entry resource. */
137    private CmsClientLock m_lock;
138
139    /** The entry name. */
140    private String m_name;
141
142    /** The nav mode icon style classes. */
143    private String m_navModeIcon;
144
145    /** True if this entry has been just created, and its name hasn't been directly changed. */
146    private boolean m_new;
147
148    /** The properties for the entry itself. */
149    private Map<String, CmsClientProperty> m_ownProperties = new HashMap<String, CmsClientProperty>();
150
151    /** The permission info. */
152    private CmsPermissionInfo m_permissionInfo;
153
154    /** The relative position between siblings. */
155    private int m_position = -1;
156
157    /** The target in case of a redirect type. */
158    private String m_redirectTarget;
159
160    /** The resource state. */
161    private CmsResourceState m_resourceState;
162
163    /** The resource type id. */
164    private int m_resourceTypeId;
165
166    /** The resource type name. */
167    private String m_resourceTypeName;
168
169    /** The sitemap path. */
170    private String m_sitePath;
171
172    /** The children. */
173    private List<CmsClientSitemapEntry> m_subEntries;
174
175    /** The vfs mode icon style classes. */
176    private String m_vfsModeIcon;
177
178    /** The VFS path. */
179    private String m_vfsPath;
180
181    /**
182     * Constructor.<p>
183     */
184    public CmsClientSitemapEntry() {
185
186        m_subEntries = new ArrayList<CmsClientSitemapEntry>();
187        m_entryType = EntryType.folder;
188        m_defaultFileReleased = true;
189    }
190
191    /**
192     * Creates a copy without children of the given entry.<p>
193     *
194     * @param clone the entry to clone
195     */
196    public CmsClientSitemapEntry(CmsClientSitemapEntry clone) {
197
198        this();
199        copyMembers(clone);
200        setPosition(clone.getPosition());
201    }
202
203    /**
204    * Adds the given entry to the children.<p>
205    *
206    * @param entry the entry to add
207    * @param controller a sitemap controller instance
208    */
209    public void addSubEntry(CmsClientSitemapEntry entry, I_CmsSitemapController controller) {
210
211        entry.setPosition(m_subEntries.size());
212        entry.updateSitePath(CmsStringUtil.joinPaths(m_sitePath, entry.getName()), controller);
213        entry.setFolderDefaultPage(entry.isLeafType() && getVfsPath().equals(entry.getVfsPath()));
214        m_subEntries.add(entry);
215    }
216
217    /**
218     * Returns the aliases.<p>
219     *
220     * @return the aliases
221     */
222    public List<String> getAliases() {
223
224        return m_aliases;
225    }
226
227    /**
228     * Returns true if this item's children have been loaded initially.<p>
229     *
230     * @return true if this item's children have been loaded initially
231     */
232    public boolean getChildrenLoadedInitially() {
233
234        return m_childrenLoadedInitially;
235    }
236
237    /**
238     * Returns the expiration date.<p>
239     *
240     * @return the expiration date
241     */
242    public String getDateExpired() {
243
244        return m_dateExpired;
245    }
246
247    /**
248     * Returns the release date.<p>
249     *
250     * @return the release date
251     */
252    public String getDateReleased() {
253
254        return m_dateReleased;
255    }
256
257    /**
258     * Gets the default file id.<p>
259     *
260     * @return the default file id, or null if there is no detail page
261     */
262    public CmsUUID getDefaultFileId() {
263
264        return m_defaultFileId;
265    }
266
267    /**
268     * Returns the properties for the default file.<p>
269     *
270     * @return the properties for the default file
271     */
272    public Map<String, CmsClientProperty> getDefaultFileProperties() {
273
274        return m_defaultFileProperties;
275    }
276
277    /**
278     * Returns the default file resource type name.<p>
279     *
280     * @return the default file resource type name
281     */
282    public String getDefaultFileType() {
283
284        return m_defaultFileType;
285    }
286
287    /**
288     * Returns the detail resource type name.<p>
289     *
290     * @return the detail resource type name
291     */
292    public String getDetailpageTypeName() {
293
294        return m_detailpageTypeName;
295    }
296
297    /**
298     * Returns the entry type.<p>
299     *
300     * @return the entry type
301     */
302    public EntryType getEntryType() {
303
304        return m_entryType;
305    }
306
307    /**
308     * Returns the cached export name for this entry.<p>
309     *
310     * @return the cached export name for this entry
311     */
312    public String getExportName() {
313
314        return m_cachedExportName;
315    }
316
317    /**
318     * Returns the id.<p>
319     *
320     * @return the id
321     */
322    public CmsUUID getId() {
323
324        return m_id;
325    }
326
327    /**
328     * Returns the lock of the entry resource.<p>
329     *
330     * @return the lock of the entry resource
331     */
332    public CmsClientLock getLock() {
333
334        return m_lock;
335    }
336
337    /**
338     * Returns the name.<p>
339     *
340     * @return the name
341     */
342    public String getName() {
343
344        return m_name;
345    }
346
347    /**
348     * Returns the nav mode icon style classes.<p>
349     *
350     * @return the nav mode icon style classes
351     */
352    public String getNavModeIcon() {
353
354        return m_navModeIcon != null ? m_navModeIcon : m_vfsModeIcon;
355    }
356
357    /**
358     * Returns the no edit reason.<p>
359     *
360     * @return the no edit reason
361     */
362    public String getNoEditReason() {
363
364        return m_permissionInfo.getNoEditReason();
365    }
366
367    /**
368     * Returns the properties for the entry itself.<p>
369     *
370     * @return the properties for the entry itself
371     */
372    public Map<String, CmsClientProperty> getOwnProperties() {
373
374        return m_ownProperties;
375    }
376
377    /**
378     * Returns the position.<p>
379     *
380     * @return the position
381     */
382    public int getPosition() {
383
384        return m_position;
385    }
386
387    /**
388     * Returns the property value or null if not set.<p>
389     *
390     * @param propertyName the property name
391     *
392     * @return the property value
393     */
394    public String getPropertyValue(String propertyName) {
395
396        if (m_ownProperties.containsKey(propertyName)) {
397            return m_ownProperties.get(propertyName).getEffectiveValue();
398        }
399        return null;
400    }
401
402    /**
403     * Returns the redirect target.<p>
404     *
405     * @return the redirect target
406     */
407    public String getRedirectTarget() {
408
409        return m_redirectTarget;
410    }
411
412    /**
413     * Returns the resource state.<p>
414     *
415     * @return the resource state
416     */
417    public CmsResourceState getResourceState() {
418
419        return m_resourceState;
420    }
421
422    /**
423     * Returns the resource type id.<p>
424     *
425     * @return the resource type id
426     */
427    public int getResourceTypeId() {
428
429        return m_resourceTypeId;
430    }
431
432    /**
433     * Returns the resource type name.<p>
434     *
435     * @return the resource type name
436     */
437    public String getResourceTypeName() {
438
439        return m_resourceTypeName;
440    }
441
442    /**
443     * Returns the sitemap path.<p>
444     *
445     * @return the sitemap path
446     */
447    public String getSitePath() {
448
449        return m_sitePath;
450    }
451
452    /**
453     * Returns the children.<p>
454     *
455     * @return the children
456     */
457    public List<CmsClientSitemapEntry> getSubEntries() {
458
459        return m_subEntries;
460    }
461
462    /**
463     * Returns the title.<p>
464     *
465     * @return the title
466     */
467    public String getTitle() {
468
469        String title = getPropertyValue(CmsClientProperty.PROPERTY_NAVTEXT);
470        if (CmsStringUtil.isEmptyOrWhitespaceOnly(title)) {
471            title = getPropertyValue(CmsClientProperty.PROPERTY_TITLE);
472        }
473        if (CmsStringUtil.isEmptyOrWhitespaceOnly(title)) {
474            title = m_name;
475        }
476        return title;
477    }
478
479    /**
480     * Returns the vfs mode icon style classes.<p>
481     *
482     * @return the vfs mode icon style classes
483     */
484    public String getVfsModeIcon() {
485
486        return m_vfsModeIcon;
487    }
488
489    /**
490     * Returns the vfs path.<p>
491     *
492     * @return the vfs path
493     */
494    public String getVfsPath() {
495
496        return m_vfsPath;
497    }
498
499    /**
500     * Returns if this entry has blocking locked children.<p>
501     *
502     * @return <code>true</code> if this entry has blocking locked children
503     */
504    public boolean hasBlockingLockedChildren() {
505
506        return m_hasBlockingLockedChildren;
507    }
508
509    /**
510     * Returns if the entry folder is locked by another user.<p>
511     *
512     * @return <code>true</code> if the entry folder is locked by another user
513     */
514    public boolean hasForeignFolderLock() {
515
516        return m_hasForeignFolderLock;
517    }
518
519    /**
520     * Initializes this sitemap entry.<p>
521     *
522     * @param controller a sitemap controller instance
523     */
524    public void initialize(I_CmsSitemapController controller) {
525
526        m_ownProperties = controller.replaceProperties(m_id, m_ownProperties);
527        m_defaultFileProperties = controller.replaceProperties(m_defaultFileId, m_defaultFileProperties);
528        controller.registerEntry(this);
529    }
530
531    /**
532     * Initializes this sitemap entry and its descendants.<p>
533     *
534     * @param controller the controller instance with which to initialize the entries
535     */
536    public void initializeAll(I_CmsSitemapController controller) {
537
538        initialize(controller);
539        for (CmsClientSitemapEntry child : m_subEntries) {
540            child.initializeAll(controller);
541        }
542    }
543
544    /**
545     * Inserts the given entry at the given position.<p>
546     *
547     * @param entry the entry to insert
548     * @param position the position
549     * @param controller a sitemap controller instance
550     */
551    public void insertSubEntry(CmsClientSitemapEntry entry, int position, I_CmsSitemapController controller) {
552
553        entry.updateSitePath(CmsStringUtil.joinPaths(m_sitePath, entry.getName()), controller);
554        m_subEntries.add(position, entry);
555        updatePositions(position);
556    }
557
558    /**
559     * Returns the default file is released and not expired flag.<p>
560     *
561     * @return the default file is released and not expired flag
562     */
563    public boolean isDefaultFileReleased() {
564
565        return m_defaultFileReleased;
566    }
567
568    /**
569     * Returns if the current lock state allows editing.<p>
570     *
571     * @return <code>true</code> if the resource is editable
572     */
573    public boolean isEditable() {
574
575        return m_permissionInfo.hasWritePermission()
576            && CmsStringUtil.isEmptyOrWhitespaceOnly(getNoEditReason())
577            && !hasForeignFolderLock()
578            && !hasBlockingLockedChildren()
579            && (((getLock() == null) || (getLock().getLockOwner() == null)) || getLock().isOwnedByUser());
580    }
581
582    /**
583     * Returns if the entry is the folder default page.<p>
584     *
585     * @return if the entry is the folder default page
586     */
587    public boolean isFolderDefaultPage() {
588
589        return m_isFolderDefaultPage;
590    }
591
592    /**
593     * Returns if this entry is of type folder.<p>
594     *
595     * @return <code>true</code> if this entry is of type folder
596     */
597    public boolean isFolderType() {
598
599        return (EntryType.folder == m_entryType) || (EntryType.navigationLevel == m_entryType);
600    }
601
602    /**
603     * Returns if this is a hidden navigation entry.<p>
604     *
605     * @return <code>true</code> if this is a hidden navigation entry
606     */
607    public boolean isHiddenNavigationEntry() {
608
609        CmsClientProperty property = m_ownProperties.get(CmsClientProperty.PROPERTY_NAVINFO);
610        return (property != null) && HIDDEN_NAVIGATION_ENTRY.equals(property.getEffectiveValue());
611    }
612
613    /**
614     * Returns if the entry is visible in navigation.<p>
615     *
616     * @return <code>true</code> if the entry is visible in navigation
617     */
618    public boolean isInNavigation() {
619
620        return m_inNavigation;
621    }
622
623    /**
624     * Returns if this entry is of type leaf.<p>
625     *
626     * @return <code>true</code> if this entry is of type leaf
627     */
628    public boolean isLeafType() {
629
630        return (EntryType.leaf == m_entryType) || (EntryType.redirect == m_entryType);
631    }
632
633    /**
634     * Returns if this entry is of type folder.<p>
635     *
636     * @return <code>true</code> if this entry is of type folder
637     */
638    public boolean isNavigationLevelType() {
639
640        return EntryType.navigationLevel == m_entryType;
641    }
642
643    /**
644     * Returns the "new" flag of the sitemap entry.<p>
645     *
646     * @return the "new" flag
647     */
648    public boolean isNew() {
649
650        return m_new;
651    }
652
653    /**
654     * Returns if the resource is released and not expired.<p>
655     *
656     * @return <code>true</code> if the resource is released and not expired
657     */
658    public boolean isResleasedAndNotExpired() {
659
660        return m_isResleasedAndNotExpired;
661    }
662
663    /**
664     * Returns true if this entry is the root entry of the sitemap.<p>
665     *
666     * @return true if this entry is the root entry of the sitemap
667     */
668    public boolean isRoot() {
669
670        return m_name.equals("");
671    }
672
673    /**
674     * Returns if this entry is of type sub-sitemap.<p>
675     *
676     * @return <code>true</code> if this entry is of type sub-sitemap
677     */
678    public boolean isSubSitemapType() {
679
680        return EntryType.subSitemap == m_entryType;
681    }
682
683    /**
684     * Removes empty properties.<p>
685     */
686    public void normalizeProperties() {
687
688        CmsClientProperty.removeEmptyProperties(m_ownProperties);
689        if (m_defaultFileProperties != null) {
690            CmsClientProperty.removeEmptyProperties(m_defaultFileProperties);
691        }
692    }
693
694    /**
695     * Removes the child at the given position.<p>
696     *
697     * @param entryId the id of the child to remove
698     *
699     * @return the removed child
700     */
701    public CmsClientSitemapEntry removeSubEntry(CmsUUID entryId) {
702
703        CmsClientSitemapEntry removed = null;
704        int position = -1;
705        if (!m_subEntries.isEmpty()) {
706            for (int i = 0; i < m_subEntries.size(); i++) {
707                if (m_subEntries.get(i).getId().equals(entryId)) {
708                    position = i;
709                }
710            }
711            if (position != -1) {
712                removed = m_subEntries.remove(position);
713                updatePositions(position);
714            }
715
716        }
717        return removed;
718    }
719
720    /**
721     * Removes the child at the given position.<p>
722     *
723     * @param position the index of the child to remove
724     *
725     * @return the removed child
726     */
727    public CmsClientSitemapEntry removeSubEntry(int position) {
728
729        CmsClientSitemapEntry removed = m_subEntries.remove(position);
730        updatePositions(position);
731        return removed;
732    }
733
734    /**
735     * Sets the aliases.<p>
736     *
737     * @param aliases the aliases to set
738     */
739    public void setAliases(List<String> aliases) {
740
741        m_aliases = aliases;
742    }
743
744    /**
745     * Sets if the entry resource has blocking locked children that can not be locked by the current user.<p>
746     *
747     * @param hasBlockingLockedChildren <code>true</code> if the entry resource has blocking locked children
748     */
749    public void setBlockingLockedChildren(boolean hasBlockingLockedChildren) {
750
751        m_hasBlockingLockedChildren = hasBlockingLockedChildren;
752    }
753
754    /**
755     * Sets the 'children loaded initially' flag.<p>
756     *
757     * @param childrenLoaded <code>true</code> if children are loaded initially
758     */
759    public void setChildrenLoadedInitially(boolean childrenLoaded) {
760
761        m_childrenLoadedInitially = childrenLoaded;
762    }
763
764    /**
765     * Sets the expiration date.<p>
766     *
767     * @param dateExpired the expiration date to set
768     */
769    public void setDateExpired(String dateExpired) {
770
771        m_dateExpired = dateExpired;
772    }
773
774    /**
775     * Sets the release date.<p>
776     *
777     * @param dateReleased the release date to set
778     */
779    public void setDateReleased(String dateReleased) {
780
781        m_dateReleased = dateReleased;
782    }
783
784    /**
785     * Sets the default file id.
786     *
787     * @param defaultFileId the new default file id
788     **/
789    public void setDefaultFileId(CmsUUID defaultFileId) {
790
791        m_defaultFileId = defaultFileId;
792    }
793
794    /**
795     * Sets the properties for the default file.<p>
796     *
797     * @param properties the properties for the default file
798     */
799    public void setDefaultFileProperties(Map<String, CmsClientProperty> properties) {
800
801        m_defaultFileProperties = properties;
802    }
803
804    /**
805     * Sets the default file is released and not expired flag.<p>
806     *
807     * @param defaultFileReleased the default file is released and not expired flag to set
808     */
809    public void setDefaultFileReleased(boolean defaultFileReleased) {
810
811        m_defaultFileReleased = defaultFileReleased;
812    }
813
814    /**
815     * Sets the default file resource type name.<p>
816     *
817     * @param defaultFileType the default file resource type name to set
818     */
819    public void setDefaultFileType(String defaultFileType) {
820
821        m_defaultFileType = defaultFileType;
822    }
823
824    /**
825     * Sets the detail resource type name.<p>
826     *
827     * @param detailpageTypeName the detail resource type name
828     */
829    public void setDetailpageTypeName(String detailpageTypeName) {
830
831        m_detailpageTypeName = detailpageTypeName;
832    }
833
834    /**
835     * Sets the entry type.<p>
836     *
837     * @param entryType the entry type to set
838     */
839    public void setEntryType(EntryType entryType) {
840
841        m_entryType = entryType;
842    }
843
844    /**
845     * Sets the export name for this entry.<p>
846     *
847     * @param exportName the export name for this entry
848     */
849    public void setExportName(String exportName) {
850
851        m_cachedExportName = exportName;
852    }
853
854    /**
855     * Sets if the entry is the folder default page.<p>
856     *
857     * @param isFolderDefaultPage the isFolderDefaultPage to set
858     */
859    public void setFolderDefaultPage(boolean isFolderDefaultPage) {
860
861        m_isFolderDefaultPage = isFolderDefaultPage;
862    }
863
864    /**
865     * Sets if the entry folder is locked by another user.<p>
866     *
867     * @param hasForeignFolderLock set <code>true</code> if the entry folder is locked by another user
868     */
869    public void setHasForeignFolderLock(boolean hasForeignFolderLock) {
870
871        m_hasForeignFolderLock = hasForeignFolderLock;
872    }
873
874    /**
875     * Sets the id.<p>
876     *
877     * @param id the id to set
878     */
879    public void setId(CmsUUID id) {
880
881        m_id = id;
882    }
883
884    /**
885     * Sets the entry visibility in navigation.<p>
886     *
887     * @param inNavigation set <code>true</code> for entries visible in navigation
888     */
889    public void setInNavigation(boolean inNavigation) {
890
891        m_inNavigation = inNavigation;
892    }
893
894    /**
895     * Sets the lock of the entry resource.<p>
896     *
897     * @param lock the lock of the entry resource to set
898     */
899    public void setLock(CmsClientLock lock) {
900
901        m_lock = lock;
902    }
903
904    /**
905     * Sets the name.<p>
906     *
907     * @param name the name to set
908     */
909    public void setName(String name) {
910
911        m_name = name;
912    }
913
914    /**
915     * Sets the nav mode icon style classes.<p>
916     *
917     * @param iconClasses the nav mode icon style classes to set
918     */
919    public void setNavModeIcon(String iconClasses) {
920
921        m_navModeIcon = iconClasses;
922    }
923
924    /**
925     * Sets the "new" flag of the client sitemap entry.<p>
926     *
927     * @param isNew the new new
928     */
929    public void setNew(boolean isNew) {
930
931        m_new = isNew;
932    }
933
934    /**
935     * Sets the properties for the entry itself.<p>
936     *
937     * @param properties the properties for the entry itself
938     */
939    public void setOwnProperties(Map<String, CmsClientProperty> properties) {
940
941        m_ownProperties = properties;
942    }
943
944    /**
945     * Sets the permission info.<p>
946     *
947     * @param permissionInfo the permission info to set
948     */
949    public void setPermissionInfo(CmsPermissionInfo permissionInfo) {
950
951        m_permissionInfo = permissionInfo;
952    }
953
954    /**
955     * Sets the position.<p>
956     *
957     * @param position the position to set
958     */
959    public void setPosition(int position) {
960
961        m_position = position;
962    }
963
964    /**
965     * Sets the redirect target.<p>
966     *
967     * @param redirectTarget the redirect target to set
968     */
969    public void setRedirectTarget(String redirectTarget) {
970
971        m_redirectTarget = redirectTarget;
972    }
973
974    /**
975     * Sets the resource is released and not expired flag.<p>
976     *
977     * @param isResleasedAndNotExpired the resource is released and not expired flag
978     */
979    public void setResleasedAndNotExpired(boolean isResleasedAndNotExpired) {
980
981        m_isResleasedAndNotExpired = isResleasedAndNotExpired;
982    }
983
984    /**
985     * Sets the resource state.<p>
986     *
987     * @param resourceState the resource state to set
988     */
989    public void setResourceState(CmsResourceState resourceState) {
990
991        m_resourceState = resourceState;
992    }
993
994    /**
995     * Sets the resource type id.<p>
996     *
997     * @param resourceTypeId the resource type id
998     */
999    public void setResourceTypeId(int resourceTypeId) {
1000
1001        m_resourceTypeId = resourceTypeId;
1002    }
1003
1004    /**
1005     * Sets the resource type name.<p>
1006     *
1007     * @param typeName the resource type name
1008     */
1009    public void setResourceTypeName(String typeName) {
1010
1011        m_resourceTypeName = typeName;
1012
1013    }
1014
1015    /**
1016     * Sets the site path.<p>
1017     *
1018     * @param sitepath the site path to set
1019     */
1020    public void setSitePath(String sitepath) {
1021
1022        if (!isLeafType() && !sitepath.endsWith("/")) {
1023            sitepath = sitepath + "/";
1024        }
1025        m_sitePath = sitepath;
1026    }
1027
1028    /**
1029     * Sets the children.<p>
1030     *
1031     * @param children the children to set
1032     * @param controller a sitemap controller instance
1033     */
1034    public void setSubEntries(List<CmsClientSitemapEntry> children, I_CmsSitemapController controller) {
1035
1036        m_childrenLoadedInitially = true;
1037
1038        m_subEntries.clear();
1039        if (children != null) {
1040            m_subEntries.addAll(children);
1041            for (CmsClientSitemapEntry child : children) {
1042                child.updateSitePath(CmsStringUtil.joinPaths(m_sitePath, child.getName()), controller);
1043            }
1044        }
1045    }
1046
1047    /**
1048     * Sets the vfs mode icon style classes.<p>
1049     *
1050     * @param iconClasses the vfs mode icon style classes to set
1051     */
1052    public void setVfsModeIcon(String iconClasses) {
1053
1054        m_vfsModeIcon = iconClasses;
1055    }
1056
1057    /**
1058     * Sets the VFS path.<p>
1059     *
1060     * @param path the path to set
1061     */
1062    public void setVfsPath(String path) {
1063
1064        m_vfsPath = path;
1065    }
1066
1067    /**
1068     * To string.
1069     *
1070     * @return the string
1071     * @see java.lang.Object#toString()
1072     */
1073    @Override
1074    public String toString() {
1075
1076        StringBuffer sb = new StringBuffer();
1077        sb.append(m_sitePath).append("\n");
1078        for (CmsClientSitemapEntry child : m_subEntries) {
1079            sb.append(child.toString());
1080        }
1081        return sb.toString();
1082    }
1083
1084    /**
1085     * Updates all entry properties apart from it's position-info and sub-entries.<p>
1086     *
1087     * @param source the source entry to update from
1088     */
1089    public void update(CmsClientSitemapEntry source) {
1090
1091        copyMembers(source);
1092        // position values < 0 are considered as not set
1093        if (source.getPosition() >= 0) {
1094            setPosition(source.getPosition());
1095        }
1096    }
1097
1098    /**
1099     * Updates the entry's site path and the name accordingly.<p>
1100     *
1101     * @param sitepath the new site path to set
1102     * @param controller a sitemap controller instance
1103     */
1104    public void updateSitePath(String sitepath, I_CmsSitemapController controller) {
1105
1106        if (!isLeafType() && !sitepath.endsWith("/")) {
1107            sitepath = sitepath + "/";
1108        }
1109        if (!m_sitePath.equals(sitepath)) {
1110            // update the vfs path as well
1111            int start = m_vfsPath.lastIndexOf(m_sitePath);
1112            int stop = start + m_sitePath.length();
1113            m_vfsPath = CmsStringUtil.joinPaths(m_vfsPath.substring(0, start), sitepath, m_vfsPath.substring(stop));
1114            if (isLeafType() && m_vfsPath.endsWith("/")) {
1115                m_vfsPath = m_vfsPath.substring(0, m_vfsPath.length() - 1);
1116            }
1117            String oldPath = m_sitePath;
1118            m_sitePath = sitepath;
1119            String name = CmsResource.getName(sitepath);
1120            if (name.endsWith("/")) {
1121                name = name.substring(0, name.length() - 1);
1122            }
1123            m_name = name;
1124            for (CmsClientSitemapEntry child : m_subEntries) {
1125                child.updateSitePath(CmsStringUtil.joinPaths(sitepath, child.getName()), controller);
1126            }
1127            if (controller != null) {
1128                controller.registerPathChange(this, oldPath);
1129            }
1130        }
1131    }
1132
1133    /**
1134     * Copies all member variables apart from sub-entries and position.<p>
1135     *
1136     * @param source the source to copy from
1137     */
1138    private void copyMembers(CmsClientSitemapEntry source) {
1139
1140        setId(source.getId());
1141        setName(source.getName());
1142        setOwnProperties(new HashMap<String, CmsClientProperty>(source.getOwnProperties()));
1143        setDefaultFileId(source.getDefaultFileId());
1144        setDefaultFileType(source.getDefaultFileType());
1145        Map<String, CmsClientProperty> defaultFileProperties = source.getDefaultFileProperties();
1146        if (defaultFileProperties == null) {
1147            defaultFileProperties = new HashMap<String, CmsClientProperty>();
1148        }
1149        setDefaultFileProperties(new HashMap<String, CmsClientProperty>(defaultFileProperties));
1150        if (source.getDetailpageTypeName() != null) {
1151            // do not copy the detail page type name unless it is not null, otherwise newly created detail pages
1152            // are not displayed correctly in the sitemap editor.
1153            setDetailpageTypeName(source.getDetailpageTypeName());
1154        }
1155        setSitePath(source.getSitePath());
1156        setVfsPath(source.getVfsPath());
1157        setLock(source.getLock());
1158        setEntryType(source.getEntryType());
1159        setInNavigation(source.isInNavigation());
1160        setHasForeignFolderLock(source.hasForeignFolderLock());
1161        setBlockingLockedChildren(source.hasBlockingLockedChildren());
1162        setFolderDefaultPage(source.isFolderDefaultPage());
1163        setResourceTypeName(source.getResourceTypeName());
1164        setChildrenLoadedInitially(source.getChildrenLoadedInitially());
1165        setFolderDefaultPage(source.isFolderDefaultPage());
1166        setDateExpired(source.getDateExpired());
1167        setDateReleased(source.getDateReleased());
1168        setResleasedAndNotExpired(source.isResleasedAndNotExpired());
1169        setDefaultFileReleased(source.isDefaultFileReleased());
1170        setAliases(source.getAliases());
1171        setRedirectTarget(source.getRedirectTarget());
1172        setResourceState(source.getResourceState());
1173        setPermissionInfo(source.m_permissionInfo);
1174    }
1175
1176    /**
1177     * Updates all the children positions starting from the given position.<p>
1178     *
1179     * @param position the position to start with
1180     */
1181    private void updatePositions(int position) {
1182
1183        for (int i = position; i < m_subEntries.size(); i++) {
1184            m_subEntries.get(i).setPosition(i);
1185        }
1186    }
1187
1188}