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.ade.configuration.CmsADEManager;
031import org.opencms.util.CmsUUID;
032
033import java.util.LinkedHashMap;
034
035import com.google.gwt.user.client.rpc.IsSerializable;
036
037/**
038 * Sitemap clipboard data bean.<p>
039 *
040 * @since 8.0
041 */
042public class CmsSitemapClipboardData implements IsSerializable {
043
044    /** The session stored list of deleted sitemap entries. */
045    private LinkedHashMap<CmsUUID, CmsClientSitemapEntry> m_deletions;
046
047    /** The session stored list of modified sitemap entry paths. */
048    private LinkedHashMap<CmsUUID, CmsClientSitemapEntry> m_modifications;
049
050    /**
051     * Constructor.<p>
052     */
053    public CmsSitemapClipboardData() {
054
055        m_deletions = new LinkedHashMap<CmsUUID, CmsClientSitemapEntry>();
056        m_modifications = new LinkedHashMap<CmsUUID, CmsClientSitemapEntry>();
057    }
058
059    /**
060     * Constructor.<p>
061     *
062     * @param deletions the session stored list of deleted sitemap entries
063     * @param modifications the session stored list of modified sitemap entry paths
064     */
065    public CmsSitemapClipboardData(
066        LinkedHashMap<CmsUUID, CmsClientSitemapEntry> deletions,
067        LinkedHashMap<CmsUUID, CmsClientSitemapEntry> modifications) {
068
069        m_deletions = deletions;
070        m_modifications = modifications;
071    }
072
073    /**
074     * Adds an entry to the deleted list.<p>
075     *
076     * @param entry the entry to add
077     */
078    public void addDeleted(CmsClientSitemapEntry entry) {
079
080        if (m_deletions.containsKey(entry.getId())) {
081            m_deletions.remove(entry.getId());
082        }
083        m_deletions.put(entry.getId(), entry);
084        checkMapSize(m_deletions);
085    }
086
087    /**
088     * Adds an entry to the modified list.<p>
089     *
090     * @param entry the entry to add
091     */
092    public void addModified(CmsClientSitemapEntry entry) {
093
094        if (m_modifications.containsKey(entry.getId())) {
095            m_modifications.remove(entry.getId());
096        }
097        m_modifications.put(entry.getId(), entry);
098        checkMapSize(m_modifications);
099    }
100
101    /**
102     * Provides a copy of the clip-board data.<p>
103     *
104     * @return the copied data
105     */
106    public CmsSitemapClipboardData copy() {
107
108        LinkedHashMap<CmsUUID, CmsClientSitemapEntry> deletions = new LinkedHashMap<CmsUUID, CmsClientSitemapEntry>();
109        deletions.putAll(m_deletions);
110        LinkedHashMap<CmsUUID, CmsClientSitemapEntry> modifications = new LinkedHashMap<CmsUUID, CmsClientSitemapEntry>();
111        modifications.putAll(m_modifications);
112        return new CmsSitemapClipboardData(deletions, modifications);
113    }
114
115    /**
116     * Returns the session stored list of deleted sitemap entries.<p>
117     *
118     * @return the session stored list of deleted sitemap entries
119     */
120    public LinkedHashMap<CmsUUID, CmsClientSitemapEntry> getDeletions() {
121
122        return m_deletions;
123    }
124
125    /**
126     * Returns the session stored list of modified sitemap entry paths.<p>
127     *
128     * @return the session stored list of modified sitemap entry paths
129     */
130    public LinkedHashMap<CmsUUID, CmsClientSitemapEntry> getModifications() {
131
132        return m_modifications;
133    }
134
135    /**
136     * Removes an entry from the deleted list.<p>
137     *
138     * @param entry the entry to remove
139     */
140    public void removeDeleted(CmsClientSitemapEntry entry) {
141
142        m_deletions.remove(entry.getId());
143    }
144
145    /**
146     * Removes an entry from the modified list.<p>
147     *
148     * @param entry the entry to remove
149     */
150    public void removeModified(CmsClientSitemapEntry entry) {
151
152        m_modifications.remove(entry.getId());
153    }
154
155    /**
156     * Sets list of deleted sitemap entries.<p>
157     *
158     * @param deletions the deleted sitemap entries
159     */
160    public void setDeletions(LinkedHashMap<CmsUUID, CmsClientSitemapEntry> deletions) {
161
162        m_deletions = deletions;
163        checkMapSize(m_deletions);
164    }
165
166    /**
167     * Sets the list of modified sitemap entry paths.<p>
168     *
169     * @param modifications the list of modified sitemap entry paths
170     */
171    public void setModifications(LinkedHashMap<CmsUUID, CmsClientSitemapEntry> modifications) {
172
173        m_modifications = modifications;
174        checkMapSize(m_modifications);
175    }
176
177    /**
178     * Checks map size to remove entries in case it exceeds the default list size.<p>
179     *
180     * @param map the map to check
181     */
182    private void checkMapSize(LinkedHashMap<?, ?> map) {
183
184        while (map.size() > CmsADEManager.DEFAULT_ELEMENT_LIST_SIZE) {
185            map.remove(map.keySet().iterator().next());
186        }
187    }
188}