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 org.ametys.plugins.repository.AmetysObject; 019import org.ametys.plugins.repository.AmetysObjectIterable; 020import org.ametys.plugins.repository.AmetysObjectIterator; 021import org.ametys.plugins.repository.AmetysRepositoryException; 022import org.ametys.plugins.repository.data.holder.ModelAwareDataHolder; 023import org.ametys.plugins.repository.data.holder.ModelLessDataHolder; 024import org.ametys.web.repository.page.SitemapElement; 025import org.ametys.web.repository.page.Zone; 026import org.ametys.web.repository.page.ZoneItem; 027 028/** 029 * Wrapper to present a modifiable zone into a unmodifiable one. 030 */ 031public class StaticZone implements Zone 032{ 033 034 /** The wrapped zone. */ 035 protected Zone _zone; 036 037 /** 038 * Construct a static zone, wrapping a given zone. 039 * @param zone the zone to wrap. 040 */ 041 public StaticZone(Zone zone) 042 { 043 _zone = zone; 044 } 045 046 public ModelLessDataHolder getDataHolder() 047 { 048 return _zone.getDataHolder(); 049 } 050 051 @Override 052 public String getName() throws AmetysRepositoryException 053 { 054 return _zone.getName(); 055 } 056 057 @Override 058 public String getPath() throws AmetysRepositoryException 059 { 060 return _zone.getPath(); 061 } 062 063 @Override 064 public String getId() throws AmetysRepositoryException 065 { 066 return _zone.getId(); 067 } 068 069 @Override 070 public <A extends AmetysObject> A getParent() throws AmetysRepositoryException 071 { 072 return _zone.getParent(); 073 } 074 075 @Override 076 public String getParentPath() throws AmetysRepositoryException 077 { 078 return _zone.getParentPath(); 079 } 080 081 @Override 082 public AmetysObjectIterable< ? extends ZoneItem> getZoneItems() throws AmetysRepositoryException 083 { 084 return new StaticZoneItemIterable(_zone.getZoneItems()); 085 } 086 087 @Override 088 public SitemapElement getSitemapElement() 089 { 090 return _zone.getSitemapElement(); 091 } 092 093 public ModelAwareDataHolder getZoneParametersHolder() throws AmetysRepositoryException 094 { 095 return _zone.getZoneParametersHolder(); 096 } 097 098 /** 099 * Static zone item iterable. 100 */ 101 protected class StaticZoneItemIterable implements AmetysObjectIterable<StaticZoneItem> 102 { 103 104 /** The wrapped iterable. */ 105 protected AmetysObjectIterable<? extends ZoneItem> _iterable; 106 107 /** 108 * Construct a StaticZoneItemIterable, wrapping an iterable. 109 * @param iterable zone item iterable. 110 */ 111 public StaticZoneItemIterable(AmetysObjectIterable<? extends ZoneItem> iterable) 112 { 113 _iterable = iterable; 114 } 115 116 @Override 117 public AmetysObjectIterator<StaticZoneItem> iterator() 118 { 119 return new StaticZoneItemIterator(_iterable.iterator()); 120 } 121 122 @Override 123 public long getSize() 124 { 125 return _iterable.getSize(); 126 } 127 128 @Override 129 public void close() 130 { 131 _iterable.close(); 132 } 133 134 } 135 136 class StaticZoneItemIterator implements AmetysObjectIterator<StaticZoneItem> 137 { 138 AmetysObjectIterator<? extends ZoneItem> _it; 139 140 public StaticZoneItemIterator(AmetysObjectIterator<? extends ZoneItem> it) 141 { 142 _it = it; 143 } 144 145 public boolean hasNext() 146 { 147 return _it.hasNext(); 148 } 149 150 public StaticZoneItem next() 151 { 152 return new StaticZoneItem(_it.next()); 153 } 154 155 public void skip(long skipNum) 156 { 157 _it.skip(skipNum); 158 } 159 160 public long getPosition() 161 { 162 return _it.getPosition(); 163 } 164 165 public long getSize() 166 { 167 return _it.getSize(); 168 } 169 170 public void remove() 171 { 172 _it.remove(); 173 } 174 } 175}