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 base class 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: Screen.java 1709648 2015-10-20 17:08:10Z tv $ 034 */ 035public abstract class Screen 036 extends Assembler 037{ 038 /** Prefix for screen related classes and templates */ 039 public static final String PREFIX = "screens"; 040 041 /** Property for the size of the screen cache if caching is on */ 042 public static final String CACHE_SIZE_KEY = "screen.cache.size"; 043 044 /** The default size for the screen cache */ 045 public static final int CACHE_SIZE_DEFAULT = 50; 046 047 /** Represents Screen Objects */ 048 public static final String NAME = "screen"; 049 050 /** 051 * @see org.apache.turbine.modules.Assembler#getPrefix() 052 */ 053 @Override 054 public String getPrefix() 055 { 056 return PREFIX; 057 } 058 059 /** 060 * A subclass must override this method to build itself. 061 * Subclasses override this method to store the screen in RunData 062 * or to write the screen to the output stream referenced in 063 * RunData. 064 * @param pipelineData Turbine information. 065 * @return the content of the screen 066 * @exception Exception a generic exception. 067 */ 068 protected abstract String doBuild(PipelineData pipelineData) throws Exception; 069 070 /** 071 * Subclasses can override this method to add additional 072 * functionality. This method is protected to force clients to 073 * use ScreenLoader to build a Screen. 074 * 075 * @param pipelineData Turbine information. 076 * @return the content of the screen 077 * @exception Exception a generic exception. 078 */ 079 protected String build(PipelineData pipelineData) 080 throws Exception 081 { 082 return doBuild(pipelineData); 083 } 084 085 /** 086 * If the Layout has not been defined by the Screen then set the 087 * layout to be "DefaultLayout". The Screen object can also 088 * override this method to provide intelligent determination of 089 * the Layout to execute. You can also define that logic here as 090 * well if you want it to apply on a global scale. For example, 091 * if you wanted to allow someone to define Layout "preferences" 092 * where they could dynamically change the Layout for the entire 093 * site. The information for the request is passed in with the 094 * PipelineData object. 095 * 096 * @param pipelineData Turbine information. 097 * @return A String with the Layout. 098 */ 099 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}