Coverage Report - org.apache.turbine.services.template.mapper.ScreenTemplateMapper
 
Classes in this File Line Coverage Branch Coverage Complexity
ScreenTemplateMapper
100%
12/12
66%
4/6
2,5
 
 1  
 package org.apache.turbine.services.template.mapper;
 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.lang.StringUtils;
 25  
 import org.apache.turbine.services.TurbineServices;
 26  
 import org.apache.turbine.services.template.TemplateEngineService;
 27  
 import org.apache.turbine.services.template.TemplateService;
 28  
 
 29  
 /**
 30  
  * This is a pretty simple mapper which returns template pathes for
 31  
  * a supplied template name. This path can be used by the TemplateEngine
 32  
  * to access a certain resource to actually render the template.
 33  
  *
 34  
  * @author <a href="mailto:hps@intermeta.de">Henning P. Schmiedehausen</a>
 35  
  * @version $Id: ScreenTemplateMapper.java 1723699 2016-01-08 11:29:21Z tv $
 36  
  */
 37  
 
 38  
 public class ScreenTemplateMapper
 39  
     extends BaseTemplateMapper
 40  
     implements Mapper
 41  
 {
 42  
     /**
 43  
      * Default C'tor. If you use this C'tor, you must use
 44  
      * the bean setter to set the various properties needed for
 45  
      * this mapper before first usage.
 46  
      */
 47  
     public ScreenTemplateMapper()
 48  
     {
 49  39
         super();
 50  39
     }
 51  
 
 52  
     /**
 53  
      * Check, whether the provided name exists. Returns null
 54  
      * if the screen does not exist.
 55  
      *
 56  
      * @param template The template name.
 57  
      * @return The matching screen name.
 58  
      */
 59  
     @Override
 60  
     public String doMapping(String template)
 61  
     {
 62  9
         String [] components = StringUtils.split(template, String.valueOf(TemplateService.TEMPLATE_PARTS_SEPARATOR));
 63  
 
 64  
         // Last element decides, which template Service to use...
 65  9
         TemplateService templateService = (TemplateService)TurbineServices.getInstance().getService(TemplateService.SERVICE_NAME);
 66  9
         TemplateEngineService tes = templateService.getTemplateEngineService(components[components.length - 1]);
 67  
 
 68  9
         String templatePackage = StringUtils.join(components, String.valueOf(separator));
 69  
 
 70  
         // But the Templating service must look for the name with prefix
 71  9
         StringBuilder testPath = new StringBuilder();
 72  9
         if (StringUtils.isNotEmpty(prefix))
 73  
         {
 74  9
             testPath.append(prefix);
 75  9
             testPath.append(separator);
 76  
         }
 77  9
         testPath.append(templatePackage);
 78  
 
 79  9
         return (tes != null && tes.templateExists(testPath.toString()))
 80  
             ? templatePackage
 81  
             : null;
 82  
     }
 83  
 }
 84  
 
 85  
 
 86  
 
 87