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