01: package org.apache.turbine.modules.screens;
02:
03: /*
04: * Licensed to the Apache Software Foundation (ASF) under one
05: * or more contributor license agreements. See the NOTICE file
06: * distributed with this work for additional information
07: * regarding copyright ownership. The ASF licenses this file
08: * to you under the Apache License, Version 2.0 (the
09: * "License"); you may not use this file except in compliance
10: * with the License. You may obtain a copy of the License at
11: *
12: * http://www.apache.org/licenses/LICENSE-2.0
13: *
14: * Unless required by applicable law or agreed to in writing,
15: * software distributed under the License is distributed on an
16: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17: * KIND, either express or implied. See the License for the
18: * specific language governing permissions and limitations
19: * under the License.
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: * 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: data.getResponse().setContentType(getContentType(data));
53: data.declareDirectResponse();
54: doOutput(data);
55: return null;
56: }
57:
58: /**
59: * Set the content type. This method should be overidden to
60: * actually set the real content-type header of the output.
61: *
62: * @param data Turbine information.
63: * @return A String with the content type.
64: */
65: protected abstract String getContentType(RunData data);
66:
67: /**
68: * Actually output the dynamic content. The OutputStream can be
69: * accessed like this: <pre>OutputStream out =
70: * data.getResponse().getOutputStream();</pre>.
71: *
72: * @param data Turbine information.
73: * @exception Exception, a generic exception.
74: */
75: protected abstract void doOutput(RunData data) throws Exception;
76:
77: /**
78: * The layout must be set to null.
79: *
80: * @param data Turbine information.
81: * @return A null String.
82: */
83: public final String getLayout(RunData data) {
84: return null;
85: }
86: }
|