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.jmxmanager;
019    
020    import java.io.IOException;
021    import java.io.PrintWriter;
022    
023    import javax.portlet.ActionRequest;
024    import javax.portlet.ActionResponse;
025    import javax.portlet.PortletConfig;
026    import javax.portlet.PortletContext;
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    /**
036     * The JMX manager portlet
037     */
038    public class JMXManagerPortlet extends BasePortlet {
039        private static final String VIEWJMXSERVER_ACTION = "viewJMXServer";
040    
041        private static final String VIEWJMXSERVER_JSP = "/WEB-INF/view/jmxmanager/viewJMXServer.jsp";
042    
043        private static final String HELP_JSP = "/WEB-INF/view/jmxmanager/help.jsp";
044    
045        private PortletRequestDispatcher viewJMXServerView;
046    
047        private PortletRequestDispatcher helpView;
048    
049        /**
050         * Process an action request
051         */
052        public void processAction(ActionRequest actionRequest,
053                ActionResponse actionResponse) throws PortletException, IOException {
054        }
055    
056        /**
057         * Serve up the view mode
058         */
059        protected void doView(RenderRequest renderRequest,
060                RenderResponse renderResponse) throws IOException, PortletException {
061            if (WindowState.MINIMIZED.equals(renderRequest.getWindowState())) {
062                return;
063            } else if (WindowState.NORMAL.equals(renderRequest.getWindowState())) {
064                String action = renderRequest.getParameter("action");
065                if (action == null) {
066                    action = VIEWJMXSERVER_ACTION;
067                }
068                if (VIEWJMXSERVER_ACTION.equals(action)) {
069                    viewJMXServerView.include(renderRequest, renderResponse);
070                } else {
071                    renderResponse.setContentType("text/html");
072                    PrintWriter out = renderResponse.getWriter();
073                    String errorMsg = "Invalid action message: " + action;
074                    out.println(errorMsg);
075                }
076            } else if (WindowState.MAXIMIZED.equals(renderRequest.getWindowState())) {
077                renderResponse.setContentType("text/html");
078                PrintWriter out = renderResponse.getWriter();
079                String errorMsg = "Invalid window state: "
080                        + renderRequest.getWindowState();
081                out.println(errorMsg);
082            }
083        }
084    
085        /**
086         * Serve up the help mode
087         */
088        protected void doHelp(RenderRequest renderRequest,
089                RenderResponse renderResponse) throws PortletException, IOException {
090            helpView.include(renderRequest, renderResponse);
091        }
092    
093        /**
094         * Portlet is being placed into service
095         */
096        public void init(PortletConfig portletConfig) throws PortletException {
097            super.init(portletConfig);
098            PortletContext pc = portletConfig.getPortletContext();
099            viewJMXServerView = pc.getRequestDispatcher(VIEWJMXSERVER_JSP);
100            helpView = pc.getRequestDispatcher(HELP_JSP);
101        }
102    
103        /**
104         * Portlet is being taken out of service
105         */
106        public void destroy() {
107            viewJMXServerView = null;
108            helpView = null;
109            super.destroy();
110        }
111    }