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.containerpage;
029
030import org.opencms.main.OpenCms;
031import org.opencms.util.CmsUUID;
032import org.opencms.xml.content.CmsXmlContentProperty;
033
034import java.util.Collection;
035import java.util.Collections;
036import java.util.LinkedHashMap;
037import java.util.List;
038import java.util.Map;
039import java.util.Map.Entry;
040import java.util.Set;
041
042/**
043 * Formatter configuration for macro formatters.<p>
044 */
045public class CmsMacroFormatterBean extends CmsFormatterBean {
046
047    /** The root path to the default content. */
048    private String m_defaultContentRootPath;
049
050    /** The UUID of the default content resource. */
051    private CmsUUID m_defaultContentStructureId;
052
053    /** The macro input. */
054    private String m_macroInput;
055
056    /** The online flag. */
057    private boolean m_online;
058
059    /** The placeholder macro input. */
060    private String m_placeholderMacroInput;
061
062    /** The referenced formatters. */
063    private Map<String, CmsUUID> m_referencedFormatters;
064
065    /**
066     * Constructor for creating a new formatter configuration with resource structure id.<p>
067     *
068     * @param containerTypes the formatter container types
069     * @param jspRootPath the formatter JSP VFS root path
070     * @param jspStructureId the structure id of the formatter JSP
071     * @param minWidth the formatter min width
072     * @param maxWidth the formatter max width
073     * @param searchContent indicates if the content should be searchable in the online index when this formatter is used
074     * @param location the location where this formatter was defined, should be an OpenCms VFS resource path
075     * @param niceName the configuration display name
076     * @param description the description
077     * @param resourceTypeNames the resource type names
078     * @param rank the configuration rank
079     * @param id the configuration id
080     * @param defaultContentRootPath the root path to the default content
081     * @param defaultContentStructureId the UUID of the default content resource
082     * @param settings the settings configuration
083     * @param isDetail <code>true</code> if detail formatter
084     * @param isAutoEnabled <code>true</code> if auto enabled
085     * @param displayType the display type
086     * @param isAllowsSettingsInEditor whether this formatter allows settings to be edited in the content editor
087     * @param macroInput the macro input
088     * @param placeholderMacroInput the placeholder macro input
089     * @param referencedFormatters the referenced formatters
090     * @param online if this is the online version
091     * @param metaMappings the meta mappings
092     * @param useMetaMappingsForNormalElements if true, meta mappings will be evaluated for normal container elements, not just detail elements
093     */
094    public CmsMacroFormatterBean(
095        Set<String> containerTypes,
096        String jspRootPath,
097        CmsUUID jspStructureId,
098        int minWidth,
099        int maxWidth,
100        boolean searchContent,
101        String location,
102        String niceName,
103        String description,
104        Collection<String> resourceTypeNames,
105        int rank,
106        String id,
107        String defaultContentRootPath,
108        CmsUUID defaultContentStructureId,
109        Map<String, CmsXmlContentProperty> settings,
110        boolean isAutoEnabled,
111        boolean isDetail,
112        String displayType,
113        boolean isAllowsSettingsInEditor,
114        String macroInput,
115        String placeholderMacroInput,
116        Map<String, CmsUUID> referencedFormatters,
117        boolean online,
118        List<CmsMetaMapping> metaMappings,
119        boolean useMetaMappingsForNormalElements) {
120
121        super(
122            containerTypes,
123            jspRootPath,
124            jspStructureId,
125            minWidth,
126            maxWidth,
127            false,
128            searchContent,
129            location,
130            Collections.<String> emptyList(),
131            "",
132            Collections.<String> emptyList(),
133            "",
134            niceName,
135            description,
136            resourceTypeNames,
137            rank,
138            id,
139            settings,
140            true,
141            isAutoEnabled,
142            isDetail,
143            displayType,
144            isAllowsSettingsInEditor,
145            false,
146            false,
147            metaMappings,
148            Collections.emptyMap(),
149            useMetaMappingsForNormalElements);
150        m_macroInput = macroInput;
151        m_placeholderMacroInput = placeholderMacroInput;
152        m_referencedFormatters = Collections.unmodifiableMap(referencedFormatters);
153        m_online = online;
154        m_defaultContentRootPath = defaultContentRootPath;
155        m_defaultContentStructureId = defaultContentStructureId;
156    }
157
158    /**
159     * Returns the root path to the default content.<p>
160     *
161     * @return the root path to the default content
162     */
163    public String getDefaultContentRootPath() {
164
165        return m_defaultContentRootPath;
166    }
167
168    /**
169     * Returns the UUID of the default content.<p>
170     *
171     * @return the UUID of the default content
172     */
173    public CmsUUID getDefaultContentStructureId() {
174
175        return m_defaultContentStructureId;
176    }
177
178    /**
179     * Returns the macro input.<p>
180     *
181     * @return the macro input
182     */
183    public String getMacroInput() {
184
185        return m_macroInput;
186    }
187
188    /**
189     * Returns the placeholder macro input.<p>
190     *
191     * @return the placeholder macro input
192     */
193    public String getPlaceholderMacroInput() {
194
195        return m_placeholderMacroInput;
196    }
197
198    /**
199     * The referenced formatters.<p>
200     *
201     * @return the reference formatters
202     */
203    public Map<String, CmsUUID> getReferencedFormatters() {
204
205        return m_referencedFormatters;
206    }
207
208    /**
209     * @see org.opencms.xml.containerpage.CmsFormatterBean#getSettings()
210     */
211    @Override
212    public Map<String, CmsXmlContentProperty> getSettings() {
213
214        LinkedHashMap<String, CmsXmlContentProperty> settings = new LinkedHashMap<String, CmsXmlContentProperty>(
215            super.getSettings());
216        for (CmsUUID formatterId : m_referencedFormatters.values()) {
217            I_CmsFormatterBean formatter = OpenCms.getADEManager().getCachedFormatters(m_online).getFormatters().get(
218                formatterId);
219            if (formatter != null) {
220                for (Entry<String, CmsXmlContentProperty> entry : formatter.getSettings().entrySet()) {
221                    if (!settings.containsKey(entry.getKey())) {
222                        settings.put(entry.getKey(), entry.getValue());
223                    }
224                }
225            }
226        }
227        return settings;
228    }
229}