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