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