Coverage Report - org.apache.turbine.services.pull.TurbinePull
 
Classes in this File Line Coverage Branch Coverage Complexity
TurbinePull
20%
3/15
N/A
1,222
 
 1  
 package org.apache.turbine.services.pull;
 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.turbine.pipeline.PipelineData;
 25  
 import org.apache.turbine.services.TurbineServices;
 26  
 import org.apache.turbine.util.RunData;
 27  
 import org.apache.velocity.context.Context;
 28  
 
 29  
 /**
 30  
  * This is a Facade class for PullService.
 31  
  *
 32  
  * This class provides static methods that call related methods of the
 33  
  * implementation of the PullService used by the System, according to
 34  
  * the settings in TurbineResources.
 35  
  *
 36  
  * @author <a href="mailto:jvanzyl@periapt.com">Jason van Zyl</a>
 37  
  * @author <a href="mailto:dlr@finemaltcoding.com">Daniel Rall</a>
 38  
  * @author <a href="mailto:hps@intermeta.de">Henning P. Schmiedehausen</a>
 39  
  * @author <a href="mailto:peter@courcoux.biz">Peter Courcoux</a>
 40  
  * @version $Id: TurbinePull.java 1078552 2011-03-06 19:58:46Z tv $
 41  
  */
 42  0
 public abstract class TurbinePull
 43  
 {
 44  
     /**
 45  
      * Utility method for accessing the service
 46  
      * implementation
 47  
      *
 48  
      * @return a PullService implementation instance
 49  
      */
 50  
     public static PullService getService()
 51  
     {
 52  120
         return (PullService) TurbineServices
 53  
                 .getInstance().getService(PullService.SERVICE_NAME);
 54  
     }
 55  
 
 56  
     /**
 57  
      * Get the context containing global tools that will be
 58  
      * use as part of the Turbine Pull Model.
 59  
      *
 60  
      * @return A Context object which contains the
 61  
      *         Global Tool instances.
 62  
      */
 63  
     public static final Context getGlobalContext()
 64  
     {
 65  0
         return getService().getGlobalContext();
 66  
     }
 67  
 
 68  
     /**
 69  
      * Checks whether this service has been registered.  This is
 70  
      * required by the TurbineVelocityService so it can determine
 71  
      * whether to attempt to place the ToolBox in the context.
 72  
      * <p>
 73  
      * So users can use Turbine with templates in the traditional
 74  
      * manner. If the Pull Service is not listed in
 75  
      * <code>TurbineResources.props</code>, or no tools are specified
 76  
      * the TurbineVelocityService will behave in its traditional
 77  
      * manner.
 78  
      */
 79  
     public static final boolean isRegistered()
 80  
     {
 81  62
         return TurbineServices.getInstance()
 82  
                 .isRegistered(PullService.SERVICE_NAME);
 83  
     }
 84  
 
 85  
     /**
 86  
      * Return the absolute path of the resources directory
 87  
      * used by application tools.
 88  
      *
 89  
      * @return A directory path in the file system or null.
 90  
      */
 91  
     public static final String getAbsolutePathToResourcesDirectory()
 92  
     {
 93  0
         return getService().getAbsolutePathToResourcesDirectory();
 94  
     }
 95  
 
 96  
     /**
 97  
      * Return the resources directory. This is relative
 98  
      * to the webapp context.
 99  
      *
 100  
      * @return A directory path to the resources directory relative to the webapp root or null.
 101  
      */
 102  
     public static final String getResourcesDirectory()
 103  
     {
 104  46
         return getService().getResourcesDirectory();
 105  
     }
 106  
 
 107  
     /**
 108  
      * Populate the given context with all request, session
 109  
      * and persistent scope tools (it is assumed that the context
 110  
      * already wraps the global context, and thus already contains
 111  
      * the global tools).
 112  
      *
 113  
      * @param context a Velocity Context to populate
 114  
      * @param data a RunData object for request specific data
 115  
      */
 116  
     public static void populateContext(Context context, PipelineData pipelineData)
 117  
     {
 118  0
         getService().populateContext(context, pipelineData);
 119  0
     }
 120  
 
 121  
     /**
 122  
      * Populate the given context with all request, session
 123  
      * and persistent scope tools (it is assumed that the context
 124  
      * already wraps the global context, and thus already contains
 125  
      * the global tools).
 126  
      *
 127  
      * @param context a Velocity Context to populate
 128  
      * @param data a RunData object for request specific data
 129  
      */
 130  
     public static void populateContext(Context context, RunData data)
 131  
     {
 132  0
         getService().populateContext(context, data);
 133  0
     }
 134  
 
 135  
     /**
 136  
      * Release tool instances from the given context to the
 137  
      * object pool
 138  
      *
 139  
      * @param context a Velocity Context to release tools from
 140  
      */
 141  
     public static void releaseTools(Context context)
 142  
     {
 143  0
         getService().releaseTools(context);
 144  0
     }
 145  
 
 146  
     /**
 147  
      * Helper method that allows you to easily get a tool
 148  
      * from a Context. Essentially, it just does the cast
 149  
      * to an Application tool for you.
 150  
      *
 151  
      * @param context a Velocity Context to get tools from
 152  
      * @param name the name of the tool to get
 153  
      * @return ApplicationTool null if no tool could be found
 154  
      */
 155  
     public static ApplicationTool getTool(Context context,
 156  
                                           String name)
 157  
     {
 158  
         try
 159  
         {
 160  0
             return (ApplicationTool) context.get(name);
 161  
         }
 162  0
         catch (Exception e)
 163  
         {
 164  
             // ignore
 165  
         }
 166  0
         return null;
 167  
     }
 168  
 }