01: package org.cougaar.demo.mandelbrot.v1;
02:
03: import java.io.IOException;
04: import java.io.OutputStream;
05: import javax.servlet.ServletException;
06: import javax.servlet.http.HttpServletRequest;
07: import javax.servlet.http.HttpServletResponse;
08: import org.cougaar.core.servlet.ComponentServlet;
09: import org.cougaar.demo.mandelbrot.util.Arguments;
10: import org.cougaar.demo.mandelbrot.util.FractalMath;
11: import org.cougaar.demo.mandelbrot.util.ImageOutput;
12:
13: /**
14: * This servlet is a simple inlined implementation of the Mandelbrot image
15: * generator.
16: * <p>
17: * We'll assume that the {@link org.cougaar.demo.mandelbrot.FrontPageServlet}
18: * has set and validated our URL parameters and adjusted the x/y values to
19: * preserve our width/height aspect ratio.
20: */
21: public class MandelbrotServlet extends ComponentServlet {
22: protected void doGet(HttpServletRequest req, HttpServletResponse res)
23: throws ServletException, IOException {
24:
25: // parse the URL parameters
26: Arguments args = new Arguments(req.getParameterMap());
27:
28: // compute the mandelbrot data
29: byte[] data = FractalMath.mandelbrot(args.getInt("width"), args
30: .getInt("height"), args.getDouble("x_min"), args
31: .getDouble("x_max"), args.getDouble("y_min"), args
32: .getDouble("y_max"));
33:
34: // write the data as a JPEG
35: res.setContentType("image/jpeg");
36: OutputStream out = res.getOutputStream();
37: ImageOutput.writeJPG(args.getInt("width"), args
38: .getInt("height"), data, out);
39: out.close();
40: }
41: }
|