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 */
016
017package org.ametys.plugins.odfweb.repository;
018
019import java.util.ArrayList;
020
021import org.ametys.odf.program.Program;
022import org.ametys.plugins.repository.AmetysObjectIterable;
023import org.ametys.plugins.repository.AmetysRepositoryException;
024import org.ametys.plugins.repository.CollectionIterable;
025import org.ametys.plugins.repository.data.holder.ModelAwareDataHolder;
026import org.ametys.plugins.repository.data.holder.ModelLessDataHolder;
027import org.ametys.plugins.repository.data.holder.impl.DefaultModelLessDataHolder;
028import org.ametys.plugins.repository.data.repositorydata.RepositoryData;
029import org.ametys.plugins.repository.data.repositorydata.impl.MemoryRepositoryData;
030import org.ametys.web.data.type.ModelItemTypeExtensionPoint;
031import org.ametys.web.repository.page.Page;
032import org.ametys.web.repository.page.SitemapElement;
033import org.ametys.web.repository.page.Zone;
034import org.ametys.web.repository.page.ZoneItem;
035
036/**
037 * {@link Zone} holding a {@link Program}.
038 */
039public class ProgramZone implements Zone
040{
041    private ProgramPage _page;
042    private ModelItemTypeExtensionPoint _zoneDataTypeExtensionPoint;
043    private ModelItemTypeExtensionPoint _zoneItemDataTypeExtensionPoint;
044    
045    /**
046     * Constructor
047     * @param page the parent {@link ProgramPage}.
048     * @param zoneDataTypeExtensionPoint the extension point with available data types for zones
049     * @param zoneItemDataTypeExtensionPoint the extension point with available data types for zone items
050     */
051    public ProgramZone(ProgramPage page, ModelItemTypeExtensionPoint zoneDataTypeExtensionPoint, ModelItemTypeExtensionPoint zoneItemDataTypeExtensionPoint)
052    {
053        _page = page;
054        _zoneDataTypeExtensionPoint = zoneDataTypeExtensionPoint;
055        _zoneItemDataTypeExtensionPoint = zoneItemDataTypeExtensionPoint;
056    }
057    
058    @Override
059    public SitemapElement getSitemapElement()
060    {
061        return _page;
062    }
063
064    @Override
065    public AmetysObjectIterable<? extends ZoneItem> getZoneItems() throws AmetysRepositoryException
066    {
067        ArrayList<ZoneItem> zoneItems = new ArrayList<>();
068        zoneItems.add(new ProgramZoneItem(_page, _zoneDataTypeExtensionPoint, _zoneItemDataTypeExtensionPoint));
069        return new CollectionIterable<>(zoneItems);
070    }
071
072    public ModelLessDataHolder getDataHolder()
073    {
074        RepositoryData repositoryData = new MemoryRepositoryData(getName());
075        return new DefaultModelLessDataHolder(_zoneDataTypeExtensionPoint, repositoryData);
076    }
077
078    @Override
079    public String getId() throws AmetysRepositoryException
080    {
081        return "programZone://unused?pageId=" + _page.getId();
082    }
083
084    @Override
085    public String getName() throws AmetysRepositoryException
086    {
087        return "default";
088    }
089
090    @SuppressWarnings("unchecked")
091    @Override
092    public Page getParent() throws AmetysRepositoryException
093    {
094        return _page;
095    }
096
097    @Override
098    public String getParentPath() throws AmetysRepositoryException
099    {
100        return _page.getPath();
101    }
102
103    @Override
104    public String getPath() throws AmetysRepositoryException
105    {
106        return _page.getPath() + "/default";
107    }
108    
109    public ModelAwareDataHolder getZoneParametersHolder() throws AmetysRepositoryException
110    {
111        return null;
112    }
113}