1 package com.quadcap.app.qws; 2 3 40 41 import java.io.IOException ; 42 43 import java.util.Enumeration ; 44 import java.util.HashMap ; 45 46 import javax.servlet.RequestDispatcher ; 47 import javax.servlet.ServletConfig ; 48 import javax.servlet.ServletContext ; 49 import javax.servlet.ServletException ; 50 51 import javax.servlet.http.HttpServletRequest ; 52 import javax.servlet.http.HttpServletResponse ; 53 54 import com.quadcap.http.server22.WebApplication; 55 import com.quadcap.http.server22.WebServer; 56 57 65 public class ActionList implements Action { 66 ServletConfig config; 67 WebServer server; 68 69 public void init(ServletConfig config) { 70 this.config = config; 71 ServletContext context = config.getServletContext(); 72 this.server = (WebServer)context.getAttribute("server"); 73 } 74 75 public void service(HttpServletRequest request, 76 HttpServletResponse response) 77 throws Exception 78 { 79 HashMap map = new HashMap (); 80 Enumeration names = server.getContextRoots(); 81 while (names.hasMoreElements()) { 82 String root = names.nextElement().toString(); 83 WebApplication app = server.getContextForRoot(root); 84 HashMap appMap = makeMap(app); 85 map.put(root, appMap); 86 } 87 request.setAttribute("applications", map); 88 forward(request, response, "/list.jsp"); 89 } 90 91 final HashMap makeMap(WebApplication app) { 92 HashMap map = new HashMap (); 93 map.put("display-name", app.getDisplayName()); 94 map.put("root-path", app.getRootPath()); 95 return map; 102 } 103 104 final HashMap getInitParameters(WebApplication app) { 105 HashMap map = new HashMap (); 106 Enumeration e = app.getInitParameterNames(); 107 while (e.hasMoreElements()) { 108 String name = e.nextElement().toString(); 109 String param = app.getInitParameter(name); 110 map.put(name, param); 111 } 112 return map; 113 } 114 115 final HashMap getAttributes(WebApplication app) { 116 HashMap map = new HashMap (); 117 Enumeration e = app.getAttributeNames(); 118 while (e.hasMoreElements()) { 119 String name = e.nextElement().toString(); 120 Object attr = app.getAttribute(name); 121 map.put(name, attr); 122 } 123 return map; 124 } 125 126 131 136 public void forward(HttpServletRequest request, 137 HttpServletResponse response, 138 String page) 139 throws ServletException , IOException 140 { 141 ServletContext context = config.getServletContext(); 142 RequestDispatcher rd = context.getRequestDispatcher(page); 143 rd.forward(request, response); 144 } 145 146 } 147 | Popular Tags |