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.jsp.CmsJspActionElement; 031import org.opencms.loader.CmsImageLoader; 032import org.opencms.main.CmsEvent; 033import org.opencms.main.I_CmsEventListener; 034import org.opencms.main.OpenCms; 035import org.opencms.widgets.CmsCalendarWidget; 036import org.opencms.workplace.CmsWidgetDialog; 037import org.opencms.workplace.CmsWidgetDialogParameter; 038 039import java.util.Collections; 040 041import javax.servlet.http.HttpServletRequest; 042import javax.servlet.http.HttpServletResponse; 043import javax.servlet.jsp.PageContext; 044 045/** 046 * The image cache clear dialog.<p> 047 * 048 * @since 7.0.5 049 */ 050public class CmsImageCacheClearDialog extends CmsWidgetDialog { 051 052 /** localized messages Keys prefix. */ 053 public static final String KEY_PREFIX = "image.clear"; 054 055 /** Defines which pages are valid for this dialog. */ 056 public static final String[] PAGES = {"page1"}; 057 058 /** Widget value. */ 059 private String m_time; 060 061 /** 062 * Public constructor with JSP action element.<p> 063 * 064 * @param jsp an initialized JSP action element 065 */ 066 public CmsImageCacheClearDialog(CmsJspActionElement jsp) { 067 068 super(jsp); 069 070 } 071 072 /** 073 * Public constructor with JSP variables.<p> 074 * 075 * @param context the JSP page context 076 * @param req the JSP request 077 * @param res the JSP response 078 */ 079 public CmsImageCacheClearDialog(PageContext context, HttpServletRequest req, HttpServletResponse res) { 080 081 this(new CmsJspActionElement(context, req, res)); 082 } 083 084 /** 085 * Commits the edited group to the db.<p> 086 */ 087 @Override 088 public void actionCommit() { 089 090 try { 091 float age = (System.currentTimeMillis() - Long.parseLong(m_time)) / (60f * 60f * 1000f); 092 OpenCms.fireCmsEvent( 093 new CmsEvent( 094 I_CmsEventListener.EVENT_CLEAR_CACHES, 095 Collections.<String, Object> singletonMap(CmsImageLoader.PARAM_CLEAR_IMAGES_CACHE, "" + age))); 096 } catch (Exception e) { 097 setCommitErrors(Collections.singletonList((Throwable)e)); 098 } 099 } 100 101 /** 102 * Returns the time.<p> 103 * 104 * @return the time 105 */ 106 public String getTime() { 107 108 return m_time; 109 } 110 111 /** 112 * Sets the time.<p> 113 * 114 * @param time the time to set 115 */ 116 public void setTime(String time) { 117 118 m_time = time; 119 } 120 121 /** 122 * Creates the dialog HTML for all defined widgets of the named dialog (page).<p> 123 * 124 * This overwrites the method from the super class to create a layout variation for the widgets.<p> 125 * 126 * @param dialog the dialog (page) to get the HTML for 127 * 128 * @return the dialog HTML for all defined widgets of the named dialog (page) 129 */ 130 @Override 131 protected String createDialogHtml(String dialog) { 132 133 StringBuffer result = new StringBuffer(1024); 134 135 // create widget table 136 result.append(createWidgetTableStart()); 137 138 // show error header once if there were validation errors 139 result.append(createWidgetErrorHeader()); 140 141 if (dialog.equals(PAGES[0])) { 142 // create the widgets for the first dialog page 143 result.append(dialogBlockStart(key(Messages.GUI_IMAGECACHE_LABEL_CLEAN_BLOCK_0))); 144 result.append(createWidgetTableStart()); 145 result.append(createDialogRowsHtml(0, 0)); 146 result.append(createWidgetTableEnd()); 147 result.append(dialogBlockEnd()); 148 } 149 150 // close widget table 151 result.append(createWidgetTableEnd()); 152 153 return result.toString(); 154 } 155 156 /** 157 * @see org.opencms.workplace.CmsWidgetDialog#defaultActionHtmlEnd() 158 */ 159 @Override 160 protected String defaultActionHtmlEnd() { 161 162 return ""; 163 } 164 165 /** 166 * Creates the list of widgets for this dialog.<p> 167 */ 168 @Override 169 protected void defineWidgets() { 170 171 setKeyPrefix(KEY_PREFIX); 172 173 // default value is 30 minutes ago 174 setTime("" + (System.currentTimeMillis() - (30 * 60 * 1000L))); 175 // widgets to display 176 addWidget(new CmsWidgetDialogParameter(this, "time", PAGES[0], new CmsCalendarWidget())); 177 } 178 179 /** 180 * @see org.opencms.workplace.CmsWidgetDialog#getPageArray() 181 */ 182 @Override 183 protected String[] getPageArray() { 184 185 return PAGES; 186 } 187 188 /** 189 * @see org.opencms.workplace.CmsWorkplace#initMessages() 190 */ 191 @Override 192 protected void initMessages() { 193 194 // add specific dialog resource bundle 195 addMessages(Messages.get().getBundleName()); 196 // add default resource bundles 197 super.initMessages(); 198 } 199 200 /** 201 * Overridden to set the online help path for this dialog.<p> 202 * 203 * @see org.opencms.workplace.CmsWorkplace#initWorkplaceMembers(org.opencms.jsp.CmsJspActionElement) 204 */ 205 @Override 206 protected void initWorkplaceMembers(CmsJspActionElement jsp) { 207 208 super.initWorkplaceMembers(jsp); 209 setOnlineHelpUriCustom("/cache/image/clean/"); 210 } 211}