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 GmbH & Co. KG, 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.file.types;
029
030import org.opencms.configuration.CmsConfigurationException;
031import org.opencms.configuration.CmsParameterConfiguration;
032import org.opencms.main.OpenCms;
033import org.opencms.util.CmsStringUtil;
034
035/**
036 * Resource type descriptor for the type "folder".<p>
037 *
038 * @since 6.0.0
039 */
040public class CmsResourceTypeFolder extends A_CmsResourceTypeFolderBase {
041
042    /** Configuration key for the optional list of resource types to show as available index page types. */
043    public static final String CONFIGURATION_INDEX_PAGE_TYPE = "restypes.indexpage";
044
045    /** The type id of this resource. */
046    public static final int RESOURCE_TYPE_ID = 0;
047
048    /** The name of this resource type. */
049    public static final String RESOURCE_TYPE_NAME = "folder";
050
051    /** Indicates that the static configuration of the resource type has been frozen. */
052    private static boolean m_staticFrozen;
053
054    /** The static type id of this resource type. */
055    private static int m_staticTypeId;
056
057    /** The serial version id. */
058    private static final long serialVersionUID = -6627448037959709694L;
059
060    /** The configured list of resource types to show as available index page types. */
061    private String m_indexPageTypes;
062
063    /**
064     * Default constructor, used to initialize member variables.<p>
065     */
066    public CmsResourceTypeFolder() {
067
068        super();
069        m_typeId = RESOURCE_TYPE_ID;
070        m_typeName = RESOURCE_TYPE_NAME;
071    }
072
073    /**
074     * Returns the static type id of this (default) resource type.<p>
075     *
076     * @return the static type id of this (default) resource type
077     */
078    public static int getStaticTypeId() {
079
080        return m_staticTypeId;
081    }
082
083    /**
084     * Returns the static type name of this (default) resource type.<p>
085     *
086     * @return the static type name of this (default) resource type
087     */
088    public static String getStaticTypeName() {
089
090        return RESOURCE_TYPE_NAME;
091    }
092
093    /**
094     * @see org.opencms.file.types.A_CmsResourceType#addConfigurationParameter(java.lang.String, java.lang.String)
095     */
096    @Override
097    public void addConfigurationParameter(String paramName, String paramValue) {
098
099        super.addConfigurationParameter(paramName, paramValue);
100        if (CmsStringUtil.isNotEmpty(paramName) && CmsStringUtil.isNotEmpty(paramValue)) {
101            if (CONFIGURATION_INDEX_PAGE_TYPE.equalsIgnoreCase(paramName)) {
102                m_indexPageTypes = paramValue.trim();
103            }
104        }
105    }
106
107    /**
108     * @see org.opencms.file.types.A_CmsResourceType#getConfiguration()
109     */
110    @Override
111    public CmsParameterConfiguration getConfiguration() {
112
113        CmsParameterConfiguration result = new CmsParameterConfiguration();
114        CmsParameterConfiguration additional = super.getConfiguration();
115        if ((additional != null) && (additional.size() > 0)) {
116            result.putAll(additional);
117        }
118        if (CmsStringUtil.isNotEmpty(getIndexPageTypes())) {
119            result.put(CONFIGURATION_INDEX_PAGE_TYPE, getIndexPageTypes());
120        }
121        return result;
122    }
123
124    /**
125     * Returns the indexPageTypes.<p>
126     *
127     * @return the indexPageTypes
128     */
129    public String getIndexPageTypes() {
130
131        return m_indexPageTypes;
132    }
133
134    /**
135     * @see org.opencms.file.types.A_CmsResourceType#initConfiguration(java.lang.String, java.lang.String, String)
136     */
137    @Override
138    public void initConfiguration(String name, String id, String className) throws CmsConfigurationException {
139
140        if ((OpenCms.getRunLevel() > OpenCms.RUNLEVEL_2_INITIALIZING) && m_staticFrozen) {
141            // configuration already frozen
142            throw new CmsConfigurationException(
143                Messages.get().container(
144                    Messages.ERR_CONFIG_FROZEN_3,
145                    this.getClass().getName(),
146                    getStaticTypeName(),
147                    Integer.valueOf(getStaticTypeId())));
148        }
149
150        if (!RESOURCE_TYPE_NAME.equals(name)) {
151            // default resource type MUST have default name
152            throw new CmsConfigurationException(
153                Messages.get().container(
154                    Messages.ERR_INVALID_RESTYPE_CONFIG_NAME_3,
155                    this.getClass().getName(),
156                    RESOURCE_TYPE_NAME,
157                    name));
158        }
159
160        // freeze the configuration
161        m_staticFrozen = true;
162
163        super.initConfiguration(RESOURCE_TYPE_NAME, id, className);
164        // set static members with values from the configuration
165        m_staticTypeId = m_typeId;
166    }
167}