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 GmbH & Co. KG, 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 030/** 031 * The cache settings for ADE.<p> 032 * 033 * @since 8.0.0 034 */ 035public class CmsADECacheSettings { 036 037 /** Default size for container page caches. */ 038 private static final int DEFAULT_CONTAINER_PAGE_SIZE = 128; 039 040 /** The size of the container page offline cache. */ 041 private int m_containerPageOfflineSize; 042 043 /** The size of the container page online cache. */ 044 private int m_containerPageOnlineSize; 045 046 /** Default size for group container caches. */ 047 private static final int DEFAULT_GROUP_CONTAINER_SIZE = 128; 048 049 /** The size of the group container offline cache. */ 050 private int m_groupContainerOfflineSize; 051 052 /** The size of the group container online cache. */ 053 private int m_groupContainerOnlineSize; 054 055 /** 056 * Default constructor.<p> 057 */ 058 public CmsADECacheSettings() { 059 060 super(); 061 } 062 063 /** 064 * Returns the size of the container page offline cache.<p> 065 * 066 * @return the size of the container page offline cache 067 */ 068 public int getContainerPageOfflineSize() { 069 070 if (m_containerPageOfflineSize <= 0) { 071 return DEFAULT_CONTAINER_PAGE_SIZE; 072 } 073 return m_containerPageOfflineSize; 074 } 075 076 /** 077 * Returns the size of the container page online cache.<p> 078 * 079 * @return the size of the container page online cache 080 */ 081 public int getContainerPageOnlineSize() { 082 083 if (m_containerPageOnlineSize <= 0) { 084 return DEFAULT_CONTAINER_PAGE_SIZE; 085 } 086 return m_containerPageOnlineSize; 087 } 088 089 /** 090 * Sets the size of the cache for offline container pages.<p> 091 * 092 * @param size the size of the cache for offline container pages 093 */ 094 public void setContainerPageOfflineSize(String size) { 095 096 m_containerPageOfflineSize = getIntValue(size, DEFAULT_CONTAINER_PAGE_SIZE); 097 } 098 099 /** 100 * Sets the size of the cache for online container pages.<p> 101 * 102 * @param size the size of the cache for online container pages 103 */ 104 public void setContainerPageOnlineSize(String size) { 105 106 m_containerPageOnlineSize = getIntValue(size, DEFAULT_CONTAINER_PAGE_SIZE); 107 } 108 109 /** 110 * Returns the size of the group container offline cache.<p> 111 * 112 * @return the size of the group container offline cache 113 */ 114 public int getGroupContainerOfflineSize() { 115 116 if (m_groupContainerOfflineSize <= 0) { 117 return DEFAULT_GROUP_CONTAINER_SIZE; 118 } 119 return m_groupContainerOfflineSize; 120 } 121 122 /** 123 * Returns the size of the group container online cache.<p> 124 * 125 * @return the size of the group container online cache 126 */ 127 public int getGroupContainerOnlineSize() { 128 129 if (m_groupContainerOnlineSize <= 0) { 130 return DEFAULT_GROUP_CONTAINER_SIZE; 131 } 132 return m_groupContainerOnlineSize; 133 } 134 135 /** 136 * Sets the size of the cache for offline group containers.<p> 137 * 138 * @param size the size of the cache for offline group containers 139 */ 140 public void setGroupContainerOfflineSize(String size) { 141 142 m_groupContainerOfflineSize = getIntValue(size, DEFAULT_GROUP_CONTAINER_SIZE); 143 } 144 145 /** 146 * Sets the size of the cache for online group containers.<p> 147 * 148 * @param size the size of the cache for online group containers 149 */ 150 public void setGroupContainerOnlineSize(String size) { 151 152 m_groupContainerOnlineSize = getIntValue(size, DEFAULT_GROUP_CONTAINER_SIZE); 153 } 154 155 /** 156 * Turns a string into an int.<p> 157 * 158 * @param str the string to be converted 159 * @param defaultValue a default value to be returned in case the string could not be parsed or the parsed int value is <= 0 160 * @return the int value of the string 161 */ 162 private int getIntValue(String str, int defaultValue) { 163 164 try { 165 int intValue = Integer.parseInt(str); 166 return (intValue > 0) ? intValue : defaultValue; 167 } catch (NumberFormatException e) { 168 // intentionally left blank 169 } 170 return defaultValue; 171 } 172}