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 */ 017 018 package org.apache.geronimo.console.internaldb; 019 020 import java.io.IOException; 021 import java.util.HashMap; 022 import java.util.Map; 023 024 import javax.portlet.ActionRequest; 025 import javax.portlet.ActionResponse; 026 import javax.portlet.PortletConfig; 027 import javax.portlet.PortletException; 028 import javax.portlet.PortletRequestDispatcher; 029 import javax.portlet.RenderRequest; 030 import javax.portlet.RenderResponse; 031 import javax.portlet.WindowState; 032 033 import org.apache.geronimo.console.BasePortlet; 034 035 public class InternalDBPortlet extends BasePortlet { 036 037 private static final String NORMALVIEW_JSP = "/WEB-INF/view/internaldb/internalDBNormal.jsp"; 038 039 private static final String MAXIMIZEDVIEW_JSP = "/WEB-INF/view/internaldb/internalDBMaximized.jsp"; 040 041 private static final String HELPVIEW_JSP = "/WEB-INF/view/internaldb/internalDBHelp.jsp"; 042 043 private static InternalDBHelper helper = new InternalDBHelper(); 044 045 private static Map javaSysInfo = new HashMap(); 046 047 private PortletRequestDispatcher normalView; 048 049 private PortletRequestDispatcher maximizedView; 050 051 private PortletRequestDispatcher helpView; 052 053 public void processAction(ActionRequest actionRequest, 054 ActionResponse actionResponse) throws PortletException, IOException { 055 // Getting parameters here because it fails on doView() 056 String rdbms = actionRequest.getParameter("rdbms"); 057 if (rdbms != null) { 058 actionResponse.setRenderParameter("rdbms", rdbms); 059 } 060 } 061 062 protected void doView(RenderRequest renderRequest, 063 RenderResponse renderResponse) throws IOException, PortletException { 064 if (WindowState.MINIMIZED.equals(renderRequest.getWindowState())) { 065 return; 066 } 067 068 String rdbmsParam = renderRequest.getParameter("rdbms"); 069 int rdbms = 1; 070 if ((rdbmsParam != null) && (rdbmsParam.length() > 0)) { 071 rdbms = Integer.parseInt(rdbmsParam); 072 } 073 Map internalDB = helper.getDBInfo(); 074 renderRequest.setAttribute("internalDB", internalDB); 075 076 if (WindowState.NORMAL.equals(renderRequest.getWindowState())) { 077 normalView.include(renderRequest, renderResponse); 078 } else { 079 maximizedView.include(renderRequest, renderResponse); 080 } 081 } 082 083 protected void doHelp(RenderRequest renderRequest, 084 RenderResponse renderResponse) throws PortletException, IOException { 085 helpView.include(renderRequest, renderResponse); 086 } 087 088 public void init(PortletConfig portletConfig) throws PortletException { 089 super.init(portletConfig); 090 normalView = portletConfig.getPortletContext().getRequestDispatcher( 091 NORMALVIEW_JSP); 092 maximizedView = portletConfig.getPortletContext().getRequestDispatcher( 093 MAXIMIZEDVIEW_JSP); 094 helpView = portletConfig.getPortletContext().getRequestDispatcher( 095 HELPVIEW_JSP); 096 } 097 098 public void destroy() { 099 normalView = null; 100 maximizedView = null; 101 helpView = null; 102 super.destroy(); 103 } 104 105 }