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.Program;
020import org.ametys.plugins.repository.AmetysRepositoryException;
021import org.ametys.plugins.repository.data.holder.ModelAwareDataHolder;
022import org.ametys.plugins.repository.data.holder.ModelLessDataHolder;
023import org.ametys.plugins.repository.data.holder.ModifiableModelAwareDataHolder;
024import org.ametys.plugins.repository.data.holder.impl.DefaultModelLessDataHolder;
025import org.ametys.plugins.repository.data.holder.impl.DefaultModifiableModelAwareDataHolder;
026import org.ametys.plugins.repository.data.repositorydata.ModifiableRepositoryData;
027import org.ametys.plugins.repository.data.repositorydata.RepositoryData;
028import org.ametys.plugins.repository.data.repositorydata.impl.MemoryRepositoryData;
029import org.ametys.plugins.repository.data.type.RepositoryModelItemType;
030import org.ametys.runtime.plugin.component.AbstractThreadSafeComponentExtensionPoint;
031import org.ametys.web.repository.page.Zone;
032import org.ametys.web.repository.page.ZoneItem;
033import org.ametys.web.service.ServiceExtensionPoint;
034
035/**
036 * {@link ZoneItem} holding a Sitemap service
037 */
038public class FirstLevelZoneItem implements ZoneItem
039{
040    private FirstLevelPage _page;
041    private AbstractThreadSafeComponentExtensionPoint<RepositoryModelItemType> _zoneDataTypeExtensionPoint;
042    private ServiceExtensionPoint _serviceExtensionPoint;
043    private AbstractThreadSafeComponentExtensionPoint<RepositoryModelItemType> _zoneItemDataTypeExtensionPoint;
044    
045    /**
046     * Constructor.
047     * @param page the parent {@link FirstLevelPage}.
048     * @param zoneDataTypeExtensionPoint the extension point with available data types for zones
049     * @param serviceExtensionPoint the service extension point
050     * @param zoneItemDataTypeExtensionPoint the extension point with available data types for zone items
051     */
052    public FirstLevelZoneItem(FirstLevelPage page, AbstractThreadSafeComponentExtensionPoint<RepositoryModelItemType> zoneDataTypeExtensionPoint, ServiceExtensionPoint serviceExtensionPoint, AbstractThreadSafeComponentExtensionPoint<RepositoryModelItemType> zoneItemDataTypeExtensionPoint)
053    {
054        _page = page;
055        _zoneDataTypeExtensionPoint = zoneDataTypeExtensionPoint;
056        _serviceExtensionPoint = serviceExtensionPoint;
057        _zoneItemDataTypeExtensionPoint = zoneItemDataTypeExtensionPoint;
058    }
059    
060    @SuppressWarnings("unchecked")
061    @Override
062    public Program getContent() throws AmetysRepositoryException
063    {
064        throw new UnsupportedOperationException("getContent not supported on virtual degree pages");
065    }
066
067    public String getViewName() throws AmetysRepositoryException
068    {
069        return "main";
070    }
071    
072    @Override
073    public String getServiceId() throws AmetysRepositoryException
074    {
075        return "org.ametys.web.service.SitemapService";
076    }
077
078    public ModelAwareDataHolder getServiceParameters() throws AmetysRepositoryException
079    {
080        ModifiableRepositoryData repositoryData = new MemoryRepositoryData(SERVICE_PARAMETERS_DATA_NAME);
081        ModifiableModelAwareDataHolder dataHolder = new DefaultModifiableModelAwareDataHolder(repositoryData, _serviceExtensionPoint.getExtension(getServiceId()));
082        _setServiceParameters(dataHolder);
083        return dataHolder;
084    }
085    
086    private void _setServiceParameters(ModifiableModelAwareDataHolder dataHolder)
087    {
088        dataHolder.setValue("depth", 2L);
089        dataHolder.setValue("all", "false");
090    }
091
092    @Override
093    public ZoneType getType() throws AmetysRepositoryException
094    {
095        return ZoneType.SERVICE;
096    }
097
098    @Override
099    public Zone getZone()
100    {
101        return new FirstLevelZone(_page, _zoneDataTypeExtensionPoint, _serviceExtensionPoint, _zoneItemDataTypeExtensionPoint);
102    }
103
104    public ModelLessDataHolder getDataHolder()
105    {
106        RepositoryData repositoryData = new MemoryRepositoryData(Zone.ZONEITEM_DATA_NAME);
107        return new DefaultModelLessDataHolder(_zoneItemDataTypeExtensionPoint, repositoryData);
108    }
109
110    @Override
111    public String getId() throws AmetysRepositoryException
112    {
113        return "odfLevel1ZoneItem://unused?pageId=" + _page.getId();
114    }
115
116    @Override
117    public String getName() throws AmetysRepositoryException
118    {
119        return "default";
120    }
121
122    @SuppressWarnings("unchecked")
123    @Override
124    public FirstLevelZone getParent() throws AmetysRepositoryException
125    {
126        return new FirstLevelZone(_page, _zoneDataTypeExtensionPoint, _serviceExtensionPoint, _zoneItemDataTypeExtensionPoint);
127    }
128
129    @Override
130    public String getParentPath() throws AmetysRepositoryException
131    {
132        return _page.getPath() + "/default";
133    }
134
135    @Override
136    public String getPath() throws AmetysRepositoryException
137    {
138        return _page.getPath() + "/default/default";
139    }
140    
141    public ModelAwareDataHolder getZoneItemParametersHolder() throws AmetysRepositoryException
142    {
143        return null;
144    }
145
146    public ModelAwareDataHolder getContentViewParametersHolder(String contentViewName) throws AmetysRepositoryException
147    {
148        return null;
149    }
150
151    public ModelAwareDataHolder getServiceViewParametersHolder(String serviceViewName) throws AmetysRepositoryException
152    {
153        return null;
154    }
155}