001/* 002 * Copyright 2016 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.userdirectory.page; 018 019import org.ametys.cms.repository.Content; 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 TransitionalZoneItem implements ZoneItem 039{ 040 private TransitionalPage _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 TransitionalPage}. 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 TransitionalZoneItem(TransitionalPage 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 Content 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 _setServicePrameters(dataHolder); 083 return dataHolder; 084 } 085 086 private void _setServicePrameters(ModifiableModelAwareDataHolder dataHolder) 087 { 088 dataHolder.setValue("depth", 1L); 089 dataHolder.setValue("all", "false"); 090 dataHolder.setValue("includeInvisiblePage", true); 091 } 092 093 @Override 094 public ZoneType getType() throws AmetysRepositoryException 095 { 096 return ZoneType.SERVICE; 097 } 098 099 @Override 100 public Zone getZone() 101 { 102 return new TransitionalZone(_page, _zoneDataTypeExtensionPoint, _serviceExtensionPoint, _zoneItemDataTypeExtensionPoint); 103 } 104 105 public ModelLessDataHolder getDataHolder() 106 { 107 RepositoryData repositoryData = new MemoryRepositoryData(Zone.ZONEITEM_DATA_NAME); 108 return new DefaultModelLessDataHolder(_zoneItemDataTypeExtensionPoint, repositoryData); 109 } 110 111 @Override 112 public String getId() throws AmetysRepositoryException 113 { 114 return "udtransionalzoneitem://unused?pageId=" + _page.getId(); 115 } 116 117 @Override 118 public String getName() throws AmetysRepositoryException 119 { 120 return "default"; 121 } 122 123 @SuppressWarnings("unchecked") 124 @Override 125 public TransitionalZone getParent() throws AmetysRepositoryException 126 { 127 return new TransitionalZone(_page, _zoneDataTypeExtensionPoint, _serviceExtensionPoint, _zoneItemDataTypeExtensionPoint); 128 } 129 130 @Override 131 public String getParentPath() throws AmetysRepositoryException 132 { 133 return _page.getPath() + "/default"; 134 } 135 136 @Override 137 public String getPath() throws AmetysRepositoryException 138 { 139 return _page.getPath() + "/default/default"; 140 } 141 142 public ModelAwareDataHolder getZoneItemParametersHolder() throws AmetysRepositoryException 143 { 144 return null; 145 } 146 147 public ModelAwareDataHolder getContentViewParametersHolder(String contentViewName) throws AmetysRepositoryException 148 { 149 return null; 150 } 151 152 public ModelAwareDataHolder getServiceViewParametersHolder(String serviceViewName) throws AmetysRepositoryException 153 { 154 return null; 155 } 156}