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.workplace.tools.cache; 029 030import org.opencms.cache.CmsLruCache; 031import org.opencms.flex.CmsFlexCache; 032import org.opencms.flex.CmsFlexController; 033import org.opencms.jsp.CmsJspActionElement; 034import org.opencms.util.CmsFileUtil; 035import org.opencms.widgets.CmsDisplayWidget; 036import org.opencms.workplace.CmsWidgetDialog; 037import org.opencms.workplace.CmsWidgetDialogParameter; 038 039import java.util.ArrayList; 040import java.util.Locale; 041 042import javax.servlet.http.HttpServletRequest; 043import javax.servlet.http.HttpServletResponse; 044import javax.servlet.jsp.PageContext; 045 046/** 047 * The flex cache overview dialog.<p> 048 * 049 * @since 7.0.5 050 */ 051public class CmsFlexCacheOverviewDialog extends CmsWidgetDialog { 052 053 /** localized messages Keys prefix. */ 054 public static final String KEY_PREFIX = "flex.stats"; 055 056 /** Defines which pages are valid for this dialog. */ 057 public static final String[] PAGES = {"page1"}; 058 059 /** Flex Caches average size. */ 060 private String m_avgSize; 061 062 /** Flex Caches current size. */ 063 private String m_curSize; 064 065 /** Flex Caches keys. */ 066 private String m_keys; 067 068 /** Flex Caches maximal size. */ 069 private String m_maxSize; 070 071 /** Flex Caches variations. */ 072 private String m_variations; 073 074 /** 075 * Public constructor with JSP action element.<p> 076 * 077 * @param jsp an initialized JSP action element 078 */ 079 public CmsFlexCacheOverviewDialog(CmsJspActionElement jsp) { 080 081 super(jsp); 082 083 } 084 085 /** 086 * Public constructor with JSP variables.<p> 087 * 088 * @param context the JSP page context 089 * @param req the JSP request 090 * @param res the JSP response 091 */ 092 public CmsFlexCacheOverviewDialog(PageContext context, HttpServletRequest req, HttpServletResponse res) { 093 094 this(new CmsJspActionElement(context, req, res)); 095 } 096 097 /** 098 * Commits the edited group to the db.<p> 099 */ 100 @Override 101 public void actionCommit() { 102 103 // no saving needed 104 setCommitErrors(new ArrayList()); 105 } 106 107 /** 108 * Returns the average size.<p> 109 * 110 * @return the average size 111 */ 112 public String getAvgSize() { 113 114 return m_avgSize; 115 } 116 117 /** 118 * Returns the current size.<p> 119 * 120 * @return the current size 121 */ 122 public String getCurSize() { 123 124 return m_curSize; 125 } 126 127 /** 128 * Returns the number of keys.<p> 129 * 130 * @return the number of keys 131 */ 132 public String getKeys() { 133 134 return m_keys; 135 } 136 137 /** 138 * Returns the maximal size.<p> 139 * 140 * @return the maximal size 141 */ 142 public String getMaxSize() { 143 144 return m_maxSize; 145 } 146 147 /** 148 * Returns the number of variations.<p> 149 * 150 * @return the number of variations 151 */ 152 public String getVariations() { 153 154 return m_variations; 155 } 156 157 /** 158 * Sets the average size.<p> 159 * 160 * @param avgSize the average size to set 161 */ 162 public void setAvgSize(String avgSize) { 163 164 m_avgSize = avgSize; 165 } 166 167 /** 168 * Sets the current size.<p> 169 * 170 * @param curSize the current size to set 171 */ 172 public void setCurSize(String curSize) { 173 174 m_curSize = curSize; 175 } 176 177 /** 178 * Sets the number of keys.<p> 179 * 180 * @param keys the number of keys to set 181 */ 182 public void setKeys(String keys) { 183 184 m_keys = keys; 185 } 186 187 /** 188 * Sets the maximal size.<p> 189 * 190 * @param maxSize the maximal size to set 191 */ 192 public void setMaxSize(String maxSize) { 193 194 m_maxSize = maxSize; 195 } 196 197 /** 198 * Sets the number of variations.<p> 199 * 200 * @param variations the number of variations to set 201 */ 202 public void setVariations(String variations) { 203 204 m_variations = variations; 205 } 206 207 /** 208 * Creates the dialog HTML for all defined widgets of the named dialog (page).<p> 209 * 210 * This overwrites the method from the super class to create a layout variation for the widgets.<p> 211 * 212 * @param dialog the dialog (page) to get the HTML for 213 * @return the dialog HTML for all defined widgets of the named dialog (page) 214 */ 215 @Override 216 protected String createDialogHtml(String dialog) { 217 218 StringBuffer result = new StringBuffer(1024); 219 220 // create widget table 221 result.append(createWidgetTableStart()); 222 223 // show error header once if there were validation errors 224 result.append(createWidgetErrorHeader()); 225 226 if (dialog.equals(PAGES[0])) { 227 // create the widgets for the first dialog page 228 result.append(dialogBlockStart(key(Messages.GUI_FLEXCACHE_LABEL_STATS_BLOCK_0))); 229 result.append(createWidgetTableStart()); 230 result.append(createDialogRowsHtml(0, 1)); 231 result.append(createWidgetTableEnd()); 232 result.append(dialogBlockEnd()); 233 result.append(dialogBlockStart(key(Messages.GUI_FLEXCACHE_LABEL_MEMORY_BLOCK_0))); 234 result.append(createWidgetTableStart()); 235 result.append(createDialogRowsHtml(2, 4)); 236 result.append(createWidgetTableEnd()); 237 result.append(dialogBlockEnd()); 238 } 239 240 // close widget table 241 result.append(createWidgetTableEnd()); 242 243 return result.toString(); 244 } 245 246 /** 247 * @see org.opencms.workplace.CmsWidgetDialog#defaultActionHtmlEnd() 248 */ 249 @Override 250 protected String defaultActionHtmlEnd() { 251 252 return ""; 253 } 254 255 /** 256 * Creates the list of widgets for this dialog.<p> 257 */ 258 @Override 259 protected void defineWidgets() { 260 261 // initialize the cache object to use for the dialog 262 initCacheObject(); 263 264 setKeyPrefix(KEY_PREFIX); 265 266 // widgets to display 267 addWidget(new CmsWidgetDialogParameter(this, "keys", PAGES[0], new CmsDisplayWidget())); 268 addWidget(new CmsWidgetDialogParameter(this, "variations", PAGES[0], new CmsDisplayWidget())); 269 addWidget(new CmsWidgetDialogParameter(this, "maxSize", PAGES[0], new CmsDisplayWidget())); 270 addWidget(new CmsWidgetDialogParameter(this, "avgSize", PAGES[0], new CmsDisplayWidget())); 271 addWidget(new CmsWidgetDialogParameter(this, "curSize", PAGES[0], new CmsDisplayWidget())); 272 } 273 274 /** 275 * @see org.opencms.workplace.CmsWidgetDialog#getPageArray() 276 */ 277 @Override 278 protected String[] getPageArray() { 279 280 return PAGES; 281 } 282 283 /** 284 * Initializes the cache object.<p> 285 */ 286 protected void initCacheObject() { 287 288 CmsFlexController controller = (CmsFlexController)getJsp().getRequest().getAttribute( 289 CmsFlexController.ATTRIBUTE_NAME); 290 CmsFlexCache cache = controller.getCmsCache(); 291 292 setVariations("" + cache.size()); 293 setKeys("" + cache.keySize()); 294 CmsLruCache entryLruCache = cache.getEntryLruCache(); 295 296 if (entryLruCache != null) { 297 Locale locale = getLocale(); 298 setMaxSize(CmsFileUtil.formatFilesize(entryLruCache.getMaxCacheCosts(), locale)); 299 setAvgSize(CmsFileUtil.formatFilesize(entryLruCache.getAvgCacheCosts(), locale)); 300 setCurSize(CmsFileUtil.formatFilesize(entryLruCache.getObjectCosts(), locale)); 301 } 302 } 303 304 /** 305 * @see org.opencms.workplace.CmsWorkplace#initMessages() 306 */ 307 @Override 308 protected void initMessages() { 309 310 // add specific dialog resource bundle 311 addMessages(Messages.get().getBundleName()); 312 // add default resource bundles 313 super.initMessages(); 314 } 315 316 /** 317 * Overridden to set the online help path for this dialog.<p> 318 * 319 * @see org.opencms.workplace.CmsWorkplace#initWorkplaceMembers(org.opencms.jsp.CmsJspActionElement) 320 */ 321 @Override 322 protected void initWorkplaceMembers(CmsJspActionElement jsp) { 323 324 super.initWorkplaceMembers(jsp); 325 setOnlineHelpUriCustom("/cache/flex/"); 326 } 327}