001/*
002 * File   : $Source$
003 * Date   : $Date$
004 * Version: $Revision$
005 *
006 * This library is part of OpenCms -
007 * the Open Source Content Management System
008 *
009 * Copyright (C) 2002 - 2011 Alkacon Software (http://www.alkacon.com)
010 *
011 * This library is free software; you can redistribute it and/or
012 * modify it under the terms of the GNU Lesser General Public
013 * License as published by the Free Software Foundation; either
014 * version 2.1 of the License, or (at your option) any later version.
015 *
016 * This library is distributed in the hope that it will be useful,
017 * but WITHOUT ANY WARRANTY; without even the implied warranty of
018 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
019 * Lesser General Public License for more details.
020 *
021 * For further information about Alkacon Software, please see the
022 * company website: http://www.alkacon.com
023 *
024 * For further information about OpenCms, please see the
025 * project website: http://www.opencms.org
026 *
027 * You should have received a copy of the GNU Lesser General Public
028 * License along with this library; if not, write to the Free Software
029 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
030 */
031
032package org.opencms.ade.containerpage.inherited;
033
034import org.opencms.xml.containerpage.CmsContainerElementBean;
035
036import java.util.Collections;
037import java.util.HashMap;
038import java.util.LinkedHashMap;
039import java.util.List;
040import java.util.Map;
041
042/**
043 * A bean representing a single configuration entry for the inherited container configuration.<p>
044 *
045 */
046public class CmsContainerConfiguration {
047
048    /** Node name. **/
049    public static final String N_CONFIGURATION = "Configuration";
050
051    /** Node name. **/
052    public static final String N_ELEMENT = "Element";
053
054    /** Node name. **/
055    public static final String N_HIDDEN = "Hidden";
056
057    /** Node name. **/
058    public static final String N_KEY = "Key";
059
060    /** Node name. **/
061    public static final String N_NAME = "Name";
062
063    /** Node name. **/
064    public static final String N_NEWELEMENT = "NewElement";
065
066    /** Node name. **/
067    public static final String N_ORDERKEY = "OrderKey";
068
069    /** Node name. **/
070    public static final String N_URI = "Uri";
071
072    /** Node name. **/
073    public static final String N_VISIBLE = "Visible";
074
075    /** A map containing the new elements. */
076    private Map<String, CmsContainerElementBean> m_newElements;
077
078    /** A list of keys for a new ordering of elements. **/
079    private List<String> m_ordering;
080
081    /** The path from which the configuration was fetched. */
082    private String m_path;
083
084    /** A map from element keys to Booleans, representing hidden/shown elements. */
085    private Map<String, Boolean> m_visibility;
086
087    /**
088     * Creates a new instance.<p>
089     *
090     * @param ordering the new ordering list
091     * @param visibility the visibility map
092     * @param newElements the new elements
093     */
094    public CmsContainerConfiguration(
095        List<String> ordering,
096        Map<String, Boolean> visibility,
097        Map<String, CmsContainerElementBean> newElements) {
098
099        m_ordering = ordering != null ? Collections.unmodifiableList(ordering) : null;
100        m_visibility = Collections.unmodifiableMap(visibility);
101        m_newElements = Collections.unmodifiableMap(newElements);
102    }
103
104    /**
105     * Generates an empty configuration object.<p>
106     *
107     * @return an empty configuration object
108     */
109    public static CmsContainerConfiguration emptyConfiguration() {
110
111        return new CmsContainerConfiguration(
112            null,
113            new HashMap<String, Boolean>(),
114            new HashMap<String, CmsContainerElementBean>());
115    }
116
117    /**
118     * Gets the map of new elements.<p>
119     *
120     * @return the map of new elements
121     */
122    public Map<String, CmsContainerElementBean> getNewElements() {
123
124        return m_newElements;
125    }
126
127    /**
128     * Gets the new elements in the order in which they appear in the 'ordering' list.<p>
129     *
130     * @return an ordered map containing the new elements in the correct order
131     */
132    public LinkedHashMap<String, CmsContainerElementBean> getNewElementsInOrder() {
133
134        LinkedHashMap<String, CmsContainerElementBean> result = new LinkedHashMap<String, CmsContainerElementBean>();
135        if (m_ordering != null) {
136            for (String orderKey : m_ordering) {
137                CmsContainerElementBean element = m_newElements.get(orderKey);
138                if (element != null) {
139                    result.put(orderKey, element);
140                }
141            }
142            return result;
143        }
144        return new LinkedHashMap<String, CmsContainerElementBean>();
145    }
146
147    /**
148     * Gets the ordering list.<p>
149     *
150     * @return the ordering list
151     */
152    public List<String> getOrdering() {
153
154        return m_ordering;
155    }
156
157    /**
158     * Gets the path from which this configuration was read.<p>
159     *
160     * @return the path from which this configuration was read
161     */
162    public String getPath() {
163
164        return m_path;
165    }
166
167    /**
168     * Gets the visibility map for this configuration.<p>
169     *
170     * @return the visibility map
171     */
172    public Map<String, Boolean> getVisibility() {
173
174        return m_visibility;
175    }
176
177    /**
178     * Sets the path for this configuration.<p>
179     *
180     * @param path the new path value
181     */
182    public void setPath(String path) {
183
184        m_path = path;
185    }
186
187}