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.AbstractProgram; 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.impl.DefaultModelLessDataHolder; 025import org.ametys.plugins.repository.data.repositorydata.RepositoryData; 026import org.ametys.plugins.repository.data.repositorydata.impl.MemoryRepositoryData; 027import org.ametys.plugins.repository.data.type.RepositoryModelItemType; 028import org.ametys.runtime.plugin.component.AbstractThreadSafeComponentExtensionPoint; 029import org.ametys.web.repository.page.Zone; 030import org.ametys.web.repository.page.ZoneItem; 031 032/** 033 * {@link ZoneItem} holding a {@link Program}. 034 */ 035public class ProgramZoneItem implements ZoneItem 036{ 037 private ProgramPage _page; 038 private AbstractThreadSafeComponentExtensionPoint<RepositoryModelItemType> _zoneDataTypeExtensionPoint; 039 private AbstractThreadSafeComponentExtensionPoint<RepositoryModelItemType> _zoneItemDataTypeExtensionPoint; 040 041 /** 042 * Constructor. 043 * @param page the parent {@link ProgramPage}. 044 * @param zoneDataTypeExtensionPoint the extension point with available data types for zones 045 * @param zoneItemDataTypeExtensionPoint the extension point with available data types for zone items 046 */ 047 public ProgramZoneItem(ProgramPage page, AbstractThreadSafeComponentExtensionPoint<RepositoryModelItemType> zoneDataTypeExtensionPoint, AbstractThreadSafeComponentExtensionPoint<RepositoryModelItemType> zoneItemDataTypeExtensionPoint) 048 { 049 _page = page; 050 _zoneDataTypeExtensionPoint = zoneDataTypeExtensionPoint; 051 _zoneItemDataTypeExtensionPoint = zoneItemDataTypeExtensionPoint; 052 } 053 054 @SuppressWarnings("unchecked") 055 @Override 056 public AbstractProgram getContent() throws AmetysRepositoryException 057 { 058 AbstractProgram program = _page.getProgram(); 059 program.setContextPath(_page.getPathInSitemap()); 060 return program; 061 } 062 063 public String getViewName() throws AmetysRepositoryException 064 { 065 return "main"; 066 } 067 068 @Override 069 public String getServiceId() throws AmetysRepositoryException 070 { 071 throw new UnsupportedOperationException("getServiceId not supported on virtual odf pages"); 072 } 073 074 public ModelAwareDataHolder getServiceParameters() throws AmetysRepositoryException 075 { 076 throw new UnsupportedOperationException("getServiceParameters not supported on virtual odf pages"); 077 } 078 079 @Override 080 public ZoneType getType() throws AmetysRepositoryException 081 { 082 return ZoneType.CONTENT; 083 } 084 085 @Override 086 public Zone getZone() 087 { 088 return new ProgramZone(_page, _zoneDataTypeExtensionPoint, _zoneItemDataTypeExtensionPoint); 089 } 090 091 public ModelLessDataHolder getDataHolder() 092 { 093 RepositoryData repositoryData = new MemoryRepositoryData(Zone.ZONEITEM_DATA_NAME); 094 return new DefaultModelLessDataHolder(_zoneItemDataTypeExtensionPoint, repositoryData); 095 } 096 097 @Override 098 public String getId() throws AmetysRepositoryException 099 { 100 return "programZoneItem://unused?pageId=" + _page.getId(); 101 } 102 103 @Override 104 public String getName() throws AmetysRepositoryException 105 { 106 return "default"; 107 } 108 109 @SuppressWarnings("unchecked") 110 @Override 111 public ProgramZone getParent() throws AmetysRepositoryException 112 { 113 return new ProgramZone(_page, _zoneDataTypeExtensionPoint, _zoneItemDataTypeExtensionPoint); 114 } 115 116 @Override 117 public String getParentPath() throws AmetysRepositoryException 118 { 119 return _page.getPath() + "/default"; 120 } 121 122 @Override 123 public String getPath() throws AmetysRepositoryException 124 { 125 return _page.getPath() + "/default/default"; 126 } 127 128 public ModelAwareDataHolder getZoneItemParametersHolder() throws AmetysRepositoryException 129 { 130 return null; 131 } 132 133 public ModelAwareDataHolder getContentViewParametersHolder(String contentViewName) throws AmetysRepositoryException 134 { 135 return null; 136 } 137 138 public ModelAwareDataHolder getServiceViewParametersHolder(String serviceViewName) throws AmetysRepositoryException 139 { 140 return null; 141 } 142}