00001
package com.quadcap.app.qws;
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
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
00059
00060
00061
00062
00063
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
00096
00097
00098
00099
00100
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
00127
00128
00129
00130
00131
00132
00133
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 }