001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. The ASF licenses this file to You
004: * under the Apache License, Version 2.0 (the "License"); you may not
005: * use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License. For additional information regarding
015: * copyright in this work, please see the NOTICE file in the top level
016: * directory of this distribution.
017: */
018: /*
019: * CacheInfoAction.java
020: *
021: * Created on November 11, 2005, 1:12 PM
022: */
023:
024: package org.apache.roller.ui.admin.struts.actions;
025:
026: import java.io.IOException;
027: import java.util.Map;
028: import javax.servlet.ServletException;
029: import javax.servlet.http.HttpServletRequest;
030: import javax.servlet.http.HttpServletResponse;
031: import org.apache.commons.logging.Log;
032: import org.apache.commons.logging.LogFactory;
033: import org.apache.struts.action.ActionForm;
034: import org.apache.struts.action.ActionForward;
035: import org.apache.struts.action.ActionMapping;
036: import org.apache.struts.actions.DispatchAction;
037: import org.apache.roller.ui.core.BasePageModel;
038: import org.apache.roller.ui.core.RollerRequest;
039: import org.apache.roller.ui.core.RollerSession;
040: import org.apache.roller.util.cache.CacheManager;
041:
042: /**
043: * Struts Action class which handles requests to the System Info page.
044: *
045: * @struts.action path="/roller-ui/admin/cacheInfo" scope="request" parameter="method"
046: *
047: * @struts.action-forward name="cacheInfo.page" path=".cacheInfo"
048: *
049: * @author Allen Gilliland
050: */
051: public class CacheInfoAction extends DispatchAction {
052:
053: private static Log mLogger = LogFactory
054: .getLog(CacheInfoAction.class);
055:
056: public ActionForward unspecified(ActionMapping mapping,
057: ActionForm actionForm, HttpServletRequest request,
058: HttpServletResponse response) throws IOException,
059: ServletException {
060:
061: ActionForward forward = mapping.findForward("cacheInfo.page");
062:
063: try {
064: BasePageModel pageModel = new BasePageModel(
065: "cacheInfo.title", request, response, mapping);
066: request.setAttribute("model", pageModel);
067: RollerRequest rreq = RollerRequest
068: .getRollerRequest(request);
069: RollerSession rollerSession = RollerSession
070: .getRollerSession(request);
071: if (rollerSession.isGlobalAdminUser()) {
072:
073: // caching instrumentation
074: Map cacheStats = CacheManager.getStats();
075: request.setAttribute("cacheStats", cacheStats);
076:
077: } else {
078: forward = mapping.findForward("access-denied");
079: }
080:
081: } catch (Exception e) {
082: mLogger.error("ERROR in action", e);
083: throw new ServletException(e);
084: }
085:
086: return forward;
087: }
088:
089: /**
090: * clear action.
091: *
092: * this is triggered when someone has indicated that they want to clear
093: * one or all of the caches.
094: */
095: public ActionForward clear(ActionMapping mapping,
096: ActionForm actionForm, HttpServletRequest request,
097: HttpServletResponse response) throws IOException,
098: ServletException {
099:
100: ActionForward forward = mapping.findForward("cacheInfo.page");
101:
102: try {
103: BasePageModel pageModel = new BasePageModel(
104: "cacheInfo.title", request, response, mapping);
105: request.setAttribute("model", pageModel);
106: RollerRequest rreq = RollerRequest
107: .getRollerRequest(request);
108: RollerSession rollerSession = RollerSession
109: .getRollerSession(request);
110: if (rollerSession.isGlobalAdminUser()) {
111:
112: // see if a specific cache was specified
113: String handlerClass = request.getParameter("cache");
114: if (handlerClass != null && handlerClass.length() > 0) {
115: CacheManager.clear(handlerClass);
116: } else {
117: CacheManager.clear();
118: }
119:
120: // caching instrumentation
121: Map cacheStats = CacheManager.getStats();
122: request.setAttribute("cacheStats", cacheStats);
123:
124: } else {
125: forward = mapping.findForward("access-denied");
126: }
127:
128: } catch (Exception e) {
129: mLogger.error("ERROR in action", e);
130: throw new ServletException(e);
131: }
132:
133: return forward;
134: }
135: }
|