View Javadoc

    1   package org.apache.turbine.modules.screens;
    2
    3   /*
    4    * Licensed to the Apache Software Foundation (ASF) under one
    5    * or more contributor license agreements.  See the NOTICE file
    6    * distributed with this work for additional information
    7    * regarding copyright ownership.  The ASF licenses this file
    8    * to you under the Apache License, Version 2.0 (the
    9    * "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
    23  // Turbine stuff.
    24
    25  import org.apache.ecs.ConcreteElement;
    26  import org.apache.turbine.modules.Screen;
    27  import org.apache.turbine.pipeline.PipelineData;
    28  import org.apache.turbine.util.RunData;
    29
    30  /**
    31   * Base class for writing Screens that output binary data.  This class
    32   * is provided as a helper class for those who want to write Screens
    33   * that output raw binary data.  For example, it may be extended into
    34   * a Screen that outputs a SVG file or a SWF (Flash Player format)
    35   * movie.  The only thing one has to do is to implement the two
    36   * methods <code>getContentType(RunData data)</code> and
    37   * <code>doOutput(RunData data)</code> (see below).
    38   *
    39   * <p> You migth want to take a look at the ImageServer screen class
    40   * contained in the TDK.<br>
    41   *
    42   * @author <a href="mailto:rkoenig@chez.com">Regis Koenig</a>
    43   * @author <a href="mailto:peter@courcoux.biz">Peter Courcoux</a>
    44   * @version $Id: RawScreen.java 938645 2010-04-27 20:57:51Z tv $
    45   */
    46  public abstract class RawScreen extends Screen
    47  {
    48      /**
    49       * Build the Screen.  This method actually makes a call to the
    50       * doOutput() method in order to generate the Screen content.
    51       *
    52       * @deprecated Use PipelineData version instead.
    53       * @param data Turbine information.
    54       * @return A ConcreteElement.
    55       * @exception Exception, a generic exception.
    56       */
    57      protected final ConcreteElement doBuild(RunData data)
    58              throws Exception
    59      {
    60          data.getResponse().setContentType(getContentType(data));
    61          data.declareDirectResponse();
    62          doOutput(data);
    63          return null;
    64      }
    65
    66      /**
    67       * Build the Screen.  This method actually makes a call to the
    68       * doOutput() method in order to generate the Screen content.
    69       *
    70       * @param data Turbine information.
    71       * @return A ConcreteElement.
    72       * @exception Exception, a generic exception.
    73       */
    74      protected final ConcreteElement doBuild(PipelineData pipelineData)
    75              throws Exception
    76      {
    77          RunData data = getRunData(pipelineData);
    78          return doBuild(data);
    79      }
    80
    81
    82      /**
    83       * Set the content type.  This method should be overidden to
    84       * actually set the real content-type header of the output.
    85       *
    86       * @deprecated Use PipelineData version instead.
    87       * @param data Turbine information.
    88       * @return A String with the content type.
    89       */
    90      protected abstract String getContentType(RunData data);
    91
    92      /**
    93       * Set the content type.  This method should be overidden to
    94       * actually set the real content-type header of the output.
    95       *
    96       * @param data Turbine information.
    97       * @return A String with the content type.
    98       */
    99      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 }