001/* 002 * Copyright 2011 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.blog.repository; 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.impl.DefaultModelLessDataHolder; 024import org.ametys.plugins.repository.data.repositorydata.RepositoryData; 025import org.ametys.plugins.repository.data.repositorydata.impl.MemoryRepositoryData; 026import org.ametys.web.data.type.ModelItemTypeExtensionPoint; 027import org.ametys.web.repository.page.Zone; 028import org.ametys.web.repository.page.ZoneItem; 029 030/** 031 * {@link ZoneItem} holding a post {@link Content}. 032 */ 033public class PostZoneItem implements ZoneItem 034{ 035 private VirtualPostPage _page; 036 private ModelItemTypeExtensionPoint _zoneDataTypeExtensionPoint; 037 private ModelItemTypeExtensionPoint _zoneItemDataTypeExtensionPoint; 038 039 /** 040 * Constructor. 041 * @param page the parent {@link VirtualPostPage}. 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 PostZoneItem(VirtualPostPage page, ModelItemTypeExtensionPoint zoneDataTypeExtensionPoint, ModelItemTypeExtensionPoint zoneItemDataTypeExtensionPoint) 046 { 047 _page = page; 048 _zoneDataTypeExtensionPoint = zoneDataTypeExtensionPoint; 049 _zoneItemDataTypeExtensionPoint = zoneItemDataTypeExtensionPoint; 050 } 051 052 @SuppressWarnings("unchecked") 053 @Override 054 public Content getContent() throws AmetysRepositoryException 055 { 056 Content program = _page.getPost(); 057 return program; 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 post pages"); 069 } 070 071 public ModelAwareDataHolder getServiceParameters() throws AmetysRepositoryException 072 { 073 throw new UnsupportedOperationException("getServiceParameters not supported on virtual post 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 PostZone(_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 "postZoneItem://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 PostZone getParent() throws AmetysRepositoryException 109 { 110 return new PostZone(_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}