    001    package 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
    024    import org.apache.ecs.ConcreteElement;
    025
    026    import org.apache.turbine.pipeline.PipelineData;
    027    import org.apache.turbine.util.InputFilterUtils;
    028    import org.apache.turbine.util.RunData;
    029
    030    /**
    031     * This is the base class which defines the Screen modules.
    032     *
    033     * @author <a href="mailto:mbryson@mont.mindspring.com">Dave Bryson</a>
    034     * @author <a href="mailto:hps@intermeta.de">Henning P. Schmiedehausen</a>
    035     * @author <a href="mailto:peter@courcoux.biz">Peter Courcoux</a>
    036     * @version $Id: Screen.java 717934 2008-11-15 21:48:47Z tv $
    037     */
    038    public abstract class Screen
    039        extends Assembler
    040    {
    041        /** Prefix for screen related classes and templates */
    042        public static final String PREFIX = "screens";
    043
    044        /** Property for the size of the screen cache if caching is on */
    045        public static final String CACHE_SIZE_KEY = "screen.cache.size";
    046
    047        /** The default size for the screen cache */
    048        public static final int CACHE_SIZE_DEFAULT = 50;
    049
    050        /** Represents Screen Objects */
    051        public static final String NAME = "screen";
    052
    053        /**
    054         * @see org.apache.turbine.modules.Assembler#getPrefix()
    055         */
    056        public String getPrefix()
    057        {
    058            return PREFIX;
    059        }
    060
    061        /**
    062         * A subclass must override this method to build itself.
    063         * Subclasses override this method to store the screen in RunData
    064         * or to write the screen to the output stream referenced in
    065         * RunData.
    066         * Should revert to abstract when RunData has gone.
    067         * @param data Turbine information.
    068         * @exception Exception a generic exception.
    069         */
    070        protected ConcreteElement doBuild(PipelineData pipelineData)
    071            throws Exception
    072        {
    073            RunData data = getRunData(pipelineData);
    074            return doBuild(data);
    075        }
    076
    077        /**
    078         * Subclasses can override this method to add additional
    079         * functionality.  This method is protected to force clients to
    080         * use ScreenLoader to build a Screen.
    081         *
    082         * @param pipelineData Turbine information.
    083         * @exception Exception a generic exception.
    084         */
    085        protected ConcreteElement build(PipelineData pipelineData)
    086            throws Exception
    087        {
    088            return doBuild(pipelineData);
    089        }
    090
    091        /**
    092         * If the Layout has not been defined by the Screen then set the
    093         * layout to be "DefaultLayout".  The Screen object can also
    094         * override this method to provide intelligent determination of
    095         * the Layout to execute.  You can also define that logic here as
    096         * well if you want it to apply on a global scale.  For example,
    097         * if you wanted to allow someone to define Layout "preferences"
    098         * where they could dynamically change the Layout for the entire
    099         * site.  The information for the request is passed in with the
    100         * PipelineData object.
    101         *
    102         * @param pipelineData Turbine information.
    103         * @return A String with the Layout.
    104         */
    105        public String getLayout(PipelineData pipelineData)
    106        {
    107            RunData data = getRunData(pipelineData);
    108            return data.getLayout();
    109        }
    110
    111        /**
    112         * Set the layout for a Screen.
    113         *
    114         * @param data Turbine information.
    115         * @param layout The layout name.
    116         */
    117        public void setLayout(PipelineData pipelineData, String layout)
    118        {
    119            RunData data = getRunData(pipelineData);
    120            data.setLayout(layout);
    121        }
    122
    123        /**
    124         * A subclass must override this method to build itself.
    125         * Subclasses override this method to store the screen in RunData
    126         * or to write the screen to the output stream referenced in
    127         * RunData.
    128         * @deprecated Use PipelineData version instead.
    129         * @param data Turbine information.
    130         * @exception Exception a generic exception.
    131         */
    132        protected abstract ConcreteElement doBuild(RunData data)
    133            throws Exception;
    134
    135        /**
    136         * Subclasses can override this method to add additional
    137         * functionality.  This method is protected to force clients to
    138         * use ScreenLoader to build a Screen.
    139         * @deprecated Use PipelineData version instead.
    140         *
    141         * @param data Turbine information.
    142         * @exception Exception a generic exception.
    143         */
    144        protected ConcreteElement build(RunData data)
    145            throws Exception
    146        {
    147            return doBuild(data);
    148        }
    149
    150        /**
    151         * If the Layout has not been defined by the Screen then set the
    152         * layout to be "DefaultLayout".  The Screen object can also
    153         * override this method to provide intelligent determination of
    154         * the Layout to execute.  You can also define that logic here as
    155         * well if you want it to apply on a global scale.  For example,
    156         * if you wanted to allow someone to define Layout "preferences"
    157         * where they could dynamically change the Layout for the entire
    158         * site.  The information for the request is passed in with the
    159         * RunData object.
    160         * @deprecated Use PipelineData version instead.
    161         *
    162         * @param data Turbine information.
    163         * @return A String with the Layout.
    164         */
    165        public String getLayout(RunData data)
    166        {
    167            return data.getLayout();
    168        }
    169
    170        /**
    171         * Set the layout for a Screen.
    172         *
    173         * @deprecated Use PipelineData version instead.
    174         * @param data Turbine information.
    175         * @param layout The layout name.
    176         */
    177        public void setLayout(RunData data, String layout)
    178        {
    179            data.setLayout(layout);
    180        }
    181
    182        /**
    183         * This function can/should be used in any screen that will output
    184         * User entered text.  This will help prevent users from entering
    185         * html (<SCRIPT>) tags that will get executed by the browser.
    186         *
    187         * @param s The string to prepare.
    188         * @return A string with the input already prepared.
    189         * @deprecated Use InputFilterUtils.prepareText(String s)
    190         */
    191        public static String prepareText(String s)
    192        {
    193            return InputFilterUtils.prepareText(s);
    194        }
    195
    196        /**
    197         * This function can/should be used in any screen that will output
    198         * User entered text.  This will help prevent users from entering
    199         * html (<SCRIPT>) tags that will get executed by the browser.
    200         *
    201         * @param s The string to prepare.
    202         * @return A string with the input already prepared.
    203         * @deprecated Use InputFilterUtils.prepareTextMinimum(String s)
    204         */
    205        public static String prepareTextMinimum(String s)
    206        {
    207            return InputFilterUtils.prepareTextMinimum(s);
    208        }
    209    }