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.formatters.CmsSettingConfiguration;
031import org.opencms.ade.configuration.plugins.CmsTemplatePlugin;
032import org.opencms.file.types.CmsResourceTypeFunctionConfig;
033import org.opencms.util.CmsUUID;
034
035import java.util.Arrays;
036import java.util.Collection;
037import java.util.Collections;
038import java.util.HashMap;
039import java.util.List;
040import java.util.Map;
041import java.util.Set;
042
043/**
044 * A bean containing formatter configuration data as strings.<p>
045 */
046public class CmsFunctionFormatterBean extends CmsFormatterBean {
047
048    /** The standard function formatter structure id. */
049    private CmsUUID m_functionFormatterId;
050
051    /** The request parameters to add for the included JSP. */
052    private Map<String, String[]> m_parameters = new HashMap<>();
053
054    /** The real path of the configured jsp. */
055    private String m_realJspRootPath;
056
057    /**
058     * Constructor for creating a new formatter configuration with resource structure id.<p>
059     *
060     * @param containerTypes the formatter container types
061     * @param jspRootPath the formatter JSP VFS root path
062     * @param jspStructureId the structure id of the formatter JSP
063     * @param key the key
064     * @param aliasKeys the alias keys
065     * @param functionFormatterId the standard function formatter structure id
066     * @param minWidth the formatter min width
067     * @param maxWidth the formatter max width
068     * @param location the location where this formatter was defined, should be an OpenCms VFS resource path
069     * @param cssHeadIncludes the CSS head includes
070     * @param inlineCss the in-line CSS
071     * @param javascriptHeadIncludes the JavaScript headincludes
072     * @param inlineJavascript the in-line JavaScript
073     * @param plugins the template plugins
074     * @param niceName the configuration display name
075     * @param description the description text for the formatter
076     * @param id the configuration id
077     * @param settingConfig the settings configuration
078     * @param isAllowsSettingsInEditor whether this formatter allows settings to be edited in the content editor
079     * @param isStrictContainers <code>true</code> if this formatter will always render all nested containers
080     * @param parameters the request parameters to add for the included JSP
081     */
082    public CmsFunctionFormatterBean(
083        Set<String> containerTypes,
084        String jspRootPath,
085        CmsUUID jspStructureId,
086        String key,
087        Set<String> aliasKeys,
088        CmsUUID functionFormatterId,
089        int minWidth,
090        int maxWidth,
091        String location,
092        List<String> cssHeadIncludes,
093        String inlineCss,
094        List<String> javascriptHeadIncludes,
095        String inlineJavascript,
096        List<CmsTemplatePlugin> plugins,
097        String niceName,
098        String description,
099        String id,
100        CmsSettingConfiguration settingConfig,
101        boolean isAllowsSettingsInEditor,
102        boolean isStrictContainers,
103        Map<String, String[]> parameters) {
104
105        super(
106            containerTypes,
107            jspRootPath,
108            jspStructureId,
109            key,
110            aliasKeys,
111            minWidth,
112            maxWidth,
113            true, // preview
114            false, // searchContent
115            location,
116            cssHeadIncludes,
117            inlineCss,
118            javascriptHeadIncludes,
119            inlineJavascript,
120            plugins,
121            niceName,
122            description,
123            Arrays.asList(CmsResourceTypeFunctionConfig.TYPE_NAME),
124            10099, // rank
125            id,
126            settingConfig,
127            true, //isFromConfigFile
128            true, // isAutoEnabled
129            false, // detailType
130            null, // isDisplay
131            isAllowsSettingsInEditor,
132            isStrictContainers,
133            false, // nestedFormatterSettings
134            Collections.<CmsMetaMapping> emptyList(),
135            Collections.emptyMap(),
136            false);
137        m_realJspRootPath = jspRootPath;
138        m_functionFormatterId = functionFormatterId;
139        if (parameters != null) {
140            m_parameters.putAll(parameters);
141        }
142    }
143
144    /**
145     * @see org.opencms.xml.containerpage.CmsFormatterBean#getJspRootPath()
146     *
147     * This is not the configured JSP, but the formatter JSP for the function_config type itself.
148     */
149    @Override
150    public String getJspRootPath() {
151
152        return CmsResourceTypeFunctionConfig.FORMATTER_PATH;
153    }
154
155    /**
156     * @see org.opencms.xml.containerpage.CmsFormatterBean#getJspStructureId()
157     *
158     * This is not the configured JSP, but the formatter JSP for the function_config type itself.
159     */
160    @Override
161    public CmsUUID getJspStructureId() {
162
163        return m_functionFormatterId;
164    }
165
166    /**
167     * Gets the parameters the dynamic function should set for the included JSP.<p>
168     *
169     * @return the map of parameters to add for the included JSP
170     */
171    public Map<String, String[]> getParameters() {
172
173        return Collections.unmodifiableMap(m_parameters);
174    }
175
176    /**
177     * @see org.opencms.xml.containerpage.I_CmsFormatterBean#getRank()
178     */
179    @Override
180    public int getRank() {
181
182        return 1000;
183    }
184
185    /**
186     * Gets the <em>actual</em> JSP id of the function.<p>
187     *
188     * @return the JSP structure id
189     */
190    public CmsUUID getRealJspId() {
191
192        return super.getJspStructureId();
193    }
194
195    /**
196     * Gets the root path of the configured JSP.<p>
197     *
198     * @return the root path of the configured JSP
199     */
200    public String getRealJspRootPath() {
201
202        return m_realJspRootPath;
203    }
204
205    /**
206     * @see org.opencms.xml.containerpage.I_CmsFormatterBean#getResourceTypeNames()
207     */
208    @Override
209    public Collection<String> getResourceTypeNames() {
210
211        return Collections.singletonList(CmsResourceTypeFunctionConfig.TYPE_NAME);
212    }
213
214}