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.xml.content;
029
030import org.opencms.xml.I_CmsXmlDocument;
031import org.opencms.xml.types.I_CmsXmlContentValue;
032
033import java.util.ArrayList;
034import java.util.List;
035import java.util.Locale;
036
037/**
038 * Represents the root of an XML content for a given locale.<p>
039 *
040 * @since 8.0.0
041 */
042public class CmsXmlContentRootLocation implements I_CmsXmlContentLocation {
043
044    /** The XML document. */
045    private I_CmsXmlDocument m_document;
046
047    /** The locale. */
048    private Locale m_locale;
049
050    /**
051     * Creates a new root location for a given locale.<p>
052     *
053     * @param doc the XML document
054     * @param locale the locale
055     */
056    public CmsXmlContentRootLocation(I_CmsXmlDocument doc, Locale locale) {
057
058        m_document = doc;
059        m_locale = locale;
060    }
061
062    /**
063     * @see org.opencms.xml.content.I_CmsXmlContentLocation#getDocument()
064     */
065    public I_CmsXmlDocument getDocument() {
066
067        return m_document;
068    }
069
070    /**
071     * @see org.opencms.xml.content.I_CmsXmlContentLocation#getLocale()
072     */
073    public Locale getLocale() {
074
075        return m_locale;
076    }
077
078    /**
079     * @see org.opencms.xml.content.I_CmsXmlContentLocation#getSubValue(java.lang.String)
080     */
081    public I_CmsXmlContentValueLocation getSubValue(String subPath) {
082
083        I_CmsXmlContentValue value = m_document.getValue(subPath, m_locale);
084        if (value == null) {
085            return null;
086        }
087        return new CmsXmlContentValueLocation(value);
088    }
089
090    /**
091     * @see org.opencms.xml.content.I_CmsXmlContentLocation#getSubValues(java.lang.String)
092     */
093    public List<I_CmsXmlContentValueLocation> getSubValues(String subPath) {
094
095        List<I_CmsXmlContentValue> values = m_document.getValues(subPath, m_locale);
096        List<I_CmsXmlContentValueLocation> result = new ArrayList<I_CmsXmlContentValueLocation>();
097        for (I_CmsXmlContentValue value : values) {
098            if (value != null) {
099                result.add(new CmsXmlContentValueLocation(value));
100            }
101        }
102        return result;
103    }
104}