View Javadoc
1 package org.apache.turbine.modules.screens; 2 3 /* ==================================================================== 4 * The Apache Software License, Version 1.1 5 * 6 * Copyright (c) 2001 The Apache Software Foundation. All rights 7 * reserved. 8 * 9 * Redistribution and use in source and binary forms, with or without 10 * modification, are permitted provided that the following conditions 11 * are met: 12 * 13 * 1. Redistributions of source code must retain the above copyright 14 * notice, this list of conditions and the following disclaimer. 15 * 16 * 2. Redistributions in binary form must reproduce the above copyright 17 * notice, this list of conditions and the following disclaimer in 18 * the documentation and/or other materials provided with the 19 * distribution. 20 * 21 * 3. The end-user documentation included with the redistribution, 22 * if any, must include the following acknowledgment: 23 * "This product includes software developed by the 24 * Apache Software Foundation (http://www.apache.org/)." 25 * Alternately, this acknowledgment may appear in the software itself, 26 * if and wherever such third-party acknowledgments normally appear. 27 * 28 * 4. The names "Apache" and "Apache Software Foundation" and 29 * "Apache Turbine" must not be used to endorse or promote products 30 * derived from this software without prior written permission. For 31 * written permission, please contact apache@apache.org. 32 * 33 * 5. Products derived from this software may not be called "Apache", 34 * "Apache Turbine", nor may "Apache" appear in their name, without 35 * prior written permission of the Apache Software Foundation. 36 * 37 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED 38 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 39 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 40 * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR 41 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 42 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 43 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 44 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 45 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 46 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 47 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 48 * SUCH DAMAGE. 49 * ==================================================================== 50 * 51 * This software consists of voluntary contributions made by many 52 * individuals on behalf of the Apache Software Foundation. For more 53 * information on the Apache Software Foundation, please see 54 * <http://www.apache.org/>;. 55 */ 56 57 // Turbine/Village/ECS Imports 58 import org.apache.ecs.ConcreteElement; 59 import org.apache.ecs.StringElement; 60 import org.apache.turbine.services.freemarker.FreeMarkerService; 61 import org.apache.turbine.services.TurbineServices; 62 import org.apache.turbine.services.template.TurbineTemplate; 63 import org.apache.turbine.util.RunData; 64 65 // FreeMarker Stuff 66 import freemarker.template.SimpleHash; 67 68 69 /*** 70 * Sample FreeMarker Screen. Screens which use FreeMarker templates 71 * can extend this screen. 72 * 73 * For templates which require no database content, this screen may be 74 * adequate. In other cases, screens can override the 75 * doBuildFreeMarker method to add more data to the context. 76 * 77 * @author <a href="mailto:john.mcnally@clearink.com">John D. McNally</a> 78 * @version $Id: BaseFreeMarkerScreen.java,v 1.1.1.1 2001/08/16 05:08:37 jvanzyl Exp $ 79 * @deprecated you should use velocity 80 */ 81 public class BaseFreeMarkerScreen extends TemplateScreen 82 { 83 /*** 84 * Screens extending this class should overide this method to 85 * perform any particular business logic and add information to 86 * the context. 87 * 88 * @param data, the Rundata object 89 * @param context, the context into which the extra data is to be added. 90 * @exception Exception, a generic exception. 91 */ 92 protected void doBuildTemplate(RunData data, SimpleHash context) 93 throws Exception 94 { 95 } 96 97 98 /*** 99 * Needs to be implemented to make TemplateScreen like us. The 100 * actual method that you should override is the one with the 101 * context in the parameter list. 102 * 103 * @param data, the Rundata object 104 * @exception Exception, a generic exception. 105 */ 106 protected void doBuildTemplate( RunData data ) 107 throws Exception 108 { 109 doBuildTemplate( data, getContext(data) ); 110 } 111 112 /*** 113 * Return the model needed by FreeMarker. This is where 114 * information needed by the template should be placed. 115 * 116 * @param data, the Rundata object 117 * @return SimpleHash 118 */ 119 protected SimpleHash getContext(RunData data) 120 { 121 // Attempt to get it from the TemplateInfo first. If it 122 // doesn't exist, create it and then stuff it into the 123 // TemplateInfo. 124 SimpleHash context = (SimpleHash)data.getTemplateInfo() 125 .getTemplateContext(FreeMarkerService.CONTEXT); 126 if (context == null) 127 { 128 FreeMarkerService fm = (FreeMarkerService)TurbineServices 129 .getInstance().getService(FreeMarkerService.SERVICE_NAME); 130 context = fm.getContext(); 131 data.getTemplateInfo() 132 .setTemplateContext(FreeMarkerService.CONTEXT, context); 133 } 134 return context; 135 } 136 137 /*** 138 * Build the template. 139 * 140 * @param data Turbine information. 141 * @return A ConcreteElement. 142 * @exception Exception, a generic exception. 143 */ 144 public ConcreteElement buildTemplate(RunData data) 145 throws Exception 146 { 147 SimpleHash context = getContext(data); 148 String templateName = TurbineTemplate.getScreenTemplateName( 149 data.getTemplateInfo().getScreenTemplate() ); 150 151 // Template service adds the leading slash, but make it sure. 152 if ((templateName.length() > 0) && 153 (templateName.charAt(0) != '/')) 154 { 155 templateName = '/' + templateName; 156 } 157 158 FreeMarkerService fm = (FreeMarkerService) 159 TurbineServices.getInstance() 160 .getService(FreeMarkerService.SERVICE_NAME); 161 162 StringElement output = new StringElement(); 163 output.setFilterState(false); 164 output.addElement( 165 fm.handleRequest(context, "screens" + templateName, true)); 166 return output; 167 } 168 }

This page was automatically generated by Maven