View Javadoc
1 package org.apache.turbine.services.pull; 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 import org.apache.velocity.context.Context; 58 59 import org.apache.turbine.services.TurbineServices; 60 import org.apache.turbine.util.RunData; 61 62 /*** 63 * This is a Facade class for PullService. 64 * 65 * This class provides static methods that call related methods of the 66 * implementation of the PullService used by the System, according to 67 * the settings in TurbineResources. 68 * 69 * @author <a href="mailto:jvanzyl@periapt.com">Jason van Zyl</a> 70 * @author <a href="mailto:dlr@finemaltcoding.com">Daniel Rall</a> 71 * @version $Id: TurbinePull.java,v 1.1.1.1 2001/08/16 05:09:10 jvanzyl Exp $ 72 */ 73 public abstract class TurbinePull 74 { 75 /*** 76 * Utility method for accessing the service 77 * implementation 78 * 79 * @return a PullService implementation instance 80 */ 81 protected static PullService getService() 82 { 83 return (PullService)TurbineServices 84 .getInstance().getService(PullService.SERVICE_NAME); 85 } 86 87 /*** 88 * Get the ToolBox that was created by 89 * Pull Service during early initialization. This 90 * method is used by the various template services 91 * that are available for use in Turbine, but 92 * specifically the TurbineVelocityService. 93 */ 94 public static final Context getGlobalContext() 95 { 96 return getService().getGlobalContext(); 97 } 98 99 /*** 100 * Checks whether this service has been registered. This is 101 * required by the TurbineVelocityService so it can determine 102 * whether to attempt to place the ToolBox in the context. 103 * <p> 104 * So users can use Turbine with templates in the traditional 105 * manner. If the Pull Service is not listed in 106 * <code>TurbineResources.props</code>, or no tools are specified 107 * the TurbineVelocityService will behave in its traditional 108 * manner. 109 */ 110 public static final boolean isRegistered() 111 { 112 return TurbineServices.getInstance() 113 .isRegistered(PullService.SERVICE_NAME); 114 } 115 116 /*** 117 * Return the absolute path of resources directory 118 * where tools store resource information. 119 */ 120 public static final String getAbsolutePathToResourcesDirectory() 121 { 122 return getService().getAbsolutePathToResourcesDirectory(); 123 } 124 125 /*** 126 * Return the resources directory. This is relative 127 * to the webapp context. 128 */ 129 public static final String getResourcesDirectory() 130 { 131 return getService().getResourcesDirectory(); 132 } 133 134 /*** 135 * Populate the given context with all request, session 136 * and persistent scope tools (it is assumed that the context 137 * already wraps the global context, and thus already contains 138 * the global tools). 139 * 140 * @param context a Velocity Context to populate 141 * @param data a RunData object for request specific data 142 */ 143 public static void populateContext(Context context, RunData data) 144 { 145 getService().populateContext(context, data); 146 } 147 148 /*** 149 * Refresh the global tools. This is necessary 150 * for development work where tools depend 151 * on configuration information. The configuration 152 * information is typically cached after initialization 153 * but during development you might want the tool 154 * to refresh itself on each request. 155 * <p> 156 * If there are objects that don't implement 157 * application ApplicationTool then they won't 158 * be refreshed. 159 */ 160 public static final void refreshGlobalTools() 161 { 162 getService().refreshGlobalTools(); 163 } 164 165 /*** 166 * Shoud we refresh the tools 167 * on each request. For development purposes. 168 */ 169 public static final boolean refreshToolsPerRequest() 170 { 171 return getService().refreshToolsPerRequest(); 172 } 173 174 /*** 175 * Release tool instances from the given context to the 176 * object pool 177 * 178 * @param context a Velocity Context to release tools from 179 */ 180 public static void releaseTools(Context context) 181 { 182 getService().releaseTools(context); 183 } 184 185 /*** 186 * Helper method that allows you to easily get a tool 187 * from a Context. Essentially, it just does the cast 188 * to an Application tool for you. 189 * 190 * @param context a Velocity Context to get tools from 191 * @param name the name of the tool to get 192 * @return ApplicationTool null if no tool could be found 193 */ 194 public static ApplicationTool getTool(Context context, 195 String name) 196 { 197 try 198 { 199 return (ApplicationTool) context.get(name); 200 } 201 catch (Exception e) 202 { 203 } 204 return null; 205 } 206 }

This page was automatically generated by Maven