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 org.ametys.odf.program.AbstractProgram;
020import org.ametys.odf.program.Program;
021import org.ametys.plugins.repository.AmetysRepositoryException;
022import org.ametys.plugins.repository.data.holder.ModelAwareDataHolder;
023import org.ametys.plugins.repository.data.holder.ModelLessDataHolder;
024import org.ametys.plugins.repository.data.holder.impl.DefaultModelLessDataHolder;
025import org.ametys.plugins.repository.data.repositorydata.RepositoryData;
026import org.ametys.plugins.repository.data.repositorydata.impl.MemoryRepositoryData;
027import org.ametys.plugins.repository.data.type.RepositoryModelItemType;
028import org.ametys.runtime.plugin.component.AbstractThreadSafeComponentExtensionPoint;
029import org.ametys.web.repository.page.Zone;
030import org.ametys.web.repository.page.ZoneItem;
031
032/**
033 * {@link ZoneItem} holding a {@link Program}.
034 */
035public class ProgramZoneItem implements ZoneItem
036{
037    private ProgramPage _page;
038    private AbstractThreadSafeComponentExtensionPoint<RepositoryModelItemType> _zoneDataTypeExtensionPoint;
039    private AbstractThreadSafeComponentExtensionPoint<RepositoryModelItemType> _zoneItemDataTypeExtensionPoint;
040    
041    /**
042     * Constructor.
043     * @param page the parent {@link ProgramPage}.
044     * @param zoneDataTypeExtensionPoint the extension point with available data types for zones
045     * @param zoneItemDataTypeExtensionPoint the extension point with available data types for zone items
046     */
047    public ProgramZoneItem(ProgramPage page, AbstractThreadSafeComponentExtensionPoint<RepositoryModelItemType> zoneDataTypeExtensionPoint, AbstractThreadSafeComponentExtensionPoint<RepositoryModelItemType> zoneItemDataTypeExtensionPoint)
048    {
049        _page = page;
050        _zoneDataTypeExtensionPoint = zoneDataTypeExtensionPoint;
051        _zoneItemDataTypeExtensionPoint = zoneItemDataTypeExtensionPoint;
052    }
053    
054    @SuppressWarnings("unchecked")
055    @Override
056    public AbstractProgram getContent() throws AmetysRepositoryException
057    {
058        AbstractProgram program = _page.getProgram();
059        program.setContextPath(_page.getPathInSitemap());
060        return program;
061    }
062
063    @Override
064    public String getMetadataSetName() throws AmetysRepositoryException
065    {
066        return getViewName();
067    }
068    
069    public String getViewName() throws AmetysRepositoryException
070    {
071        return "main";
072    }
073    
074    @Override
075    public String getServiceId() throws AmetysRepositoryException
076    {
077        throw new UnsupportedOperationException("getServiceId not supported on virtual odf pages");
078    }
079
080    public ModelAwareDataHolder getServiceParameters() throws AmetysRepositoryException
081    {
082        throw new UnsupportedOperationException("getServiceParameters not supported on virtual odf pages");
083    }
084
085    @Override
086    public ZoneType getType() throws AmetysRepositoryException
087    {
088        return ZoneType.CONTENT;
089    }
090
091    @Override
092    public Zone getZone()
093    {
094        return new ProgramZone(_page, _zoneDataTypeExtensionPoint, _zoneItemDataTypeExtensionPoint);
095    }
096
097    public ModelLessDataHolder getDataHolder()
098    {
099        RepositoryData repositoryData = new MemoryRepositoryData(Zone.ZONEITEM_DATA_NAME);
100        return new DefaultModelLessDataHolder(_zoneItemDataTypeExtensionPoint, repositoryData);
101    }
102
103    @Override
104    public String getId() throws AmetysRepositoryException
105    {
106        return "programZoneItem://unused?pageId=" + _page.getId();
107    }
108
109    @Override
110    public String getName() throws AmetysRepositoryException
111    {
112        return "default";
113    }
114
115    @SuppressWarnings("unchecked")
116    @Override
117    public ProgramZone getParent() throws AmetysRepositoryException
118    {
119        return new ProgramZone(_page, _zoneDataTypeExtensionPoint, _zoneItemDataTypeExtensionPoint);
120    }
121
122    @Override
123    public String getParentPath() throws AmetysRepositoryException
124    {
125        return _page.getPath() + "/default";
126    }
127
128    @Override
129    public String getPath() throws AmetysRepositoryException
130    {
131        return _page.getPath() + "/default/default";
132    }
133}