001: package com.quadcap.app.dbimage;
002:
003: /* Copyright 2000 - 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.util.HashMap;
042:
043: import javax.servlet.ServletConfig;
044: import javax.servlet.ServletException;
045:
046: import javax.servlet.http.HttpServlet;
047: import javax.servlet.http.HttpServletRequest;
048: import javax.servlet.http.HttpServletResponse;
049:
050: /**
051: * The controller servlet for the image database application. All incoming
052: * requests get dispatched from here to an Action instance.
053: *
054: * @author Stan Bailes
055: */
056: public class DbImageController extends HttpServlet {
057: HashMap actions = new HashMap();
058:
059: static HashMap actionClasses = new HashMap();
060: static {
061: actionClasses
062: .put("/load", "com.quadcap.app.dbimage.ActionLoad");
063: }
064:
065: public void init(ServletConfig config) throws ServletException {
066: super .init(config);
067:
068: }
069:
070: public void doPost(HttpServletRequest request,
071: HttpServletResponse response) throws ServletException {
072: doGet(request, response);
073: }
074:
075: public void doGet(HttpServletRequest request,
076: HttpServletResponse response) throws ServletException {
077: try {
078: Action action = getAction(request);
079: if (action == null) {
080: response.sendError(HttpServletResponse.SC_NOT_FOUND,
081: "Not Found");
082: } else {
083: try {
084: action.service(request, response);
085: } catch (ServletException e) {
086: throw e;
087: }
088: }
089: } catch (Throwable t) {
090: throw new ServletException(t);
091: }
092: }
093:
094: Action getAction(HttpServletRequest request) throws Exception {
095: String s = request.getPathInfo();
096: Action action = (Action) actions.get(s);
097: if (action == null) {
098: String actionClass = (String) actionClasses.get(s);
099: if (actionClass != null) {
100: Class c = Class.forName(actionClass);
101: action = (Action) c.newInstance();
102: action.init(getServletConfig());
103: actions.put(s, action);
104: }
105: }
106: return action;
107: }
108: }
|