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 java.util.ArrayList;
031import java.util.Collections;
032import java.util.List;
033
034/**
035 * Geo-coordinate mapping configuration for an XML content schema.
036 *
037 * <p>Consists of a list of entries, where each entry has a type and a value.
038 */
039public class CmsGeoMappingConfiguration {
040
041    /**
042     * A single configuration entry.
043     */
044    public static class Entry {
045
046        /** The mapping type. */
047        private EntryType m_type;
048
049        /** The parameter value. */
050        private String m_value;
051
052        /**
053         * Creates a new entry.
054         *
055         * @param type the entry type
056         * @param value the entry parameter value
057         */
058        public Entry(EntryType type, String value) {
059
060            super();
061            m_type = type;
062            m_value = value;
063            if (m_value == null) {
064                m_value = "";
065            } else {
066                m_value = m_value.trim();
067            }
068        }
069
070        /**
071         * Gets the mapping type.
072         *
073         * @return the mapping type
074         */
075        public EntryType getType() {
076
077            return m_type;
078        }
079
080        /**
081         * Gets the mapping parameter value.
082         *
083         * @return the mapping parameter value
084         *
085         */
086        public String getValue() {
087
088            return m_value;
089        }
090
091        /**
092         * @see java.lang.Object#toString()
093         */
094        @Override
095        public String toString() {
096
097            return "" + m_type + ":" + m_value;
098        }
099    }
100
101    /**
102     * Enum representing the type of a single configuration entry in a geomapping configuration.
103     */
104    public enum EntryType {
105        /** Take value from a content field. */
106        field,
107
108        /** Take value from another resource, the link to which is contained in a content field. */
109        link
110    }
111
112    /** The list of configuration entries. */
113    private List<Entry> m_entries = new ArrayList<>();
114
115    /**
116     * Creates a configuration from a list of configuration entries.
117     *
118     * @param configEntries the configuration entries.
119     */
120    public CmsGeoMappingConfiguration(List<Entry> configEntries) {
121
122        m_entries = new ArrayList<>(configEntries);
123    }
124
125    /**
126     * Gets the configuration entries.
127     *
128     * @return the list of configuration entries
129     */
130    public List<Entry> getEntries() {
131
132        return Collections.unmodifiableList(m_entries);
133    }
134
135    /**
136     * @see java.lang.Object#toString()
137     */
138    @Override
139    public String toString() {
140
141        return "CmsGeoMappingConfiguration:" + m_entries.toString();
142    }
143
144}