001package org.apache.turbine.modules.layouts; 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.commons.lang3.StringUtils; 025import org.apache.turbine.TurbineConstants; 026import org.apache.turbine.annotation.TurbineLoader; 027import org.apache.turbine.modules.Screen; 028import org.apache.turbine.modules.ScreenLoader; 029import org.apache.turbine.pipeline.PipelineData; 030import org.apache.turbine.util.template.TemplateNavigation; 031import org.apache.velocity.context.Context; 032 033/** 034 * This Layout module allows Velocity templates to be used as layouts. 035 * Since dynamic content is supposed to be primarily located in 036 * screens and navigations there should be relatively few reasons to 037 * subclass this Layout. 038 * 039 * To get the same functionality as with VelocityECSLayout, you can use two 040 * supplied VelocityMacros, TurbineHtmlHead and TurbineHtmlBodyAttributes 041 * in your templates. These are used to put HtmlPageAttributes into a page 042 * before rendering. 043 * 044 * Use these macros should be used in the Layout template like this: 045 * 046 * ... set things like style sheets, scripts here. 047 * <html> 048 * #TurbineHtmlHead() 049 * <body #TurbineHtmlBodyAttributes() > 050 * .... your body information 051 * </body> 052 * </html> 053 * 054 * As the layout template is rendered _after_ the screen template, you 055 * can of course, add information to the $page tool in your screen template. 056 * This will be added correctly to the <head>...</head> and 057 * <body> tags. 058 * 059 * @author <a href="mailto:john.mcnally@clearink.com">John D. McNally</a> 060 * @author <a href="mailto:mbryson@mont.mindspring.com">Dave Bryson</a> 061 * @author <a href="mailto:hps@intermeta.de">Henning P. Schmiedehausen</a> 062 * @author <a href="mailto:peter@courcoux.biz">Peter Courcoux</a> 063 * @version $Id$ 064 */ 065public class VelocityOnlyLayout extends VelocityLayout 066{ 067 /** Injected loader instance */ 068 @TurbineLoader( Screen.class ) 069 private ScreenLoader screenLoader; 070 071 /** 072 * @see org.apache.turbine.modules.layouts.VelocityLayout#populateContext(org.apache.turbine.pipeline.PipelineData, org.apache.velocity.context.Context) 073 */ 074 @Override 075 protected void populateContext(PipelineData pipelineData, Context context) throws Exception 076 { 077 String screenName = pipelineData.getRunData().getScreen(); 078 079 log.debug("Loading Screen {}", screenName); 080 081 // First, generate the screen and put it in the context so 082 // we can grab it the layout template. 083 String results = screenLoader.eval(pipelineData, screenName); 084 String returnValue = StringUtils.defaultIfEmpty(results, StringUtils.EMPTY); 085 086 // variable for the screen in the layout template 087 context.put(TurbineConstants.SCREEN_PLACEHOLDER, returnValue); 088 089 // variable to reference the navigation screen in the layout template 090 context.put(TurbineConstants.NAVIGATION_PLACEHOLDER, 091 new TemplateNavigation(pipelineData)); 092 } 093}