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.file.CmsResource;
032
033import java.util.ArrayList;
034import java.util.List;
035
036/**
037 * Resource type descriptor for sub site map folder types.<p>
038 *
039 * This type extends an extended folder with a configurable type id and type name.<p>
040 *
041 * @since 8.5.0
042 */
043public class CmsResourceTypeFolderSubSitemap extends CmsResourceTypeFolderExtended {
044
045    /** The type name for subsitemaps. */
046    public static final String TYPE_SUBSITEMAP = "subsitemap";
047
048    /** The registered sub site map resource type id's.    */
049    private static List<Integer> m_subSitemapResourceTypeIds = new ArrayList<Integer>();
050
051    /** The serial version id. */
052    private static final long serialVersionUID = 3152961195421254155L;
053
054    /**
055     * Returns the registered sub site map resource type id's.<p>
056     *
057     * @return the resource type id's
058     */
059    public static List<Integer> getSubSitemapResourceTypeIds() {
060
061        return m_subSitemapResourceTypeIds;
062    }
063
064    /**
065     * Returns <code>true</code> in case the given resource is a sub site map.<p>
066     *
067     * Internally this checks if the given resource type has an id that is registered as a sub site map resource type.<p>
068     *
069     * @param resource the resource to check
070     *
071     * @return <code>true</code> in case the given resource is a sub site map
072     *
073     * @since 8.0.0
074     */
075    public static boolean isSubSitemap(CmsResource resource) {
076
077        return resource == null ? false : isSubSitemapTypeId(resource.getTypeId());
078    }
079
080    /**
081     * Returns <code>true</code> in case the given resource type id is a sub site map type.<p>
082     *
083     * Internally this checks if the given resource type id is registered as a sub site map resource type.<p>
084     *
085     * @param typeId the resource type id to check
086     *
087     * @return <code>true</code> in case the given resource type id is a sub site map type
088     *
089     * @since 8.0.0
090     */
091    public static boolean isSubSitemapTypeId(int typeId) {
092
093        return m_subSitemapResourceTypeIds.contains(Integer.valueOf(typeId));
094    }
095
096    /**
097     * @see org.opencms.file.types.A_CmsResourceType#initConfiguration(java.lang.String, java.lang.String, String)
098     */
099    @Override
100    public void initConfiguration(String name, String id, String className) throws CmsConfigurationException {
101
102        super.initConfiguration(name, id, className);
103        // set static members with values from the configuration
104        addTypeId(m_typeId);
105    }
106
107    /**
108     * Adds another resource type id to the registered sub site map resource type id's.<p>
109     *
110     * @param typeId the resource type id to add
111     */
112    private void addTypeId(int typeId) {
113
114        m_subSitemapResourceTypeIds.add(Integer.valueOf(typeId));
115    }
116
117}