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.ecs.ConcreteElement;
25  
26  import org.apache.turbine.pipeline.PipelineData;
27  import org.apache.turbine.util.InputFilterUtils;
28  import org.apache.turbine.util.RunData;
29  
30  /**
31   * This is the base class which defines the Screen modules.
32   *
33   * @author <a href="mailto:mbryson@mont.mindspring.com">Dave Bryson</a>
34   * @author <a href="mailto:hps@intermeta.de">Henning P. Schmiedehausen</a>
35   * @author <a href="mailto:peter@courcoux.biz">Peter Courcoux</a>
36   * @version $Id: Screen.java 717934 2008-11-15 21:48:47Z tv $
37   */
38  public abstract class Screen
39      extends Assembler
40  {
41      /** Prefix for screen related classes and templates */
42      public static final String PREFIX = "screens";
43      
44      /** Property for the size of the screen cache if caching is on */
45      public static final String CACHE_SIZE_KEY = "screen.cache.size";
46      
47      /** The default size for the screen cache */
48      public static final int CACHE_SIZE_DEFAULT = 50;
49  
50      /** Represents Screen Objects */
51      public static final String NAME = "screen";
52  
53      /**
54       * @see org.apache.turbine.modules.Assembler#getPrefix()
55       */
56      public String getPrefix()
57      {
58          return PREFIX;
59      }
60  
61      /**
62       * A subclass must override this method to build itself.
63       * Subclasses override this method to store the screen in RunData
64       * or to write the screen to the output stream referenced in
65       * RunData.
66       * Should revert to abstract when RunData has gone.
67       * @param data Turbine information.
68       * @exception Exception a generic exception.
69       */
70      protected ConcreteElement doBuild(PipelineData pipelineData)
71          throws Exception
72      {
73          RunData data = getRunData(pipelineData);
74          return doBuild(data);
75      }
76  
77      /**
78       * Subclasses can override this method to add additional
79       * functionality.  This method is protected to force clients to
80       * use ScreenLoader to build a Screen.
81       *
82       * @param pipelineData Turbine information.
83       * @exception Exception a generic exception.
84       */
85      protected ConcreteElement build(PipelineData pipelineData)
86          throws Exception
87      {
88          return doBuild(pipelineData);
89      }
90  
91      /**
92       * If the Layout has not been defined by the Screen then set the
93       * layout to be "DefaultLayout".  The Screen object can also
94       * override this method to provide intelligent determination of
95       * the Layout to execute.  You can also define that logic here as
96       * well if you want it to apply on a global scale.  For example,
97       * if you wanted to allow someone to define Layout "preferences"
98       * where they could dynamically change the Layout for the entire
99       * 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 }