001: /**********************************************************************************
002: * $URL: https://source.sakaiproject.org/svn/memory/tags/sakai_2-4-1/memory-tool/tool/src/java/org/sakaiproject/memory/tool/MemoryAction.java $
003: * $Id: MemoryAction.java 9917 2006-05-25 03:07:52Z ggolden@umich.edu $
004: ***********************************************************************************
005: *
006: * Copyright (c) 2003, 2004, 2005, 2006 The Sakai Foundation.
007: *
008: * Licensed under the Educational Community License, Version 1.0 (the "License");
009: * you may not use this file except in compliance with the License.
010: * You may obtain a copy of the License at
011: *
012: * http://www.opensource.org/licenses/ecl1.php
013: *
014: * Unless required by applicable law or agreed to in writing, software
015: * distributed under the License is distributed on an "AS IS" BASIS,
016: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
017: * See the License for the specific language governing permissions and
018: * limitations under the License.
019: *
020: **********************************************************************************/package org.sakaiproject.memory.tool;
021:
022: import org.sakaiproject.authz.cover.SecurityService;
023: import org.sakaiproject.cheftool.Context;
024: import org.sakaiproject.cheftool.JetspeedRunData;
025: import org.sakaiproject.cheftool.RunData;
026: import org.sakaiproject.cheftool.VelocityPortlet;
027: import org.sakaiproject.cheftool.VelocityPortletPaneledAction;
028: import org.sakaiproject.cheftool.api.Menu;
029: import org.sakaiproject.event.api.SessionState;
030: import org.sakaiproject.memory.api.MemoryPermissionException;
031: import org.sakaiproject.memory.cover.MemoryService;
032: import org.sakaiproject.util.ResourceLoader;
033:
034: /**
035: * <p>
036: * MemoryAction is the Sakai memory tool.
037: * </p>
038: */
039: public class MemoryAction extends VelocityPortletPaneledAction {
040:
041: /** Resource bundle using current language locale */
042: private static ResourceLoader rb = new ResourceLoader("admin");
043:
044: /**
045: * build the context
046: */
047: public String buildMainPanelContext(VelocityPortlet portlet,
048: Context context, RunData rundata, SessionState state) {
049: context.put("tlang", rb);
050:
051: // if not logged in as the super user, we won't do anything
052: if (!SecurityService.isSuperUser()) {
053: return (String) getContext(rundata).get("template")
054: + "_noaccess";
055: }
056:
057: // put $action into context for menus, forms and links
058: context.put(Menu.CONTEXT_ACTION, state
059: .getAttribute(STATE_ACTION));
060:
061: // put the current available memory into the context
062: context.put("memory", Long.toString(MemoryService
063: .getAvailableMemory()));
064:
065: // status, if there
066: if (state.getAttribute("status") != null) {
067: context.put("status", state.getAttribute("status"));
068: state.removeAttribute("status");
069: }
070:
071: return (String) getContext(rundata).get("template");
072:
073: } // buildMainPanelContext
074:
075: /**
076: * doNew called when "eventSubmit_doReset" is in the request parameters to reset memory useage (caches)
077: */
078: public void doReset(RunData data, Context context) {
079: SessionState state = ((JetspeedRunData) data)
080: .getPortletSessionState(((JetspeedRunData) data)
081: .getJs_peid());
082:
083: try {
084: MemoryService.resetCachers();
085: } catch (MemoryPermissionException e) {
086: state.setAttribute("message", rb
087: .getString("memory.notpermis"));
088: }
089:
090: } // doReset
091:
092: /**
093: * doNew called when "eventSubmit_doStatus" is in the request parameters to reset memory useage (caches)
094: */
095: public void doStatus(RunData data, Context context) {
096: SessionState state = ((JetspeedRunData) data)
097: .getPortletSessionState(((JetspeedRunData) data)
098: .getJs_peid());
099:
100: state.setAttribute("status", MemoryService.getStatus());
101:
102: } // doReset
103:
104: } // MemoryAction
|