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