KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > geronimo > console > logmanager > LogManagerPortlet


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

17
18 package org.apache.geronimo.console.logmanager;
19
20 import java.io.IOException JavaDoc;
21
22 import javax.portlet.ActionRequest;
23 import javax.portlet.ActionResponse;
24 import javax.portlet.PortletConfig;
25 import javax.portlet.PortletContext;
26 import javax.portlet.PortletException;
27 import javax.portlet.PortletRequestDispatcher;
28 import javax.portlet.RenderRequest;
29 import javax.portlet.RenderResponse;
30 import javax.portlet.WindowState;
31
32 import org.apache.geronimo.console.BasePortlet;
33 import org.apache.geronimo.console.util.PortletManager;
34 import org.apache.geronimo.system.logging.SystemLog;
35
36 public class LogManagerPortlet extends BasePortlet {
37
38     protected PortletRequestDispatcher normalView;
39
40     protected PortletRequestDispatcher helpView;
41
42     protected void doHelp(RenderRequest renderRequest,
43             RenderResponse renderRespose) throws PortletException, IOException JavaDoc {
44         helpView.include(renderRequest, renderRespose);
45     }
46
47     protected void doView(RenderRequest renderRequest,
48             RenderResponse renderRespose) throws PortletException, IOException JavaDoc {
49         if (WindowState.MINIMIZED.equals(renderRequest.getWindowState())) {
50             return;
51         }
52         SystemLog log = PortletManager.getCurrentSystemLog(renderRequest);
53         renderRequest.setAttribute("configFile", log.getConfigFileName());
54 // renderRequest.setAttribute("configuration", LogHelper.getConfiguration());
55
renderRequest.setAttribute("logLevel", log.getRootLoggerLevel());
56         renderRequest.setAttribute("refreshPeriod", new Integer JavaDoc(log.getRefreshPeriodSeconds()));
57
58         normalView.include(renderRequest, renderRespose);
59     }
60
61     public void init(PortletConfig portletConfig) throws PortletException {
62         PortletContext pc = portletConfig.getPortletContext();
63         normalView = pc.getRequestDispatcher("/WEB-INF/view/logmanager/view.jsp");
64         helpView = pc.getRequestDispatcher("/WEB-INF/view/logmanager/help.jsp");
65         super.init(portletConfig);
66     }
67
68     public void processAction(ActionRequest actionRequest,
69             ActionResponse actionResponse) throws PortletException, IOException JavaDoc {
70         SystemLog log = PortletManager.getCurrentSystemLog(actionRequest);
71
72         String JavaDoc action = actionRequest.getParameter("action");
73         String JavaDoc logLevel = actionRequest.getParameter("logLevel");
74         String JavaDoc configFile = actionRequest.getParameter("configFile");
75         String JavaDoc configuration = actionRequest.getParameter("append");
76         String JavaDoc refreshPeriod = actionRequest.getParameter("refreshPeriod");
77         String JavaDoc currentLevel = log.getRootLoggerLevel();
78
79         if ("update".equals(action)) {
80             if (refreshPeriod != null) {
81                 int refreshPeriodInt = Integer.parseInt(refreshPeriod);
82                 if (refreshPeriodInt != log.getRefreshPeriodSeconds()) {
83                     log.setRefreshPeriodSeconds(refreshPeriodInt);
84                 }
85             }
86             if (!log.getConfigFileName().equals(configFile)) {
87                 log.setConfigFileName(configFile);
88             }
89             if (!currentLevel.equals(logLevel)) {
90                 log.setRootLoggerLevel(logLevel);
91             }
92         }
93     }
94 }
Popular Tags