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.configuration.preferences;
029
030import org.opencms.configuration.CmsDefaultUserSettings;
031import org.opencms.file.CmsObject;
032import org.opencms.util.CmsStringUtil;
033import org.opencms.xml.content.CmsXmlContentProperty;
034
035/**
036 * Start gallery preference.<p>
037 */
038public class CmsStartGallleryPreference extends A_CmsPreference {
039
040    /** The default value. */
041    private String m_value;
042
043    /** Prefix used for editor preference settings. */
044    public static final String GALLERY_PREFIX = "gallery.";
045
046    /** The gallery type for which this preference controls the start gallery. */
047    private String m_galleryType;
048
049    /**
050     * Creates a new instance.<o>
051     * @param galleryType the gallery type
052     * @param value the value
053     */
054    public CmsStartGallleryPreference(String galleryType, String value) {
055
056        m_galleryType = galleryType;
057        m_value = value;
058    }
059
060    /**
061     * @see org.opencms.configuration.preferences.I_CmsPreference#getDefaultValue()
062     */
063    public String getDefaultValue() {
064
065        return m_value;
066    }
067
068    /**
069     * @see org.opencms.configuration.preferences.I_CmsPreference#getName()
070     */
071    public String getName() {
072
073        return GALLERY_PREFIX + m_galleryType;
074    }
075
076    /**
077     * @see org.opencms.configuration.preferences.I_CmsPreference#getPropertyDefinition(org.opencms.file.CmsObject)
078     */
079    @Override
080    public CmsXmlContentProperty getPropertyDefinition() {
081
082        CmsXmlContentProperty prop = new CmsXmlContentProperty(
083            getName(), //name
084            "string", //type
085            null, //widget
086            null, //widgetconfig
087            null, //regex
088            null, //ruletype
089            null, //default
090            null, //nicename
091            null, //description
092            null, //error
093            null//preferfolder
094        );
095        return prop;
096    }
097
098    /**
099     * @see org.opencms.configuration.preferences.A_CmsPreference#getPropertyDefinition(org.opencms.file.CmsObject)
100     */
101    @Override
102    public CmsXmlContentProperty getPropertyDefinition(CmsObject cms) {
103
104        return getPropertyDefinition();
105    }
106
107    /**
108     * @see org.opencms.configuration.preferences.I_CmsPreference#getTab()
109     */
110    public String getTab() {
111
112        return "hidden";
113    }
114
115    /**
116     * @see org.opencms.configuration.preferences.I_CmsPreference#getValue(org.opencms.configuration.CmsDefaultUserSettings)
117     */
118    public String getValue(CmsDefaultUserSettings userSettings) {
119
120        return userSettings.getStartGallery(m_galleryType);
121    }
122
123    /**
124     * @see org.opencms.configuration.preferences.I_CmsPreference#setValue(org.opencms.configuration.CmsDefaultUserSettings, java.lang.String)
125     */
126    public void setValue(CmsDefaultUserSettings settings, String value) {
127
128        if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(value) && value.contains("/") && !(value.endsWith("/"))) {
129            value += "/";
130        }
131        settings.setStartGallery(m_galleryType, value);
132    }
133
134}