01: /*
02: * Copyright Javelin Software, All rights reserved.
03: */
04:
05: package com.javelin.swinglets;
06:
07: import java.util.*;
08: import java.io.*;
09: import java.awt.*;
10:
11: import javax.servlet.*;
12: import javax.servlet.http.*;
13:
14: /**
15: * Factory to provide SImages by their name. The user must pass the URL: -
16: * http://hostname/servlets/com.javelin.servlets.ImageServlet?image=name
17: * <p>
18: * This class currently returns all images as "image/gifs".
19: *
20: * @author Robin Sharp
21: */
22:
23: public class ImageServlet extends HttpServlet {
24: public void doGet(HttpServletRequest request,
25: HttpServletResponse response) throws ServletException,
26: IOException {
27: try {
28: //System.out.println( SConstants.IMAGE_NAME + "=" + request.getParameter( SConstants.IMAGE_NAME ) );
29: SImage image = ImageManager.getManager().get(
30: request.getParameter(SConstants.IMAGE_NAME));
31:
32: if (image == null) {
33: response
34: .sendError(
35: response.SC_INTERNAL_SERVER_ERROR,
36: "No image defined called "
37: + request
38: .getParameter(SConstants.IMAGE_NAME));
39: }
40:
41: response.setContentType("image/gif");
42:
43: image.paint(response.getOutputStream());
44:
45: } catch (Exception e) {
46: response.sendError(response.SC_INTERNAL_SERVER_ERROR, e
47: .getMessage());
48: } finally {
49: response.getOutputStream().close();
50: }
51: }
52:
53: }
|