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