Quadcap Embedded Server Administrator Console

com/quadcap/app/qws/ActionList.java

Go to the documentation of this file.
00001 package com.quadcap.app.qws; 00002 00003 /* Copyright 1999 - 2003 Quadcap Software. All rights reserved. 00004 * 00005 * This software is distributed under the Quadcap Free Software License. 00006 * This software may be used or modified for any purpose, personal or 00007 * commercial. Open Source redistributions are permitted. Commercial 00008 * redistribution of larger works derived from, or works which bundle 00009 * this software requires a "Commercial Redistribution License"; see 00010 * http://www.quadcap.com/purchase. 00011 * 00012 * Redistributions qualify as "Open Source" under one of the following terms: 00013 * 00014 * Redistributions are made at no charge beyond the reasonable cost of 00015 * materials and delivery. 00016 * 00017 * Redistributions are accompanied by a copy of the Source Code or by an 00018 * irrevocable offer to provide a copy of the Source Code for up to three 00019 * years at the cost of materials and delivery. Such redistributions 00020 * must allow further use, modification, and redistribution of the Source 00021 * Code under substantially the same terms as this license. 00022 * 00023 * Redistributions of source code must retain the copyright notices as they 00024 * appear in each source code file, these license terms, and the 00025 * disclaimer/limitation of liability set forth as paragraph 6 below. 00026 * 00027 * Redistributions in binary form must reproduce this Copyright Notice, 00028 * these license terms, and the disclaimer/limitation of liability set 00029 * forth as paragraph 6 below, in the documentation and/or other materials 00030 * provided with the distribution. 00031 * 00032 * The Software is provided on an "AS IS" basis. No warranty is 00033 * provided that the Software is free of defects, or fit for a 00034 * particular purpose. 00035 * 00036 * Limitation of Liability. Quadcap Software shall not be liable 00037 * for any damages suffered by the Licensee or any third party resulting 00038 * from use of the Software. 00039 */ 00040 00041 import java.io.IOException; 00042 00043 import java.util.Enumeration; 00044 import java.util.HashMap; 00045 00046 import javax.servlet.RequestDispatcher; 00047 import javax.servlet.ServletConfig; 00048 import javax.servlet.ServletContext; 00049 import javax.servlet.ServletException; 00050 00051 import javax.servlet.http.HttpServletRequest; 00052 import javax.servlet.http.HttpServletResponse; 00053 00054 import com.quadcap.http.server22.WebApplication; 00055 import com.quadcap.http.server22.WebServer; 00056 00057 /** 00058 * Implement the 'list' action, which sets the "applications" request 00059 * attribute to be a HashMap of 'context' -> 'application'. Each 00060 * 'application' object is a HashMap containing the interesting properties 00061 * of that application. 00062 * 00063 * @author Stan Bailes 00064 */ 00065 public class ActionList implements Action { 00066 ServletConfig config; 00067 WebServer server; 00068 00069 public void init(ServletConfig config) { 00070 this.config = config; 00071 ServletContext context = config.getServletContext(); 00072 this.server = (WebServer)context.getAttribute("server"); 00073 } 00074 00075 public void service(HttpServletRequest request, 00076 HttpServletResponse response) 00077 throws Exception 00078 { 00079 HashMap map = new HashMap(); 00080 Enumeration names = server.getContextRoots(); 00081 while (names.hasMoreElements()) { 00082 String root = names.nextElement().toString(); 00083 WebApplication app = server.getContextForRoot(root); 00084 HashMap appMap = makeMap(app); 00085 map.put(root, appMap); 00086 } 00087 request.setAttribute("applications", map); 00088 forward(request, response, "/list.jsp"); 00089 } 00090 00091 final HashMap makeMap(WebApplication app) { 00092 HashMap map = new HashMap(); 00093 map.put("display-name", app.getDisplayName()); 00094 map.put("root-path", app.getRootPath()); 00095 //map.put("session-timeout", new Integer(app.getSessionTimeout())); 00096 //map.put("error-page", app.getErrorPage()); 00097 //map.put("init-parameters", getInitParameters(app)); 00098 //map.put("attributes", getAttributes(app)); 00099 //map.put("servlets", getServlets(app)); 00100 //map.put("sessions", getSessions(app)); 00101 return map; 00102 } 00103 00104 final HashMap getInitParameters(WebApplication app) { 00105 HashMap map = new HashMap(); 00106 Enumeration e = app.getInitParameterNames(); 00107 while (e.hasMoreElements()) { 00108 String name = e.nextElement().toString(); 00109 String param = app.getInitParameter(name); 00110 map.put(name, param); 00111 } 00112 return map; 00113 } 00114 00115 final HashMap getAttributes(WebApplication app) { 00116 HashMap map = new HashMap(); 00117 Enumeration e = app.getAttributeNames(); 00118 while (e.hasMoreElements()) { 00119 String name = e.nextElement().toString(); 00120 Object attr = app.getAttribute(name); 00121 map.put(name, attr); 00122 } 00123 return map; 00124 } 00125 00126 // final HashMap getServlets(WebApplication app) { 00127 // HashMap map = new HashMap(); 00128 // return map; 00129 // } 00130 00131 // final HashMap getSessions(WebApplication app) { 00132 // HashMap map = new HashMap(); 00133 // return map; 00134 // } 00135 00136 public void forward(HttpServletRequest request, 00137 HttpServletResponse response, 00138 String page) 00139 throws ServletException, IOException 00140 { 00141 ServletContext context = config.getServletContext(); 00142 RequestDispatcher rd = context.getRequestDispatcher(page); 00143 rd.forward(request, response); 00144 } 00145 00146 }