001/*
002 *  Copyright 2024 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.cms.properties.tab;
017
018import java.util.HashMap;
019import java.util.Map;
020
021import org.apache.avalon.framework.configuration.Configurable;
022import org.apache.avalon.framework.configuration.Configuration;
023import org.apache.avalon.framework.configuration.ConfigurationException;
024
025import org.ametys.runtime.i18n.I18nizableText;
026import org.ametys.runtime.plugin.component.PluginAware;
027
028/**
029 * The properties tab tool configuration from a {@link Configuration}.
030 */
031public class DefaultPropertiesTab implements PropertiesTab, Configurable, PluginAware
032{
033    private String _pluginName;
034    private String _id;
035    private int _priority;
036    private Map<String, Object> _configuration;
037    
038    public void setPluginInfo(String pluginName, String featureName, String id)
039    {
040        _pluginName = pluginName;
041        _id = id;
042    }
043    
044    public void configure(Configuration configuration) throws ConfigurationException
045    {
046        _priority = configuration.getChild("priority").getValueAsInteger(Integer.MAX_VALUE);
047        
048        _configuration = new HashMap<>();
049        Configuration tabConf = configuration.getChild("tab");
050        
051        // Set the tab class, by default "Ametys.plugins.cms.properties.PropertiesTab"
052        _configuration.put("tabClass", tabConf.getAttribute("class", "Ametys.plugins.cms.properties.PropertiesTab"));
053        
054        // Set the tab configuration
055        Map<String, Object> tabConfiguration = new HashMap<>();
056        tabConfiguration.put("id", _id);
057        for (Configuration itemConf : tabConf.getChildren())
058        {
059            tabConfiguration.put(itemConf.getName(), I18nizableText.parseI18nizableText(itemConf, "plugin." + _pluginName));
060        }
061        _configuration.put("tabConf", tabConfiguration);
062    }
063    
064    public int getPriority()
065    {
066        return _priority;
067    }
068    
069    public Map<String, Object> getConfiguration()
070    {
071        return _configuration;
072    }
073}