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.ModelLessDataHolder; 026import org.ametys.plugins.repository.data.holder.impl.DefaultModelLessDataHolder; 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.Page; 032import org.ametys.web.repository.page.Zone; 033import org.ametys.web.repository.page.ZoneItem; 034import org.ametys.web.service.ServiceExtensionPoint; 035 036/** 037 * {@link Zone} holding a {@link Program}. 038 */ 039public class SecondLevelZone implements Zone 040{ 041 private SecondLevelPage _page; 042 private AbstractThreadSafeComponentExtensionPoint<RepositoryModelItemType> _zoneDataTypeExtensionPoint; 043 private ServiceExtensionPoint _serviceExtensionPoint; 044 private AbstractThreadSafeComponentExtensionPoint<RepositoryModelItemType> _zoneItemDataTypeExtensionPoint; 045 046 /** 047 * Constructor 048 * @param page the parent {@link SecondLevelPage}. 049 * @param zoneDataTypeExtensionPoint the extension point with available data types for zones 050 * @param serviceExtensionPoint the service extension point 051 * @param zoneItemDataTypeExtensionPoint the extension point with available data types for zone items 052 */ 053 public SecondLevelZone(SecondLevelPage page, AbstractThreadSafeComponentExtensionPoint<RepositoryModelItemType> zoneDataTypeExtensionPoint, ServiceExtensionPoint serviceExtensionPoint, AbstractThreadSafeComponentExtensionPoint<RepositoryModelItemType> zoneItemDataTypeExtensionPoint) 054 { 055 _page = page; 056 _zoneDataTypeExtensionPoint = zoneDataTypeExtensionPoint; 057 _serviceExtensionPoint = serviceExtensionPoint; 058 _zoneItemDataTypeExtensionPoint = zoneItemDataTypeExtensionPoint; 059 } 060 061 @Override 062 public Page getPage() 063 { 064 return _page; 065 } 066 067 @Override 068 public AmetysObjectIterable<? extends ZoneItem> getZoneItems() throws AmetysRepositoryException 069 { 070 ArrayList<ZoneItem> zoneItems = new ArrayList<>(); 071 zoneItems.add(new SecondLevelZoneItem(_page, _zoneDataTypeExtensionPoint, _serviceExtensionPoint, _zoneItemDataTypeExtensionPoint)); 072 return new CollectionIterable<>(zoneItems); 073 } 074 075 public ModelLessDataHolder getDataHolder() 076 { 077 RepositoryData repositoryData = new MemoryRepositoryData(getName()); 078 return new DefaultModelLessDataHolder(_zoneDataTypeExtensionPoint, repositoryData); 079 } 080 081 @Override 082 public String getId() throws AmetysRepositoryException 083 { 084 return "odfLevel2Zone://unused?pageId=" + _page.getId(); 085 } 086 087 @Override 088 public String getName() throws AmetysRepositoryException 089 { 090 return "default"; 091 } 092 093 @SuppressWarnings("unchecked") 094 @Override 095 public Page getParent() throws AmetysRepositoryException 096 { 097 return _page; 098 } 099 100 @Override 101 public String getParentPath() throws AmetysRepositoryException 102 { 103 return _page.getPath(); 104 } 105 106 @Override 107 public String getPath() throws AmetysRepositoryException 108 { 109 return _page.getPath() + "/default"; 110 } 111}