001/* 002 * This library is part of OpenCms - 003 * the Open Source Content Management System 004 * 005 * Copyright (c) Alkacon Software GmbH & Co. KG (http://www.alkacon.com) 006 * 007 * This library is free software; you can redistribute it and/or 008 * modify it under the terms of the GNU Lesser General Public 009 * License as published by the Free Software Foundation; either 010 * version 2.1 of the License, or (at your option) any later version. 011 * 012 * This library is distributed in the hope that it will be useful, 013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 015 * Lesser General Public License for more details. 016 * 017 * For further information about Alkacon Software, please see the 018 * company website: http://www.alkacon.com 019 * 020 * For further information about OpenCms, please see the 021 * project website: http://www.opencms.org 022 * 023 * You should have received a copy of the GNU Lesser General Public 024 * License along with this library; if not, write to the Free Software 025 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 026 */ 027 028package org.opencms.xml.containerpage; 029 030import org.opencms.util.CmsCollectionsGenericWrapper; 031import org.opencms.util.CmsStringUtil; 032import org.opencms.util.CmsUUID; 033 034import java.util.ArrayList; 035import java.util.Collections; 036import java.util.List; 037import java.util.Map; 038 039import org.apache.commons.collections.Transformer; 040 041/** 042 * One container of a container page.<p> 043 * 044 * @since 8.0 045 */ 046public class CmsContainerBean { 047 048 /** A lazy initialized map that describes if a certain element if part of this container. */ 049 private transient Map<CmsUUID, Boolean> m_containsElement; 050 051 /** Flag indicating this container is used on detail pages only. */ 052 private boolean m_detailOnly; 053 054 /** The id's of of all elements in this container. */ 055 private transient List<CmsUUID> m_elementIds; 056 057 /** The container elements. */ 058 private final List<CmsContainerElementBean> m_elements; 059 060 /** 061 * Indicates whether this container not nested, 062 * or in case of a detail only container page the starting point of a detail only container hierarchy. 063 **/ 064 private boolean m_isRootContainer; 065 066 /** The maximal number of elements in the container. */ 067 private int m_maxElements; 068 069 /** The container name. */ 070 private final String m_name; 071 072 /** The optional container parameter. */ 073 private String m_param; 074 075 /** The parent element instance id. */ 076 private String m_parentInstanceId; 077 078 /** The container type. */ 079 private String m_type; 080 081 /** The container width set by the rendering container tag. */ 082 private String m_width; 083 084 /** 085 * Creates a new container bean.<p> 086 * 087 * @param name the container name 088 * @param type the container type 089 * @param parentInstanceId the parent instance id 090 * @param isRootContainer <code>true</code> if this container not nested 091 * @param maxElements the maximal number of elements in the container 092 * @param elements the elements 093 **/ 094 public CmsContainerBean( 095 String name, 096 String type, 097 String parentInstanceId, 098 boolean isRootContainer, 099 int maxElements, 100 List<CmsContainerElementBean> elements) { 101 102 m_name = name; 103 m_type = type; 104 m_parentInstanceId = parentInstanceId; 105 m_isRootContainer = isRootContainer; 106 m_maxElements = maxElements; 107 m_elements = (elements == null 108 ? Collections.<CmsContainerElementBean> emptyList() 109 : Collections.unmodifiableList(elements)); 110 } 111 112 /** 113 * Creates a new container bean with an unlimited number of elements.<p> 114 * 115 * @param name the container name 116 * @param type the container type 117 * @param parentInstanceId the parent instance id 118 * @param isRootContainer <code>true</code> if this container not nested 119 * @param elements the elements 120 **/ 121 public CmsContainerBean( 122 String name, 123 String type, 124 String parentInstanceId, 125 boolean isRootContainer, 126 List<CmsContainerElementBean> elements) { 127 128 this(name, type, parentInstanceId, isRootContainer, -1, elements); 129 } 130 131 /** 132 * Returns <code>true</code> if the element with the provided id is contained in this container.<p> 133 * 134 * @param elementId the element id to check 135 * 136 * @return <code>true</code> if the element with the provided id is contained in this container 137 */ 138 public boolean containsElement(CmsUUID elementId) { 139 140 return getElementIds().contains(elementId); 141 } 142 143 /** 144 * Returns a lazy initialized map that describes if a certain element if part of this container.<p> 145 * 146 * @return a lazy initialized map that describes if a certain element if part of this container 147 */ 148 public Map<CmsUUID, Boolean> getContainsElement() { 149 150 if (m_containsElement == null) { 151 m_containsElement = CmsCollectionsGenericWrapper.createLazyMap(new Transformer() { 152 153 public Object transform(Object input) { 154 155 return Boolean.valueOf(containsElement((CmsUUID)input)); 156 } 157 }); 158 } 159 return m_containsElement; 160 } 161 162 /** 163 * Returns the id's of all elements in this container.<p> 164 * 165 * @return the id's of all elements in this container 166 */ 167 public List<CmsUUID> getElementIds() { 168 169 if (m_elementIds == null) { 170 m_elementIds = new ArrayList<CmsUUID>(m_elements.size()); 171 for (CmsContainerElementBean element : m_elements) { 172 m_elementIds.add(element.getId()); 173 } 174 } 175 return m_elementIds; 176 } 177 178 /** 179 * Returns the elements in this container.<p> 180 * 181 * @return the elements in this container 182 */ 183 public List<CmsContainerElementBean> getElements() { 184 185 return m_elements; 186 } 187 188 /** 189 * Returns the maximal number of elements in this container.<p> 190 * 191 * @return the maximal number of elements in this container 192 */ 193 public int getMaxElements() { 194 195 return m_maxElements; 196 } 197 198 /** 199 * Returns the name of this container.<p> 200 * 201 * @return the name of this container 202 */ 203 public String getName() { 204 205 return m_name; 206 } 207 208 /** 209 * Returns the (optional) container parameter.<p> 210 * 211 * This is useful for a dynamically generated nested container, 212 * to pass information to the formatter used inside that container. 213 * 214 * If no parameters have been set, this will return <code>null</code> 215 * 216 * @return the (optional) container parameter 217 */ 218 public String getParam() { 219 220 return m_param; 221 } 222 223 /** 224 * Returns the the parent instance id.<p> 225 * 226 * @return the parent instance id 227 */ 228 public String getParentInstanceId() { 229 230 return m_parentInstanceId; 231 } 232 233 /** 234 * Returns the type of this container.<p> 235 * 236 * @return the type of this container 237 */ 238 public String getType() { 239 240 return m_type; 241 } 242 243 /** 244 * Returns the container width set by the rendering container tag.<p> 245 * 246 * @return the container width 247 */ 248 public String getWidth() { 249 250 return m_width; 251 } 252 253 /** 254 * Returns if this container is used on detail pages only.<p> 255 * 256 * @return <code>true</code> if this container is used on detail pages only 257 */ 258 public boolean isDetailOnly() { 259 260 return m_detailOnly; 261 } 262 263 /** 264 * Returns if the given container is a nested container.<p> 265 * 266 * @return <code>true</code> if the given container is a nested container 267 */ 268 public boolean isNestedContainer() { 269 270 return CmsStringUtil.isNotEmptyOrWhitespaceOnly(m_parentInstanceId); 271 } 272 273 /** 274 * Returns if this container not nested, 275 * or in case of a detail only container page the starting point of a detail only container hierarchy.<p> 276 * 277 * @return <code>true</code> if this container not nested 278 */ 279 public boolean isRootContainer() { 280 281 return m_isRootContainer; 282 } 283 284 /** 285 * Sets if this container is used on detail pages only.<p> 286 * 287 * @param detailOnly <code>true</code> if this container is used on detail pages only 288 */ 289 public void setDetailOnly(boolean detailOnly) { 290 291 m_detailOnly = detailOnly; 292 } 293 294 /** 295 * Sets the maximal number of elements in the container.<p> 296 * 297 * @param maxElements the maximal number of elements to set 298 */ 299 public void setMaxElements(int maxElements) { 300 301 m_maxElements = maxElements; 302 } 303 304 /** 305 * Sets the container parameter.<p> 306 * 307 * This is useful for a dynamically generated nested container, 308 * to pass information to the formatter used inside that container. 309 * 310 * @param param the parameter String to set 311 */ 312 public void setParam(String param) { 313 314 m_param = param; 315 } 316 317 /** 318 * Sets the container type.<p> 319 * 320 * @param type the container type 321 */ 322 public void setType(String type) { 323 324 m_type = type; 325 } 326 327 /** 328 * Sets the client side render with of this container.<p> 329 * 330 * @param width the client side render with of this container 331 */ 332 public void setWidth(String width) { 333 334 m_width = width; 335 } 336}