KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > roller > ui > admin > struts > actions > CacheInfoAction


1 /*
2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. The ASF licenses this file to You
4 * under the Apache License, Version 2.0 (the "License"); you may not
5 * use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License. For additional information regarding
15 * copyright in this work, please see the NOTICE file in the top level
16 * directory of this distribution.
17 */

18 /*
19  * CacheInfoAction.java
20  *
21  * Created on November 11, 2005, 1:12 PM
22  */

23
24 package org.apache.roller.ui.admin.struts.actions;
25
26 import java.io.IOException JavaDoc;
27 import java.util.Map JavaDoc;
28 import javax.servlet.ServletException JavaDoc;
29 import javax.servlet.http.HttpServletRequest JavaDoc;
30 import javax.servlet.http.HttpServletResponse JavaDoc;
31 import org.apache.commons.logging.Log;
32 import org.apache.commons.logging.LogFactory;
33 import org.apache.struts.action.ActionForm;
34 import org.apache.struts.action.ActionForward;
35 import org.apache.struts.action.ActionMapping;
36 import org.apache.struts.actions.DispatchAction;
37 import org.apache.roller.ui.core.BasePageModel;
38 import org.apache.roller.ui.core.RollerRequest;
39 import org.apache.roller.ui.core.RollerSession;
40 import org.apache.roller.util.cache.CacheManager;
41
42
43 /**
44  * Struts Action class which handles requests to the System Info page.
45  *
46  * @struts.action path="/roller-ui/admin/cacheInfo" scope="request" parameter="method"
47  *
48  * @struts.action-forward name="cacheInfo.page" path=".cacheInfo"
49  *
50  * @author Allen Gilliland
51  */

52 public class CacheInfoAction extends DispatchAction {
53     
54     private static Log mLogger = LogFactory.getLog(CacheInfoAction.class);
55     
56     
57     public ActionForward unspecified(
58             ActionMapping mapping,
59             ActionForm actionForm,
60             HttpServletRequest JavaDoc request,
61             HttpServletResponse JavaDoc response)
62             throws IOException JavaDoc, ServletException JavaDoc {
63         
64         ActionForward forward = mapping.findForward("cacheInfo.page");
65         
66         try {
67             BasePageModel pageModel = new BasePageModel(
68                     "cacheInfo.title", request, response, mapping);
69             request.setAttribute("model",pageModel);
70             RollerRequest rreq = RollerRequest.getRollerRequest(request);
71             RollerSession rollerSession = RollerSession.getRollerSession(request);
72             if (rollerSession.isGlobalAdminUser() ) {
73                 
74                 // caching instrumentation
75
Map JavaDoc cacheStats = CacheManager.getStats();
76                 request.setAttribute("cacheStats", cacheStats);
77                 
78             } else {
79                 forward = mapping.findForward("access-denied");
80             }
81             
82         } catch (Exception JavaDoc e) {
83             mLogger.error("ERROR in action",e);
84             throw new ServletException JavaDoc(e);
85         }
86         
87         return forward;
88     }
89     
90     
91     /**
92      * clear action.
93      *
94      * this is triggered when someone has indicated that they want to clear
95      * one or all of the caches.
96      */

97     public ActionForward clear(
98             ActionMapping mapping,
99             ActionForm actionForm,
100             HttpServletRequest JavaDoc request,
101             HttpServletResponse JavaDoc response)
102             throws IOException JavaDoc, ServletException JavaDoc {
103         
104         ActionForward forward = mapping.findForward("cacheInfo.page");
105         
106         try {
107             BasePageModel pageModel = new BasePageModel(
108                     "cacheInfo.title", request, response, mapping);
109             request.setAttribute("model",pageModel);
110             RollerRequest rreq = RollerRequest.getRollerRequest(request);
111             RollerSession rollerSession = RollerSession.getRollerSession(request);
112             if (rollerSession.isGlobalAdminUser() ) {
113                 
114                 // see if a specific cache was specified
115
String JavaDoc handlerClass = request.getParameter("cache");
116                 if(handlerClass != null && handlerClass.length() > 0) {
117                     CacheManager.clear(handlerClass);
118                 } else {
119                     CacheManager.clear();
120                 }
121                 
122                 // caching instrumentation
123
Map JavaDoc cacheStats = CacheManager.getStats();
124                 request.setAttribute("cacheStats", cacheStats);
125                 
126             } else {
127                 forward = mapping.findForward("access-denied");
128             }
129             
130         } catch (Exception JavaDoc e) {
131             mLogger.error("ERROR in action",e);
132             throw new ServletException JavaDoc(e);
133         }
134         
135         return forward;
136     }
137 }
138
Popular Tags