001/*
002 * This library is part of OpenCms -
003 * the Open Source Content Management System
004 *
005 * Copyright (C) Alkacon Software (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.CmsException;
033import org.opencms.xml.content.CmsDefaultXmlContentHandler;
034import org.opencms.xml.content.CmsXmlContentProperty;
035
036import java.util.ArrayList;
037import java.util.Collections;
038import java.util.List;
039import java.util.Map;
040
041/**
042 * This is the XML content handler class for the "dynamic functionality" resource type.<p>
043 *
044 * This resource type needs special handling of formatters and element settings: They are
045 * read from each content of this type rather than from the XSD.<p>
046 */
047public class CmsXmlDynamicFunctionHandler extends CmsDefaultXmlContentHandler {
048
049    /** The node name for the formatter settings. */
050    public static final String N_CONTAINER_SETTINGS = "ContainerSettings";
051
052    /** The resource type for dynamic functions. */
053    public static final String TYPE_FUNCTION = "function";
054
055    /**
056     * Default constructor.<p>
057     */
058    public CmsXmlDynamicFunctionHandler() {
059
060        super();
061    }
062
063    /**
064     * @see org.opencms.xml.content.CmsDefaultXmlContentHandler#getFormatterConfiguration(org.opencms.file.CmsObject, org.opencms.file.CmsResource)
065     */
066    @Override
067    public CmsFormatterConfiguration getFormatterConfiguration(CmsObject cms, CmsResource resource) {
068
069        try {
070            CmsDynamicFunctionParser parser = new CmsDynamicFunctionParser();
071            CmsDynamicFunctionBean functionBean = parser.parseFunctionBean(cms, resource);
072            List<CmsFormatterBean> formatters = functionBean.getFormatters();
073            List<I_CmsFormatterBean> wrappers = new ArrayList<I_CmsFormatterBean>();
074            for (CmsFormatterBean formatter : formatters) {
075                wrappers.add(new CmsSchemaFormatterBeanWrapper(cms, formatter, this, resource));
076            }
077            return CmsFormatterConfiguration.create(cms, wrappers);
078        } catch (CmsException e) {
079            return CmsFormatterConfiguration.EMPTY_CONFIGURATION;
080        }
081    }
082
083    /**
084     * @see org.opencms.xml.content.CmsDefaultXmlContentHandler#getSettings(org.opencms.file.CmsObject, org.opencms.file.CmsResource)
085     */
086    @Override
087    public Map<String, CmsXmlContentProperty> getSettings(CmsObject cms, CmsResource res) {
088
089        try {
090            CmsDynamicFunctionParser parser = new CmsDynamicFunctionParser();
091            CmsDynamicFunctionBean functionBean = parser.parseFunctionBean(cms, res);
092            return functionBean.getSettings();
093        } catch (CmsException e) {
094            return Collections.<String, CmsXmlContentProperty> emptyMap();
095        }
096    }
097
098    /**
099     * @see org.opencms.xml.content.CmsDefaultXmlContentHandler#hasModifiableFormatters()
100     */
101    @Override
102    public boolean hasModifiableFormatters() {
103
104        return false;
105    }
106
107}