001/*
002 *  Copyright 2010 Anyware Services
003 *
004 *  Licensed under the Apache License, Version 2.0 (the "License");
005 *  you may not use this file except in compliance with the License.
006 *  You may obtain a copy of the License at
007 *
008 *      http://www.apache.org/licenses/LICENSE-2.0
009 *
010 *  Unless required by applicable law or agreed to in writing, software
011 *  distributed under the License is distributed on an "AS IS" BASIS,
012 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 *  See the License for the specific language governing permissions and
014 *  limitations under the License.
015 */
016package org.ametys.web.site;
017
018import java.util.Collections;
019import java.util.HashSet;
020import java.util.Set;
021
022import org.ametys.runtime.i18n.I18nizableText;
023import org.ametys.runtime.parameter.Parameter;
024import org.ametys.runtime.parameter.ParameterHelper.ParameterType;
025import org.ametys.web.repository.site.Site;
026
027/**
028 * Definition of a {@link Site} parameter.
029 */
030public class SiteParameter extends Parameter<ParameterType>
031{
032    
033    /** The display category. */
034    protected I18nizableText _displayCategory;
035    
036    /** The display group. */
037    protected I18nizableText _displayGroup;
038    
039    /** The list of site types to which this parameter belongs, or null for no restriction. */
040    protected Set<String> _siteTypes;
041    
042    /**
043     * Get the display category.
044     * @return the display category.
045     */
046    public I18nizableText getDisplayCategory()
047    {
048        return _displayCategory;
049    }
050    
051    /**
052     * Set the parameter display category.
053     * @param displayCategory the display category to set.
054     */
055    public void setDisplayCategory(I18nizableText displayCategory)
056    {
057        _displayCategory = displayCategory;
058    }
059    
060    /**
061     * Get the display group.
062     * @return the display group.
063     */
064    public I18nizableText getDisplayGroup()
065    {
066        return _displayGroup;
067    }
068    
069    /**
070     * Set the parameter display group.
071     * @param displayGroup the display group to set.
072     */
073    public void setDisplayGroup(I18nizableText displayGroup)
074    {
075        _displayGroup = displayGroup;
076    }
077    
078    /**
079     * Get the site type restriction, null for no restriction.
080     * @return the site types or null for no restriction.
081     */
082    public Set<String> getSiteTypes()
083    {
084        return Collections.unmodifiableSet(_siteTypes);
085    }
086    
087    /**
088     * Set the site type restriction, null for no restriction.
089     * @param siteTypes the site types to set.
090     */
091    public void setSiteTypes(Set<String> siteTypes)
092    {
093        _siteTypes = new HashSet<>(siteTypes);
094    }
095    
096    /**
097     * Test if the parameter is to appear in the specified site type.
098     * @param siteType the site type name (i.e. 'default', 'blog'...)
099     * @return true to appear, false otherwise.
100     */
101    public boolean isInSiteType(String siteType)
102    {
103        return _siteTypes == null || _siteTypes.contains(siteType);
104    }
105    
106    @Override
107    public String toString()
108    {
109        return "'" + getId() + "' (type:    " + getType().name() + ", label:    " + getLabel().toString() + ", " + (getDefaultValue() != null ? ("default value: " + getDefaultValue()) : "no default value")  + ", " + (getEnumerator() != null ? ("enumerator: " + getEnumerator()) : "no enumerator") + ")";
110    }
111}