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 java.util.ArrayList; 020 021import org.ametys.cms.repository.Content; 022import org.ametys.plugins.repository.AmetysObjectIterable; 023import org.ametys.plugins.repository.AmetysRepositoryException; 024import org.ametys.plugins.repository.CollectionIterable; 025import org.ametys.plugins.repository.data.holder.ModelAwareDataHolder; 026import org.ametys.plugins.repository.data.holder.ModelLessDataHolder; 027import org.ametys.plugins.repository.data.holder.impl.DefaultModelLessDataHolder; 028import org.ametys.plugins.repository.data.repositorydata.RepositoryData; 029import org.ametys.plugins.repository.data.repositorydata.impl.MemoryRepositoryData; 030import org.ametys.plugins.repository.data.type.RepositoryModelItemType; 031import org.ametys.runtime.plugin.component.AbstractThreadSafeComponentExtensionPoint; 032import org.ametys.web.repository.page.Page; 033import org.ametys.web.repository.page.Zone; 034import org.ametys.web.repository.page.ZoneItem; 035 036/** 037 * {@link Zone} holding a post {@link Content}. 038 */ 039public class PostZone implements Zone 040{ 041 private VirtualPostPage _page; 042 private AbstractThreadSafeComponentExtensionPoint<RepositoryModelItemType> _zoneDataTypeExtensionPoint; 043 private AbstractThreadSafeComponentExtensionPoint<RepositoryModelItemType> _zoneItemDataTypeExtensionPoint; 044 045 /** 046 * Constructor 047 * @param page the parent {@link VirtualPostPage}. 048 * @param zoneDataTypeExtensionPoint the extension point with available data types for zones 049 * @param zoneItemDataTypeExtensionPoint the extension point with available data types for zone items 050 */ 051 public PostZone(VirtualPostPage page, AbstractThreadSafeComponentExtensionPoint<RepositoryModelItemType> zoneDataTypeExtensionPoint, AbstractThreadSafeComponentExtensionPoint<RepositoryModelItemType> zoneItemDataTypeExtensionPoint) 052 { 053 _page = page; 054 _zoneDataTypeExtensionPoint = zoneDataTypeExtensionPoint; 055 _zoneItemDataTypeExtensionPoint = zoneItemDataTypeExtensionPoint; 056 } 057 058 @Override 059 public Page getPage() 060 { 061 return _page; 062 } 063 064 @Override 065 public AmetysObjectIterable<? extends ZoneItem> getZoneItems() throws AmetysRepositoryException 066 { 067 ArrayList<ZoneItem> zoneItems = new ArrayList<>(); 068 zoneItems.add(new PostZoneItem(_page, _zoneDataTypeExtensionPoint, _zoneItemDataTypeExtensionPoint)); 069 return new CollectionIterable<>(zoneItems); 070 } 071 072 public ModelLessDataHolder getDataHolder() 073 { 074 RepositoryData repositoryData = new MemoryRepositoryData(getName()); 075 return new DefaultModelLessDataHolder(_zoneDataTypeExtensionPoint, repositoryData); 076 } 077 078 @Override 079 public String getId() throws AmetysRepositoryException 080 { 081 return "postZone://unused?pageId=" + _page.getId(); 082 } 083 084 @Override 085 public String getName() throws AmetysRepositoryException 086 { 087 return "default"; 088 } 089 090 @SuppressWarnings("unchecked") 091 @Override 092 public Page getParent() throws AmetysRepositoryException 093 { 094 return _page; 095 } 096 097 @Override 098 public String getParentPath() throws AmetysRepositoryException 099 { 100 return _page.getPath(); 101 } 102 103 @Override 104 public String getPath() throws AmetysRepositoryException 105 { 106 return _page.getPath() + "/default"; 107 } 108 109 public ModelAwareDataHolder getZoneParametersHolder() throws AmetysRepositoryException 110 { 111 return null; 112 } 113}