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.model.CategorizedElementDefinitionProxy; 023import org.ametys.web.repository.site.Site; 024 025/** 026 * Definition of a {@link Site} parameter. 027 * @param <T> Type of the element value 028 */ 029public class SiteParameter<T> extends CategorizedElementDefinitionProxy<T> 030{ 031 /** The list of site types to which this parameter belongs, or null for no restriction. */ 032 protected Set<String> _siteTypes; 033 034 /** 035 * Get the site type restriction, null for no restriction. 036 * @return the site types or null for no restriction. 037 */ 038 public Set<String> getSiteTypes() 039 { 040 return Collections.unmodifiableSet(_siteTypes); 041 } 042 043 /** 044 * Set the site type restriction, null for no restriction. 045 * @param siteTypes the site types to set. 046 */ 047 public void setSiteTypes(Set<String> siteTypes) 048 { 049 _siteTypes = new HashSet<>(siteTypes); 050 } 051 052 /** 053 * Test if the parameter is to appear in the specified site type. 054 * @param siteType the site type name (i.e. 'default', 'blog'...) 055 * @return true to appear, false otherwise. 056 */ 057 public boolean isInSiteType(String siteType) 058 { 059 return _siteTypes == null || _siteTypes.contains(siteType); 060 } 061 062 @Override 063 public String toString() 064 { 065 return "'" + getModel().getId() + "' (type: " + getType().getId() + ", label: " + getLabel().toString() + ", " + (getDefaultValue() != null ? ("default value: " + getDefaultValue()) : "no default value") + ", " + (getEnumerator() != null ? ("enumerator: " + getEnumerator()) : "no enumerator") + ")"; 066 } 067}