001package org.apache.turbine.modules;
002
003
004/*
005 * Licensed to the Apache Software Foundation (ASF) under one
006 * or more contributor license agreements.  See the NOTICE file
007 * distributed with this work for additional information
008 * regarding copyright ownership.  The ASF licenses this file
009 * to you under the Apache License, Version 2.0 (the
010 * "License"); you may not use this file except in compliance
011 * with the License.  You may obtain a copy of the License at
012 *
013 *   http://www.apache.org/licenses/LICENSE-2.0
014 *
015 * Unless required by applicable law or agreed to in writing,
016 * software distributed under the License is distributed on an
017 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
018 * KIND, either express or implied.  See the License for the
019 * specific language governing permissions and limitations
020 * under the License.
021 */
022
023
024import org.apache.turbine.pipeline.PipelineData;
025import org.apache.turbine.util.RunData;
026
027/**
028 * This is the interface which defines the Screen modules.
029 *
030 * @author <a href="mailto:mbryson@mont.mindspring.com">Dave Bryson</a>
031 * @author <a href="mailto:hps@intermeta.de">Henning P. Schmiedehausen</a>
032 * @author <a href="mailto:peter@courcoux.biz">Peter Courcoux</a>
033 * @version $Id$
034 */
035@FunctionalInterface
036public interface Screen extends Assembler
037{
038    /** Prefix for screen related classes and templates */
039    String PREFIX = "screens";
040
041    /** Property for the size of the screen cache if caching is on */
042    String CACHE_SIZE_KEY = "screen.cache.size";
043
044    /** The default size for the screen cache */
045    int CACHE_SIZE_DEFAULT = 50;
046
047    /** Represents Screen Objects */
048    String NAME = "screen";
049
050    /**
051     * A subclass must implement this method to build itself.
052     * Subclasses override this method to store the screen in RunData
053     * or to write the screen to the output stream referenced in
054     * RunData.
055     * @param pipelineData Turbine information.
056     * @return the content of the screen
057     * @throws Exception a generic exception.
058     */
059    String doBuild(PipelineData pipelineData) throws Exception;
060
061    /**
062     * Subclasses can override this method to add additional
063     * functionality.
064     *
065     * @param pipelineData Turbine information.
066     * @return the content of the screen
067     * @throws Exception a generic exception.
068     */
069    default String build(PipelineData pipelineData)
070        throws Exception
071    {
072        return doBuild(pipelineData);
073    }
074
075    /**
076     * If the Layout has not been defined by the Screen then set the
077     * layout to be "DefaultLayout".  The Screen object can also
078     * override this method to provide intelligent determination of
079     * the Layout to execute.  You can also define that logic here as
080     * well if you want it to apply on a global scale.  For example,
081     * if you wanted to allow someone to define Layout "preferences"
082     * where they could dynamically change the Layout for the entire
083     * site.  The information for the request is passed in with the
084     * PipelineData object.
085     *
086     * @param pipelineData Turbine information.
087     * @return A String with the Layout.
088     */
089    default String getLayout(PipelineData pipelineData)
090    {
091        RunData data = pipelineData.getRunData();
092        return data.getLayout();
093    }
094
095    /**
096     * Set the layout for a Screen.
097     *
098     * @param pipelineData Turbine information.
099     * @param layout The layout name.
100     */
101    default void setLayout(PipelineData pipelineData, String layout)
102    {
103        RunData data = pipelineData.getRunData();
104        data.setLayout(layout);
105    }
106}