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 SecondLevelZoneItem implements ZoneItem 039{ 040 private SecondLevelPage _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 SecondLevelPage}. 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 SecondLevelZoneItem(SecondLevelPage 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 @Override 068 public String getMetadataSetName() throws AmetysRepositoryException 069 { 070 return getViewName(); 071 } 072 073 public String getViewName() throws AmetysRepositoryException 074 { 075 return "main"; 076 } 077 078 @Override 079 public String getServiceId() throws AmetysRepositoryException 080 { 081 return "org.ametys.web.service.SitemapService"; 082 } 083 084 public ModelAwareDataHolder getServiceParameters() throws AmetysRepositoryException 085 { 086 ModifiableRepositoryData repositoryData = new MemoryRepositoryData(SERVICE_PARAMETERS_DATA_NAME); 087 ModifiableModelAwareDataHolder dataHolder = new DefaultModifiableModelAwareDataHolder(repositoryData, _serviceExtensionPoint.getExtension(getServiceId())); 088 _setServiceParameters(dataHolder); 089 return dataHolder; 090 } 091 092 private void _setServiceParameters(ModifiableModelAwareDataHolder dataHolder) 093 { 094 dataHolder.setValue("depth", 1L); 095 dataHolder.setValue("all", "false"); 096 } 097 098 @Override 099 public ZoneType getType() throws AmetysRepositoryException 100 { 101 return ZoneType.SERVICE; 102 } 103 104 @Override 105 public Zone getZone() 106 { 107 return new SecondLevelZone(_page, _zoneDataTypeExtensionPoint, _serviceExtensionPoint, _zoneItemDataTypeExtensionPoint); 108 } 109 110 public ModelLessDataHolder getDataHolder() 111 { 112 RepositoryData repositoryData = new MemoryRepositoryData(Zone.ZONEITEM_DATA_NAME); 113 return new DefaultModelLessDataHolder(_zoneItemDataTypeExtensionPoint, repositoryData); 114 } 115 116 @Override 117 public String getId() throws AmetysRepositoryException 118 { 119 return "odfLevel2ZoneItem://unused?pageId=" + _page.getId(); 120 } 121 122 @Override 123 public String getName() throws AmetysRepositoryException 124 { 125 return "default"; 126 } 127 128 @SuppressWarnings("unchecked") 129 @Override 130 public SecondLevelZone getParent() throws AmetysRepositoryException 131 { 132 return new SecondLevelZone(_page, _zoneDataTypeExtensionPoint, _serviceExtensionPoint, _zoneItemDataTypeExtensionPoint); 133 } 134 135 @Override 136 public String getParentPath() throws AmetysRepositoryException 137 { 138 return _page.getPath() + "/default"; 139 } 140 141 @Override 142 public String getPath() throws AmetysRepositoryException 143 { 144 return _page.getPath() + "/default/default"; 145 } 146}