View Javadoc

    1   package org.apache.turbine.modules;
    2
    3
    4   /*
    5    * Licensed to the Apache Software Foundation (ASF) under one
    6    * or more contributor license agreements.  See the NOTICE file
    7    * distributed with this work for additional information
    8    * regarding copyright ownership.  The ASF licenses this file
    9    * to you under the Apache License, Version 2.0 (the
    10   * "License"); you may not use this file except in compliance
    11   * with the License.  You may obtain a copy of the License at
    12   *
    13   *   http://www.apache.org/licenses/LICENSE-2.0
    14   *
    15   * Unless required by applicable law or agreed to in writing,
    16   * software distributed under the License is distributed on an
    17   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    18   * KIND, either express or implied.  See the License for the
    19   * specific language governing permissions and limitations
    20   * under the License.
    21   */
    22
    23
    24  import org.apache.turbine.pipeline.PipelineData;
    25  import org.apache.turbine.util.RunData;
    26
    27  /**
    28   * This is the base class which defines the Screen modules.
    29   *
    30   * @author <a href="mailto:mbryson@mont.mindspring.com">Dave Bryson</a>
    31   * @author <a href="mailto:hps@intermeta.de">Henning P. Schmiedehausen</a>
    32   * @author <a href="mailto:peter@courcoux.biz">Peter Courcoux</a>
    33   * @version $Id: Screen.java 1709648 2015-10-20 17:08:10Z tv $
    34   */
    35  public abstract class Screen
    36      extends Assembler
    37  {
    38      /** Prefix for screen related classes and templates */
    39      public static final String PREFIX = "screens";
    40
    41      /** Property for the size of the screen cache if caching is on */
    42      public static final String CACHE_SIZE_KEY = "screen.cache.size";
    43
    44      /** The default size for the screen cache */
    45      public static final int CACHE_SIZE_DEFAULT = 50;
    46
    47      /** Represents Screen Objects */
    48      public static final String NAME = "screen";
    49
    50      /**
    51       * @see org.apache.turbine.modules.Assembler#getPrefix()
    52       */
    53      @Override
    54      public String getPrefix()
    55      {
    56          return PREFIX;
    57      }
    58
    59      /**
    60       * A subclass must override this method to build itself.
    61       * Subclasses override this method to store the screen in RunData
    62       * or to write the screen to the output stream referenced in
    63       * RunData.
    64       * @param pipelineData Turbine information.
    65       * @return the content of the screen
    66       * @exception Exception a generic exception.
    67       */
    68      protected abstract String doBuild(PipelineData pipelineData) throws Exception;
    69
    70      /**
    71       * Subclasses can override this method to add additional
    72       * functionality.  This method is protected to force clients to
    73       * use ScreenLoader to build a Screen.
    74       *
    75       * @param pipelineData Turbine information.
    76       * @return the content of the screen
    77       * @exception Exception a generic exception.
    78       */
    79      protected String build(PipelineData pipelineData)
    80          throws Exception
    81      {
    82          return doBuild(pipelineData);
    83      }
    84
    85      /**
    86       * If the Layout has not been defined by the Screen then set the
    87       * layout to be "DefaultLayout".  The Screen object can also
    88       * override this method to provide intelligent determination of
    89       * the Layout to execute.  You can also define that logic here as
    90       * well if you want it to apply on a global scale.  For example,
    91       * if you wanted to allow someone to define Layout "preferences"
    92       * where they could dynamically change the Layout for the entire
    93       * site.  The information for the request is passed in with the
    94       * PipelineData object.
    95       *
    96       * @param pipelineData Turbine information.
    97       * @return A String with the Layout.
    98       */
    99      public String getLayout(PipelineData pipelineData)
    100     {
    101         RunData data = getRunData(pipelineData);
    102         return data.getLayout();
    103     }
    104
    105     /**
    106      * Set the layout for a Screen.
    107      *
    108      * @param pipelineData Turbine information.
    109      * @param layout The layout name.
    110      */
    111     public void setLayout(PipelineData pipelineData, String layout)
    112     {
    113         RunData data = getRunData(pipelineData);
    114         data.setLayout(layout);
    115     }
    116 }