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