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.file.CmsObject;
031import org.opencms.file.CmsResource;
032import org.opencms.main.CmsLog;
033import org.opencms.main.OpenCms;
034import org.opencms.util.CmsUUID;
035import org.opencms.xml.content.CmsXmlContentProperty;
036import org.opencms.xml.content.I_CmsXmlContentHandler;
037
038import java.util.ArrayList;
039import java.util.Collection;
040import java.util.Collections;
041import java.util.List;
042import java.util.Locale;
043import java.util.Map;
044import java.util.Set;
045
046import org.apache.commons.logging.Log;
047
048/**
049 * Wrapper class for formatter beans which delegates all methods to the wrapped formatter bean except those
050 * for which we need to ask the content handler for additional data like element settings or head includes.<p>
051 */
052public class CmsSchemaFormatterBeanWrapper implements I_CmsFormatterBean {
053
054    /** Logger instance for this class. */
055    private static final Log LOG = CmsLog.getLog(CmsSchemaFormatterBeanWrapper.class);
056
057    /** The CMS context to use. */
058    private CmsObject m_cms;
059
060    /** The content handler to use. */
061    private I_CmsXmlContentHandler m_contentHandler;
062
063    /** The resource to use. */
064    private CmsResource m_elementResource;
065
066    /** The wrapped formatter. */
067    private I_CmsFormatterBean m_wrappedFormatter;
068
069    /**
070     * Creates a new wrapper instance.<p>
071     *
072     * @param cms the CMS context to use
073     * @param wrappedBean the wrapped formatter
074     * @param contentHandler the content handler to ask for additional information
075     * @param resource the resource which should be used to ask the content handler for additional information
076     */
077    public CmsSchemaFormatterBeanWrapper(
078        CmsObject cms,
079        I_CmsFormatterBean wrappedBean,
080        I_CmsXmlContentHandler contentHandler,
081        CmsResource resource) {
082
083        m_elementResource = resource;
084        m_contentHandler = contentHandler;
085        m_wrappedFormatter = wrappedBean;
086        m_cms = cms;
087    }
088
089    /**
090     * @see org.opencms.xml.containerpage.I_CmsFormatterBean#getAttributes()
091     */
092    public Map<String, String> getAttributes() {
093
094        return Collections.emptyMap();
095    }
096
097    /**
098     * @see org.opencms.xml.containerpage.I_CmsFormatterBean#getContainerTypes()
099     */
100    public Set<String> getContainerTypes() {
101
102        return m_wrappedFormatter.getContainerTypes();
103    }
104
105    /**
106     * @see org.opencms.xml.containerpage.I_CmsFormatterBean#getCssHeadIncludes()
107     */
108    public Set<String> getCssHeadIncludes() {
109
110        try {
111            return m_contentHandler.getCSSHeadIncludes(m_cms, m_elementResource);
112        } catch (Exception e) {
113            LOG.error(e.getLocalizedMessage(), e);
114            return Collections.emptySet();
115        }
116    }
117
118    /**
119     * @see org.opencms.xml.containerpage.I_CmsFormatterBean#getDescription(Locale)
120     */
121    public String getDescription(Locale locale) {
122
123        return m_wrappedFormatter.getDescription(locale);
124    }
125
126    /**
127     * @see org.opencms.xml.containerpage.I_CmsFormatterBean#getDisplayType()
128     */
129    public String getDisplayType() {
130
131        return null;
132    }
133
134    /**
135     * @see org.opencms.xml.containerpage.I_CmsFormatterBean#getId()
136     */
137    public String getId() {
138
139        return m_wrappedFormatter.getId();
140    }
141
142    /**
143     * @see org.opencms.xml.containerpage.I_CmsFormatterBean#getInlineCss()
144     */
145    public String getInlineCss() {
146
147        return "";
148    }
149
150    /**
151     * @see org.opencms.xml.containerpage.I_CmsFormatterBean#getInlineJavascript()
152     */
153    public String getInlineJavascript() {
154
155        return "";
156    }
157
158    /**
159     * @see org.opencms.xml.containerpage.I_CmsFormatterBean#getJavascriptHeadIncludes()
160     */
161    public List<String> getJavascriptHeadIncludes() {
162
163        try {
164            return new ArrayList<String>(m_contentHandler.getJSHeadIncludes(m_cms, m_elementResource));
165        } catch (Exception e) {
166            LOG.error(e.getLocalizedMessage(), e);
167            return Collections.emptyList();
168        }
169    }
170
171    /**
172     * @see org.opencms.xml.containerpage.I_CmsFormatterBean#getJspRootPath()
173     */
174    public String getJspRootPath() {
175
176        return m_wrappedFormatter.getJspRootPath();
177    }
178
179    /**
180     * @see org.opencms.xml.containerpage.I_CmsFormatterBean#getJspStructureId()
181     */
182    public CmsUUID getJspStructureId() {
183
184        return m_wrappedFormatter.getJspStructureId();
185    }
186
187    /**
188     * @see org.opencms.xml.containerpage.I_CmsFormatterBean#getLocation()
189     */
190    public String getLocation() {
191
192        return m_wrappedFormatter.getLocation();
193    }
194
195    /**
196     * @see org.opencms.xml.containerpage.I_CmsFormatterBean#getMaxWidth()
197     */
198    public int getMaxWidth() {
199
200        return m_wrappedFormatter.getMaxWidth();
201    }
202
203    /**
204     * @see org.opencms.xml.containerpage.I_CmsFormatterBean#getMetaMappings()
205     */
206    public List<CmsMetaMapping> getMetaMappings() {
207
208        return null;
209    }
210
211    /**
212     * @see org.opencms.xml.containerpage.I_CmsFormatterBean#getMinWidth()
213     */
214    public int getMinWidth() {
215
216        return m_wrappedFormatter.getMinWidth();
217    }
218
219    /**
220     * @see org.opencms.xml.containerpage.I_CmsFormatterBean#getNiceName(Locale)
221     */
222    public String getNiceName(Locale locale) {
223
224        return m_wrappedFormatter.getNiceName(locale);
225    }
226
227    /**
228     *
229     * @see org.opencms.xml.containerpage.I_CmsFormatterBean#getRank()
230     */
231    public int getRank() {
232
233        return m_wrappedFormatter.getRank();
234    }
235
236    /**
237     *
238     * @see org.opencms.xml.containerpage.I_CmsFormatterBean#getResourceTypeNames()
239     */
240    public Collection<String> getResourceTypeNames() {
241
242        try {
243            return Collections.singleton(OpenCms.getResourceManager().getResourceType(m_elementResource).getTypeName());
244        } catch (Exception e) {
245            LOG.error(e.getLocalizedMessage(), e);
246            return Collections.singleton("xmlcontent");
247        }
248    }
249
250    /**
251     *
252     * @see org.opencms.xml.containerpage.I_CmsFormatterBean#getSettings()
253     */
254    public Map<String, CmsXmlContentProperty> getSettings() {
255
256        return m_contentHandler.getSettings(m_cms, m_elementResource);
257    }
258
259    /**
260     * @see org.opencms.xml.containerpage.I_CmsFormatterBean#hasNestedFormatterSettings()
261     */
262    public boolean hasNestedFormatterSettings() {
263
264        return false;
265    }
266
267    /**
268     * @see org.opencms.xml.containerpage.I_CmsFormatterBean#isAllowsSettingsInEditor()
269     */
270    public boolean isAllowsSettingsInEditor() {
271
272        // not supported by schema formatters
273        return false;
274    }
275
276    /**
277     *
278     * @see org.opencms.xml.containerpage.I_CmsFormatterBean#isAutoEnabled()
279     */
280    public boolean isAutoEnabled() {
281
282        return m_wrappedFormatter.isAutoEnabled();
283    }
284
285    /**
286     * @see org.opencms.xml.containerpage.I_CmsFormatterBean#isDetailFormatter()
287     */
288    public boolean isDetailFormatter() {
289
290        return true;
291    }
292
293    /**
294     * @see org.opencms.xml.containerpage.I_CmsFormatterBean#isDisplayFormatter()
295     */
296    public boolean isDisplayFormatter() {
297
298        return false;
299    }
300
301    /**
302     *
303     * @see org.opencms.xml.containerpage.I_CmsFormatterBean#isFromFormatterConfigFile()
304     */
305    public boolean isFromFormatterConfigFile() {
306
307        return m_wrappedFormatter.isFromFormatterConfigFile();
308    }
309
310    /**
311     * @see org.opencms.xml.containerpage.I_CmsFormatterBean#isMatchAll()
312     */
313    public boolean isMatchAll() {
314
315        return m_wrappedFormatter.isMatchAll();
316    }
317
318    /**
319     * @see org.opencms.xml.containerpage.I_CmsFormatterBean#isPreviewFormatter()
320     */
321    public boolean isPreviewFormatter() {
322
323        return m_wrappedFormatter.isPreviewFormatter();
324    }
325
326    /**
327     * @see org.opencms.xml.containerpage.I_CmsFormatterBean#isSearchContent()
328     */
329    public boolean isSearchContent() {
330
331        return m_wrappedFormatter.isSearchContent();
332    }
333
334    /**
335     * @see org.opencms.xml.containerpage.I_CmsFormatterBean#isTypeFormatter()
336     */
337    public boolean isTypeFormatter() {
338
339        return m_wrappedFormatter.isTypeFormatter();
340    }
341
342    /**
343     * @see org.opencms.xml.containerpage.I_CmsFormatterBean#setJspStructureId(org.opencms.util.CmsUUID)
344     */
345    public void setJspStructureId(CmsUUID jspStructureId) {
346
347        m_wrappedFormatter.setJspStructureId(jspStructureId);
348    }
349
350    /**
351     * @see org.opencms.xml.containerpage.I_CmsFormatterBean#useMetaMappingsForNormalElements()
352     */
353    @Override
354    public boolean useMetaMappingsForNormalElements() {
355
356        return false;
357    }
358
359}