001: package com.quadcap.app.qws;
002:
003: /* Copyright 1999 - 2003 Quadcap Software. All rights reserved.
004: *
005: * This software is distributed under the Quadcap Free Software License.
006: * This software may be used or modified for any purpose, personal or
007: * commercial. Open Source redistributions are permitted. Commercial
008: * redistribution of larger works derived from, or works which bundle
009: * this software requires a "Commercial Redistribution License"; see
010: * http://www.quadcap.com/purchase.
011: *
012: * Redistributions qualify as "Open Source" under one of the following terms:
013: *
014: * Redistributions are made at no charge beyond the reasonable cost of
015: * materials and delivery.
016: *
017: * Redistributions are accompanied by a copy of the Source Code or by an
018: * irrevocable offer to provide a copy of the Source Code for up to three
019: * years at the cost of materials and delivery. Such redistributions
020: * must allow further use, modification, and redistribution of the Source
021: * Code under substantially the same terms as this license.
022: *
023: * Redistributions of source code must retain the copyright notices as they
024: * appear in each source code file, these license terms, and the
025: * disclaimer/limitation of liability set forth as paragraph 6 below.
026: *
027: * Redistributions in binary form must reproduce this Copyright Notice,
028: * these license terms, and the disclaimer/limitation of liability set
029: * forth as paragraph 6 below, in the documentation and/or other materials
030: * provided with the distribution.
031: *
032: * The Software is provided on an "AS IS" basis. No warranty is
033: * provided that the Software is free of defects, or fit for a
034: * particular purpose.
035: *
036: * Limitation of Liability. Quadcap Software shall not be liable
037: * for any damages suffered by the Licensee or any third party resulting
038: * from use of the Software.
039: */
040:
041: import java.io.IOException;
042:
043: import java.util.Enumeration;
044: import java.util.HashMap;
045:
046: import javax.servlet.RequestDispatcher;
047: import javax.servlet.ServletConfig;
048: import javax.servlet.ServletContext;
049: import javax.servlet.ServletException;
050:
051: import javax.servlet.http.HttpServletRequest;
052: import javax.servlet.http.HttpServletResponse;
053:
054: import com.quadcap.http.server22.WebApplication;
055: import com.quadcap.http.server22.WebServer;
056:
057: /**
058: * Implement the 'list' action, which sets the "applications" request
059: * attribute to be a HashMap of 'context' -> 'application'. Each
060: * 'application' object is a HashMap containing the interesting properties
061: * of that application.
062: *
063: * @author Stan Bailes
064: */
065: public class ActionList implements Action {
066: ServletConfig config;
067: WebServer server;
068:
069: public void init(ServletConfig config) {
070: this .config = config;
071: ServletContext context = config.getServletContext();
072: this .server = (WebServer) context.getAttribute("server");
073: }
074:
075: public void service(HttpServletRequest request,
076: HttpServletResponse response) throws Exception {
077: HashMap map = new HashMap();
078: Enumeration names = server.getContextRoots();
079: while (names.hasMoreElements()) {
080: String root = names.nextElement().toString();
081: WebApplication app = server.getContextForRoot(root);
082: HashMap appMap = makeMap(app);
083: map.put(root, appMap);
084: }
085: request.setAttribute("applications", map);
086: forward(request, response, "/list.jsp");
087: }
088:
089: final HashMap makeMap(WebApplication app) {
090: HashMap map = new HashMap();
091: map.put("display-name", app.getDisplayName());
092: map.put("root-path", app.getRootPath());
093: //map.put("session-timeout", new Integer(app.getSessionTimeout()));
094: //map.put("error-page", app.getErrorPage());
095: //map.put("init-parameters", getInitParameters(app));
096: //map.put("attributes", getAttributes(app));
097: //map.put("servlets", getServlets(app));
098: //map.put("sessions", getSessions(app));
099: return map;
100: }
101:
102: final HashMap getInitParameters(WebApplication app) {
103: HashMap map = new HashMap();
104: Enumeration e = app.getInitParameterNames();
105: while (e.hasMoreElements()) {
106: String name = e.nextElement().toString();
107: String param = app.getInitParameter(name);
108: map.put(name, param);
109: }
110: return map;
111: }
112:
113: final HashMap getAttributes(WebApplication app) {
114: HashMap map = new HashMap();
115: Enumeration e = app.getAttributeNames();
116: while (e.hasMoreElements()) {
117: String name = e.nextElement().toString();
118: Object attr = app.getAttribute(name);
119: map.put(name, attr);
120: }
121: return map;
122: }
123:
124: // final HashMap getServlets(WebApplication app) {
125: // HashMap map = new HashMap();
126: // return map;
127: // }
128:
129: // final HashMap getSessions(WebApplication app) {
130: // HashMap map = new HashMap();
131: // return map;
132: // }
133:
134: public void forward(HttpServletRequest request,
135: HttpServletResponse response, String page)
136: throws ServletException, IOException {
137: ServletContext context = config.getServletContext();
138: RequestDispatcher rd = context.getRequestDispatcher(page);
139: rd.forward(request, response);
140: }
141:
142: }
|