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