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