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.ade.containerpage.shared;
029
030import org.opencms.util.CmsStringUtil;
031import org.opencms.xml.content.CmsXmlContentProperty;
032
033import java.util.Map;
034import java.util.Set;
035
036import com.google.gwt.user.client.rpc.IsSerializable;
037
038/**
039 * Formatter configuration data.<p>
040 */
041public class CmsFormatterConfig implements IsSerializable {
042
043    /** Key for the formatter configuration id setting. Append the container name to the key, to store container depending values. */
044    public static final String FORMATTER_SETTINGS_KEY = "formatterSettings#";
045
046    /** Id used for schema based formatters. */
047    public static final String SCHEMA_FORMATTER_ID = "schema_formatter";
048
049    /** The required css resources. */
050    private Set<String> m_cssResources;
051
052    /** The formatter configuration id. */
053    private String m_id;
054
055    /** The inline CSS. */
056    private String m_inlineCss;
057
058    /** The formatter root path. */
059    private String m_jspRootPath;
060
061    /** The formatter label. */
062    private String m_label;
063
064    /** Contains the nested formatters prefixes and their labels. */
065    private Map<String, String> m_nestedFormatterPrefixes;
066
067    /** The setting for this container element. */
068    private Map<String, CmsXmlContentProperty> m_settingConfig;
069
070    /** The description. */
071    private String m_description;
072
073    private String m_key;
074
075    /**
076     * Constructor.<p>
077     *
078     * @param id the formatter id
079     */
080    public CmsFormatterConfig(String id) {
081
082        m_id = id;
083    }
084
085    /**
086     * Constructor for serialization only.<p>
087     */
088    protected CmsFormatterConfig() {
089
090        // nothing to to
091    }
092
093    /**
094     * Returns the formatter configuration settings key for the given container name.<p>
095     *
096     * @param containerName the container name
097     *
098     * @return the settings key
099     */
100    public static String getSettingsKeyForContainer(String containerName) {
101
102        return FORMATTER_SETTINGS_KEY + containerName;
103    }
104
105    /**
106     * Returns the required CSS resources.<p>
107     *
108     * @return the CSS resources
109     */
110    public Set<String> getCssResources() {
111
112        return m_cssResources;
113    }
114
115    /**
116     * Gets the description.<p>
117     *
118     * @return the description
119     */
120    public String getDescription() {
121
122        return m_description;
123    }
124
125    /**
126     * Returns the formatter configuration id.<p>
127     *
128     * @return the configuration id
129     */
130    public String getId() {
131
132        return m_id;
133    }
134
135    /**
136     * Returns the inline CSS.<p>
137     *
138     * @return the inline CSS
139     */
140    public String getInlineCss() {
141
142        return m_inlineCss;
143    }
144
145    /**
146     * Returns the formatter root path.<p>
147     *
148     * @return the formatter root path
149     */
150    public String getJspRootPath() {
151
152        return m_jspRootPath;
153    }
154
155    public String getKey() {
156
157        return m_key;
158    }
159
160    public String getKeyOrId() {
161
162        if (m_key != null) {
163            return m_key;
164        }
165        return getId();
166    }
167
168    /**
169     * Returns the formatter label.<p>
170     *
171     * @return the label
172     */
173    public String getLabel() {
174
175        return m_label;
176    }
177
178    /**
179     * Returns the nested formatters prefixes and their labels.<p>
180     *
181     * @return the nested formatters prefixes and their labels
182     */
183    public Map<String, String> getNestedFormatterPrefixes() {
184
185        return m_nestedFormatterPrefixes;
186    }
187
188    /**
189     * Returns the settings configuration.<p>
190     *
191     * @return the settings configuration
192     */
193    public Map<String, CmsXmlContentProperty> getSettingConfig() {
194
195        return m_settingConfig;
196    }
197
198    /**
199     * Returns if the formatter has inline CSS.<p>
200     *
201     * @return <code>true</code> if the formatter has inline CSS
202     */
203    public boolean hasInlineCss() {
204
205        return CmsStringUtil.isNotEmptyOrWhitespaceOnly(m_inlineCss);
206    }
207
208    /**
209     * Sets the required CSS resources.<p>
210     *
211     * @param cssResources the CSS resources
212     */
213    public void setCssResources(Set<String> cssResources) {
214
215        m_cssResources = cssResources;
216    }
217
218    /**
219     * Sets the description.<p>
220     *
221     * @param description the description
222     */
223    public void setDescription(String description) {
224
225        m_description = description;
226    }
227
228    /**
229     * Sets the inline CSS.<p>
230     *
231     * @param inlineCss the inline CSS
232     */
233    public void setInlineCss(String inlineCss) {
234
235        m_inlineCss = inlineCss;
236    }
237
238    /**
239     * Sets the formatter root path.<p>
240     *
241     * @param jspRootPath the formatter root path
242     */
243    public void setJspRootPath(String jspRootPath) {
244
245        m_jspRootPath = jspRootPath;
246    }
247
248    public void setKey(String key) {
249
250        m_key = key;
251    }
252
253    /**
254     * Sets the formatter label.<p>
255     *
256     * @param label the label
257     */
258    public void setLabel(String label) {
259
260        m_label = label;
261    }
262
263    /**
264     * Sets the nested formatters prefixes and their labels.<p>
265     *
266     * @param nestedFormatterPrefixes the nested formatters prefixes and their labels to set
267     */
268    public void setNestedFormatterPrefixes(Map<String, String> nestedFormatterPrefixes) {
269
270        m_nestedFormatterPrefixes = nestedFormatterPrefixes;
271    }
272
273    /**
274     * Sets the settings configuration.<p>
275     *
276     * @param settingConfig the settings configuration
277     */
278    public void setSettingConfig(Map<String, CmsXmlContentProperty> settingConfig) {
279
280        m_settingConfig = settingConfig;
281    }
282}