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 */ 016package org.ametys.plugins.blog.repository; 017 018import java.util.ArrayList; 019 020import org.ametys.plugins.repository.AmetysObjectIterable; 021import org.ametys.plugins.repository.AmetysRepositoryException; 022import org.ametys.plugins.repository.CollectionIterable; 023import org.ametys.web.repository.page.Page; 024import org.ametys.web.repository.page.UnknownZoneException; 025import org.ametys.web.repository.page.Zone; 026 027/** 028 * Declares a root page and 029 */ 030public abstract class AbstractBlogPage implements Page 031{ 032 /** Default template for month page */ 033 public static final String BLOG_MONTH_TEMPLATE = "blog-month"; 034 /** Default template for year page */ 035 public static final String BLOG_YEAR_TEMPLATE = "blog-year"; 036 /** Default template for tag page */ 037 public static final String BLOG_TAG_TEMPLATE = "blog-tag"; 038 /** Default template for post page */ 039 public static final String BLOG_POST_TEMPLATE = "blog-post"; 040 041 /** The root page. */ 042// private Page _root; 043 044 @Override 045 public PageType getType() throws AmetysRepositoryException 046 { 047 return getReferencePage().getType(); 048 } 049 050 @Override 051 public String getTemplate() throws AmetysRepositoryException 052 { 053 return getReferencePage().getTemplate(); 054 } 055 056 @Override 057 public Zone getZone(String name) throws UnknownZoneException, AmetysRepositoryException 058 { 059 if ("default".equals(name)) 060 { 061 return getDefaultZone(); 062 } 063 return new StaticZone(getReferencePage().getZone(name)); 064 } 065 066 @Override 067 public AmetysObjectIterable< ? extends Zone> getZones() throws AmetysRepositoryException 068 { 069 ArrayList<Zone> zones = new ArrayList<>(); 070 071 // Add the default zone. 072 zones.add(getDefaultZone()); 073 074 // Add all the other zones. 075 for (Zone zone : getReferencePage().getZones()) 076 { 077 if (!"default".equals(zone.getName())) 078 { 079 zones.add(new StaticZone(zone)); 080 } 081 } 082 083 return new CollectionIterable<>(zones); 084 } 085 086 @Override 087 public boolean hasZone(String name) throws AmetysRepositoryException 088 { 089 return "default".equals(name) || getReferencePage().hasZone(name); 090 } 091 092 /** 093 * Get the reference page. 094 * @return the reference page. 095 */ 096 public Page getReferencePage() 097 { 098// return getRootPage(); 099 return getSitemap().getChild("index"); 100 } 101 102 /** 103 * Get the root page. 104 * @return the root page. 105 */ 106// protected abstract Page getRootPage(); 107 108 /** 109 * Get the "default" zone. 110 * @return the "default" zone. 111 */ 112 protected abstract Zone getDefaultZone(); 113}