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