Coverage Report - org.apache.turbine.util.template.TemplateNavigation
 
Classes in this File Line Coverage Branch Coverage Complexity
TemplateNavigation
19%
5/26
0%
0/6
3
 
 1  
 package org.apache.turbine.util.template;
 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.commons.logging.Log;
 25  
 import org.apache.commons.logging.LogFactory;
 26  
 import org.apache.turbine.modules.NavigationLoader;
 27  
 import org.apache.turbine.services.TurbineServices;
 28  
 import org.apache.turbine.services.template.TemplateService;
 29  
 import org.apache.turbine.util.RunData;
 30  
 
 31  
 /**
 32  
  * Returns output of a Navigation module.  An instance of this is
 33  
  * placed in the WebMacro context by the WebMacroSiteLayout.  This
 34  
  * allows template authors to set the navigation template they'd like
 35  
  * to place in their templates.  Here's how it's used in a
 36  
  * template:
 37  
  *
 38  
  * <p><code>
 39  
  * $navigation.setTemplate("admin_navigation.wm")
 40  
  * </code>
 41  
  *
 42  
  * @author <a href="mbryson@mont.mindspring.com">Dave Bryson</a>
 43  
  * @version $Id: TemplateNavigation.java 1723699 2016-01-08 11:29:21Z tv $
 44  
  */
 45  
 public class TemplateNavigation
 46  
 {
 47  
     /** Logging */
 48  1
     private static Log log = LogFactory.getLog(TemplateNavigation.class);
 49  
 
 50  
     /* The RunData object. */
 51  
     private RunData data;
 52  
 
 53  
     /* The name of the navigation template. */
 54  2
     private String template = null;
 55  
 
 56  
     /**
 57  
      * Constructor
 58  
      *
 59  
      * @param data A Turbine RunData object.
 60  
      */
 61  
     public TemplateNavigation(RunData data)
 62  2
     {
 63  2
         this.data = data;
 64  2
     }
 65  
 
 66  
     /**
 67  
      * Set the template.
 68  
      *
 69  
      * @param template A String with the name of the navigation
 70  
      * template.
 71  
      * @return A TemplateNavigation (self).
 72  
      */
 73  
     public TemplateNavigation setTemplate(String template)
 74  
     {
 75  0
         log.debug("setTemplate(" + template + ")");
 76  0
         this.template = template;
 77  0
         return this;
 78  
     }
 79  
 
 80  
     /**
 81  
      * Builds the output of the navigation template.
 82  
      *
 83  
      * @return A String.
 84  
      */
 85  
     @Override
 86  
     public String toString()
 87  
     {
 88  0
         String module = null;
 89  0
         String returnValue = null;
 90  
 
 91  
         try
 92  
         {
 93  0
             if (template == null)
 94  
             {
 95  0
                 returnValue = "Navigation Template is null (Might be unset)";
 96  0
                 throw new Exception(returnValue);
 97  
             }
 98  
 
 99  0
             data.getTemplateInfo().setNavigationTemplate(template);
 100  0
             TemplateService templateService = (TemplateService)TurbineServices.getInstance().getService(TemplateService.SERVICE_NAME);
 101  0
             module = templateService.getNavigationName(template);
 102  
 
 103  0
             if (module == null)
 104  
             {
 105  0
                 returnValue = "Template Service returned null for Navigation Template " + template;
 106  0
                 throw new Exception(returnValue);
 107  
             }
 108  
 
 109  0
             returnValue = NavigationLoader.getInstance().eval(data, module);
 110  
         }
 111  0
         catch (Exception e)
 112  
         {
 113  0
             if (returnValue == null)
 114  
             {
 115  0
                 returnValue = "Error processing navigation template: "
 116  
                         + template + ", using module: " + module;
 117  
             }
 118  0
             log.error(returnValue, e);
 119  0
         }
 120  
 
 121  0
         return returnValue;
 122  
     }
 123  
 }