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.file.CmsResource;
035import org.opencms.i18n.CmsLocaleManager;
036import org.opencms.util.CmsUUID;
037
038import java.util.Locale;
039import java.util.Map;
040
041/**
042 * A class which represents all the configuration entries which have been read from an inherited container
043 * configuration file.<p>
044 *
045 */
046public class CmsContainerConfigurationGroup {
047
048    /** The configurations grouped by locales. */
049    private Map<Locale, Map<String, CmsContainerConfiguration>> m_configurations;
050
051    /** Root path of the file from which this configuration was read. */
052    private String m_rootPath;
053
054    /** Structure id of the file from which this configuration was read. */
055    private CmsUUID m_structureId;
056
057    /**
058     * Creates a new instance.<p>
059     *
060     * @param configurations the data contained by this configuration group
061     */
062    public CmsContainerConfigurationGroup(Map<Locale, Map<String, CmsContainerConfiguration>> configurations) {
063
064        m_configurations = configurations;
065    }
066
067    /**
068     * Gets the configuration for a given name and locale.<p>
069     *
070     * @param name the configuration name
071     *
072     * @return the configuration for the name and locale
073     */
074    public CmsContainerConfiguration getConfiguration(String name) {
075
076        Map<String, CmsContainerConfiguration> configurationsForLocale = null;
077        if (m_configurations.containsKey(CmsLocaleManager.MASTER_LOCALE)) {
078            configurationsForLocale = m_configurations.get(CmsLocaleManager.MASTER_LOCALE);
079        } else if (!m_configurations.isEmpty()) {
080            configurationsForLocale = m_configurations.values().iterator().next();
081        } else {
082            return null;
083        }
084        return configurationsForLocale.get(name);
085    }
086
087    /**
088     * Gets the root path of the file from which this configuration was read.<p>
089     *
090     * @return the root path of the configuration resource
091     */
092    public String getRootPath() {
093
094        return m_rootPath;
095
096    }
097
098    /**
099     * Gets the structure id of the file from which this configuration was read.<p>
100     *
101     * @return the structure id of the configuration file
102     */
103    public CmsUUID getStructureId() {
104
105        return m_structureId;
106    }
107
108    /**
109     * Initializes the information about the resource from which this configuration was read.<p>
110     *
111     * @param configResource the configuration file
112     */
113    public void setResource(CmsResource configResource) {
114
115        m_structureId = configResource.getStructureId();
116        m_rootPath = configResource.getRootPath();
117    }
118}