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.galleries.shared;
029
030import org.opencms.gwt.shared.CmsIconBean;
031import org.opencms.util.CmsStringUtil;
032import org.opencms.util.CmsUUID;
033
034import java.util.ArrayList;
035import java.util.List;
036
037/**
038 * A sitemap entry bean.<p>
039 */
040public class CmsSitemapEntryBean extends CmsIconBean implements I_CmsGalleryTreeEntry<CmsSitemapEntryBean> {
041
042    /** The entry children. */
043    private List<CmsSitemapEntryBean> m_children;
044
045    /** The is folder flag. */
046    private boolean m_isFolder;
047
048    /** The hidden entry flag. */
049    private boolean m_isHiddenEntry;
050
051    /** Flag indicating whether this is entry should be displayed at the top level of the tree. */
052    private boolean m_isRoot;
053
054    /** True if this is a search match. */
055    private boolean m_isSearchMatch;
056
057    /** The root path. */
058    private String m_rootPath;
059
060    /** The site path of this VFS entry. */
061    private String m_sitePath;
062
063    /** The site root of the site to which this entry bean belongs. */
064    private String m_siteRoot;
065
066    /** The entry id. */
067    private CmsUUID m_structureId;
068
069    /** The folder title. */
070    private String m_title;
071
072    /** The resource type. */
073    private String m_type;
074
075    /**
076     * Constructor.<p>
077     *
078     * @param rootPath the root path
079     * @param sitePath the site path
080     * @param structureId the entry id
081     * @param title the title
082     * @param type the resource type
083     * @param isFolder <code>true</code> if this entry represents a folder
084     * @param isRoot <code>true</code> if this is a site root entry
085     * @param isHiddenEntry <code>true</code> if this is a hidden entry
086     */
087    public CmsSitemapEntryBean(
088        String rootPath,
089        String sitePath,
090        CmsUUID structureId,
091        String title,
092        String type,
093        boolean isFolder,
094        boolean isRoot,
095        boolean isHiddenEntry) {
096
097        m_rootPath = rootPath;
098        m_sitePath = sitePath;
099        m_structureId = structureId;
100        m_title = title;
101        m_type = type;
102        m_isFolder = isFolder;
103        m_isRoot = isRoot;
104        m_isHiddenEntry = isHiddenEntry;
105    }
106
107    /**
108     * Constructor for serialization only.<p>
109     */
110    protected CmsSitemapEntryBean() {
111
112        // nothing to do
113    }
114
115    /**
116     * @see org.opencms.ade.galleries.shared.I_CmsGalleryTreeEntry#addChild(java.lang.Object)
117     */
118    public void addChild(CmsSitemapEntryBean child) {
119
120        if (m_children == null) {
121            m_children = new ArrayList<CmsSitemapEntryBean>();
122        }
123        m_children.add(child);
124    }
125
126    /**
127     * Returns the children of this entry or <code>null</code> if not loaded.<p>
128     *
129     * @return the children of the entry
130     */
131    public List<CmsSitemapEntryBean> getChildren() {
132
133        return m_children;
134    }
135
136    /**
137     * Gets the name which should be displayed in the widget representing this VFS entry.<p>
138     *
139     * @return the name to display
140     */
141    public String getDisplayName() {
142
143        if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(m_title)) {
144            return m_title;
145        }
146        if (m_isRoot) {
147            return m_sitePath;
148        } else {
149            String fixedPath = m_sitePath.replaceFirst("/$", "");
150            int lastSlash = fixedPath.lastIndexOf('/');
151            if (lastSlash == -1) {
152                return fixedPath;
153            }
154            return fixedPath.substring(lastSlash + 1);
155        }
156    }
157
158    /**
159     * Gets the root path of the sitemap entry.<p>
160     *
161     * @return the root path of the sitemap entry
162     */
163    public String getRootPath() {
164
165        return m_rootPath;
166    }
167
168    /**
169     * Returns the site path of this VFS tree.
170     *
171     * @return the site path
172     */
173    public String getSitePath() {
174
175        return m_sitePath;
176    }
177
178    /**
179     * Gets the site root.<p>
180     *
181     * @return the site root
182     */
183    public String getSiteRoot() {
184
185        return m_siteRoot;
186    }
187
188    /**
189     * Returns the entry structure id.<p>
190     *
191     * @return the entry structure id
192     */
193    public CmsUUID getStructureId() {
194
195        return m_structureId;
196    }
197
198    /**
199     * Returns the type.<p>
200     *
201     * @return the type
202     */
203    public String getType() {
204
205        return m_type;
206    }
207
208    /**
209     * Returns if the children of this entry have been loaded.<p>
210     *
211     * @return <code>true</code> if the children of this entry have been loaded
212     */
213    public boolean hasChildren() {
214
215        return m_children != null;
216    }
217
218    /**
219     * Returns the isFolder.<p>
220     *
221     * @return the isFolder
222     */
223    public boolean isFolder() {
224
225        return m_isFolder;
226    }
227
228    /**
229     * Returns if this is a hidden entry.<p>
230     *
231     * @return <code>true</code> if this is a hidden entry
232     */
233    public boolean isHiddenEntry() {
234
235        return m_isHiddenEntry;
236    }
237
238    /**
239     * Returns true if this entry is a top-level entry.<p>
240     *
241     * @return true if this is a top-level entry
242     */
243    public boolean isRoot() {
244
245        return m_isRoot;
246    }
247
248    /**
249     * Returns true if this is a search match.<p>
250     *
251     * @return true if this is a search match
252     */
253    public boolean isSearchMatch() {
254
255        return m_isSearchMatch;
256    }
257
258    /**
259     * Sets the children of this entry.<p>
260     *
261     * @param children the children
262     */
263    public void setChildren(List<CmsSitemapEntryBean> children) {
264
265        m_children = children;
266    }
267
268    /**
269     * Marks this entry as a search match.<p>
270     *
271     * @param isSearchMatch true if this is a search match
272     */
273    public void setSearchMatch(boolean isSearchMatch) {
274
275        m_isSearchMatch = isSearchMatch;
276    }
277
278    /**
279     * Sets the site root for this bean.<p>
280     *
281     * @param siteRoot the site root
282     */
283    public void setSiteRoot(String siteRoot) {
284
285        m_siteRoot = siteRoot;
286    }
287
288    /**
289     * @see java.lang.Object#toString()
290     */
291    @Override
292    public String toString() {
293
294        return "CmsSitemapEntryBean(rootpath=" + m_rootPath + ",sitepath=" + m_sitePath + ")";
295    }
296
297}