001: /**
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */package org.apache.geronimo.console.logmanager;
017:
018: import java.io.IOException;
019:
020: import javax.portlet.ActionRequest;
021: import javax.portlet.ActionResponse;
022: import javax.portlet.PortletConfig;
023: import javax.portlet.PortletContext;
024: import javax.portlet.PortletException;
025: import javax.portlet.PortletRequestDispatcher;
026: import javax.portlet.RenderRequest;
027: import javax.portlet.RenderResponse;
028: import javax.portlet.WindowState;
029:
030: import org.apache.geronimo.console.BasePortlet;
031: import org.apache.geronimo.console.util.PortletManager;
032: import org.apache.geronimo.system.logging.SystemLog;
033:
034: public class LogManagerPortlet extends BasePortlet {
035:
036: protected PortletRequestDispatcher normalView;
037:
038: protected PortletRequestDispatcher helpView;
039:
040: protected void doHelp(RenderRequest renderRequest,
041: RenderResponse renderRespose) throws PortletException,
042: IOException {
043: helpView.include(renderRequest, renderRespose);
044: }
045:
046: protected void doView(RenderRequest renderRequest,
047: RenderResponse renderRespose) throws PortletException,
048: IOException {
049: if (WindowState.MINIMIZED
050: .equals(renderRequest.getWindowState())) {
051: return;
052: }
053: SystemLog log = PortletManager
054: .getCurrentSystemLog(renderRequest);
055: renderRequest.setAttribute("configFile", log
056: .getConfigFileName());
057: // renderRequest.setAttribute("configuration", LogHelper.getConfiguration());
058: renderRequest
059: .setAttribute("logLevel", log.getRootLoggerLevel());
060: try {
061: renderRequest.setAttribute("refreshPeriod", new Integer(log
062: .getRefreshPeriodSeconds()));
063: } catch (NumberFormatException e) {
064: //ignore
065: }
066:
067: normalView.include(renderRequest, renderRespose);
068: }
069:
070: public void init(PortletConfig portletConfig)
071: throws PortletException {
072: PortletContext pc = portletConfig.getPortletContext();
073: normalView = pc
074: .getRequestDispatcher("/WEB-INF/view/logmanager/view.jsp");
075: helpView = pc
076: .getRequestDispatcher("/WEB-INF/view/logmanager/help.jsp");
077: super .init(portletConfig);
078: }
079:
080: public void processAction(ActionRequest actionRequest,
081: ActionResponse actionResponse) throws PortletException,
082: IOException {
083: SystemLog log = PortletManager
084: .getCurrentSystemLog(actionRequest);
085:
086: String action = actionRequest.getParameter("action");
087: String logLevel = actionRequest.getParameter("logLevel");
088: String configFile = actionRequest.getParameter("configFile");
089: String configuration = actionRequest.getParameter("append");
090: String refreshPeriod = actionRequest
091: .getParameter("refreshPeriod");
092: String currentLevel = log.getRootLoggerLevel();
093:
094: if ("update".equals(action)) {
095: if (refreshPeriod != null) {
096: int refreshPeriodInt = 0;
097: try {
098: refreshPeriodInt = Integer.parseInt(refreshPeriod);
099: } catch (NumberFormatException e) {
100: //ignore
101: }
102: if (refreshPeriodInt != log.getRefreshPeriodSeconds()) {
103: log.setRefreshPeriodSeconds(refreshPeriodInt);
104: }
105: }
106: if (!log.getConfigFileName().equals(configFile)) {
107: log.setConfigFileName(configFile);
108: }
109: if (!currentLevel.equals(logLevel)) {
110: log.setRootLoggerLevel(logLevel);
111: }
112: }
113: }
114: }
|