    001    package org.apache.turbine.modules.screens;
    002
    003    /*
    004     * Licensed to the Apache Software Foundation (ASF) under one
    005     * or more contributor license agreements.  See the NOTICE file
    006     * distributed with this work for additional information
    007     * regarding copyright ownership.  The ASF licenses this file
    008     * to you under the Apache License, Version 2.0 (the
    009     * "License"); you may not use this file except in compliance
    010     * with the License.  You may obtain a copy of the License at
    011     *
    012     *   http://www.apache.org/licenses/LICENSE-2.0
    013     *
    014     * Unless required by applicable law or agreed to in writing,
    015     * software distributed under the License is distributed on an
    016     * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    017     * KIND, either express or implied.  See the License for the
    018     * specific language governing permissions and limitations
    019     * under the License.
    020     */
    021
    022
    023    // Turbine stuff.
    024
    025    import org.apache.ecs.ConcreteElement;
    026    import org.apache.turbine.modules.Screen;
    027    import org.apache.turbine.pipeline.PipelineData;
    028    import org.apache.turbine.util.RunData;
    029
    030    /**
    031     * Base class for writing Screens that output binary data.  This class
    032     * is provided as a helper class for those who want to write Screens
    033     * that output raw binary data.  For example, it may be extended into
    034     * a Screen that outputs a SVG file or a SWF (Flash Player format)
    035     * movie.  The only thing one has to do is to implement the two
    036     * methods <code>getContentType(RunData data)</code> and
    037     * <code>doOutput(RunData data)</code> (see below).
    038     *
    039     * <p> You migth want to take a look at the ImageServer screen class
    040     * contained in the TDK.<br>
    041     *
    042     * @author <a href="mailto:rkoenig@chez.com">Regis Koenig</a>
    043     * @author <a href="mailto:peter@courcoux.biz">Peter Courcoux</a>
    044     * @version $Id: RawScreen.java 938645 2010-04-27 20:57:51Z tv $
    045     */
    046    public abstract class RawScreen extends Screen
    047    {
    048        /**
    049         * Build the Screen.  This method actually makes a call to the
    050         * doOutput() method in order to generate the Screen content.
    051         *
    052         * @deprecated Use PipelineData version instead.
    053         * @param data Turbine information.
    054         * @return A ConcreteElement.
    055         * @exception Exception, a generic exception.
    056         */
    057        protected final ConcreteElement doBuild(RunData data)
    058                throws Exception
    059        {
    060            data.getResponse().setContentType(getContentType(data));
    061            data.declareDirectResponse();
    062            doOutput(data);
    063            return null;
    064        }
    065
    066        /**
    067         * Build the Screen.  This method actually makes a call to the
    068         * doOutput() method in order to generate the Screen content.
    069         *
    070         * @param data Turbine information.
    071         * @return A ConcreteElement.
    072         * @exception Exception, a generic exception.
    073         */
    074        protected final ConcreteElement doBuild(PipelineData pipelineData)
    075                throws Exception
    076        {
    077            RunData data = getRunData(pipelineData);
    078            return doBuild(data);
    079        }
    080
    081
    082        /**
    083         * Set the content type.  This method should be overidden to
    084         * actually set the real content-type header of the output.
    085         *
    086         * @deprecated Use PipelineData version instead.
    087         * @param data Turbine information.
    088         * @return A String with the content type.
    089         */
    090        protected abstract String getContentType(RunData data);
    091
    092        /**
    093         * Set the content type.  This method should be overidden to
    094         * actually set the real content-type header of the output.
    095         *
    096         * @param data Turbine information.
    097         * @return A String with the content type.
    098         */
    099        protected String getContentType(PipelineData pipelineData)
    100        {
    101            RunData data = getRunData(pipelineData);
    102            return getContentType(data);
    103        }
    104
    105
    106        /**
    107         * Actually output the dynamic content.  The OutputStream can be
    108         * accessed like this: <pre>OutputStream out =
    109         * data.getResponse().getOutputStream();</pre>.
    110         *
    111         * @deprecated Use PipelineData version instead.
    112         * @param data Turbine information.
    113         * @exception Exception, a generic exception.
    114         */
    115        protected abstract void doOutput(RunData data)
    116                throws Exception;
    117
    118        /**
    119         * Actually output the dynamic content.  The OutputStream can be
    120         * accessed like this: <pre>OutputStream out =
    121         * data.getResponse().getOutputStream();</pre>.
    122         *
    123         * @param data Turbine information.
    124         * @exception Exception, a generic exception.
    125         */
    126        protected void doOutput(PipelineData pipelineData)
    127                throws Exception
    128        {
    129            RunData data = getRunData(pipelineData);
    130            doOutput(data);
    131        }
    132
    133
    134        /**
    135         * The layout must be set to null.
    136         *
    137         * @deprecated Use PipelineData version instead.
    138         * @param data Turbine information.
    139         * @return A null String.
    140         */
    141        public final String getLayout(RunData data)
    142        {
    143            return null;
    144        }
    145
    146        /**
    147         * The layout must be set to null.
    148         *
    149         * @param data Turbine information.
    150         * @return A null String.
    151         */
    152        public final String getLayout(PipelineData pipelineData)
    153        {
    154            return null;
    155        }
    156
    157
    158
    159    }