1 package org.apache.turbine.modules.screens;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import org.apache.ecs.ConcreteElement;
23 import org.apache.turbine.modules.Screen;
24 import org.apache.turbine.util.RunData;
25
26 /***
27 * Base class for writing Screens that output binary data. This class
28 * is provided as a helper class for those who want to write Screens
29 * that output raw binary data. For example, it may be extended into
30 * a Screen that outputs a SVG file or a SWF (Flash Player format)
31 * movie. The only thing one has to do is to implement the two
32 * methods <code>getContentType(RunData data)</code> and
33 * <code>doOutput(RunData data)</code> (see below).
34 *
35 * <p> You migth want to take a look at the ImageServer screen class
36 * contained in the TDK.<br>
37 *
38 * @author <a href="mailto:rkoenig@chez.com">Regis Koenig</a>
39 * @version $Id: RawScreen.java 534527 2007-05-02 16:10:59Z tv $
40 */
41 public abstract class RawScreen extends Screen
42 {
43 /***
44 * Build the Screen. This method actually makes a call to the
45 * doOutput() method in order to generate the Screen content.
46 *
47 * @param data Turbine information.
48 * @return A ConcreteElement.
49 * @exception Exception, a generic exception.
50 */
51 protected final ConcreteElement doBuild(RunData data)
52 throws Exception
53 {
54 data.getResponse().setContentType(getContentType(data));
55 data.declareDirectResponse();
56 doOutput(data);
57 return null;
58 }
59
60 /***
61 * Set the content type. This method should be overidden to
62 * actually set the real content-type header of the output.
63 *
64 * @param data Turbine information.
65 * @return A String with the content type.
66 */
67 protected abstract String getContentType(RunData data);
68
69 /***
70 * Actually output the dynamic content. The OutputStream can be
71 * accessed like this: <pre>OutputStream out =
72 * data.getResponse().getOutputStream();</pre>.
73 *
74 * @param data Turbine information.
75 * @exception Exception, a generic exception.
76 */
77 protected abstract void doOutput(RunData data)
78 throws Exception;
79
80 /***
81 * The layout must be set to null.
82 *
83 * @param data Turbine information.
84 * @return A null String.
85 */
86 public final String getLayout(RunData data)
87 {
88 return null;
89 }
90 }