001/*
002 *  Copyright 2023 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.repository.page.virtual;
017
018import java.util.Collection;
019import java.util.LinkedHashMap;
020import java.util.Map;
021
022import org.apache.avalon.framework.configuration.Configuration;
023import org.apache.avalon.framework.configuration.ConfigurationException;
024
025/**
026 * Virtual page's zone configuration
027 */
028public class VirtualZoneConfiguration 
029{
030    private String _id;
031    private Map<String, VirtualZoneItemConfiguration> _zoneItemsConfigurations;
032
033    /**
034     * The constructor of virtual page's zone configuration
035     * @param configuration The configuration
036     * @throws ConfigurationException If an error occurs
037     */
038    public VirtualZoneConfiguration (Configuration configuration) throws ConfigurationException 
039    {
040        _id = configuration.getAttribute("id");
041        
042        _zoneItemsConfigurations = new LinkedHashMap<>();
043        for (Configuration zoneItemConfiguration : configuration.getChildren())
044        {
045            VirtualZoneItemConfiguration zoneItem = new VirtualZoneItemConfiguration(zoneItemConfiguration, this);
046            
047            _zoneItemsConfigurations.put(zoneItem.getName(), zoneItem);
048        }
049    }
050
051    /**
052     * Get the id of the zone
053     * @return The id of the zone
054     */
055    public String getId() 
056    {
057        return _id;
058    }
059    
060    /**
061     * Get the zone items configurations of the zone
062     * @return collection of VirtualPageZoneItemConfiguration
063     */
064    public Collection<VirtualZoneItemConfiguration> getZoneItemsConfigurations() 
065    {
066        return _zoneItemsConfigurations.values();
067    }
068    
069    /**
070     * Get the zone item configuration of the zone, for a given id
071     * @param id the id
072     * @return the VirtualPageZoneItemConfiguration for the given id, null if none was found
073     */
074    public VirtualZoneItemConfiguration getZoneItemConfiguration(String id) 
075    {
076        return _zoneItemsConfigurations.get(id);
077    }
078}