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