Coverage Report - org.apache.turbine.services.template.mapper.BaseTemplateMapper
 
Classes in this File Line Coverage Branch Coverage Complexity
BaseTemplateMapper
82%
19/23
66%
4/6
1,75
 
 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.lang3.StringUtils;
 25  
 import org.apache.turbine.services.TurbineServices;
 26  
 import org.apache.turbine.services.template.TemplateService;
 27  
 
 28  
 /**
 29  
  * This is a mapper like the BaseMapper but it returns its
 30  
  * results with the extension of the template names passed or (if no
 31  
  * extension is passed), the default extension.
 32  
  *
 33  
  * @author <a href="mailto:hps@intermeta.de">Henning P. Schmiedehausen</a>
 34  
  * @version $Id: BaseTemplateMapper.java 1844792 2018-10-24 21:47:54Z painter $
 35  
  */
 36  
 
 37  
 public abstract class BaseTemplateMapper
 38  
     extends BaseMapper
 39  
 {
 40  
     /** A prefix which is used to separate the various template types (screen, layouts, navigation) */
 41  396
     protected String prefix = "";
 42  
 
 43  
     /**
 44  
      * Default C'tor. If you use this C'tor, you must use
 45  
      * the bean setter to set the various properties needed for
 46  
      * this mapper before first usage.
 47  
      */
 48  
     public BaseTemplateMapper()
 49  
     {
 50  396
         super();
 51  396
     }
 52  
 
 53  
     /**
 54  
      * Get the Prefix value.
 55  
      * @return the Prefix value.
 56  
      */
 57  
     public String getPrefix()
 58  
     {
 59  0
         return prefix;
 60  
     }
 61  
 
 62  
     /**
 63  
      * Set the Prefix value.
 64  
      * @param prefix The new Prefix value.
 65  
      */
 66  
     public void setPrefix(String prefix)
 67  
     {
 68  396
         this.prefix = prefix;
 69  396
     }
 70  
 
 71  
     /**
 72  
      * Returns the default name for the passed Template.
 73  
      * If the template has no extension, the default extension
 74  
      * is added.
 75  
      * If the template is empty, the default template is
 76  
      * returned.
 77  
      *
 78  
      * @param template The template name.
 79  
      *
 80  
      * @return the mapped default name for the template.
 81  
      */
 82  
     @Override
 83  
     public String getDefaultName(String template)
 84  
     {
 85  90
         String res = super.getDefaultName(template);
 86  
 
 87  
         // Does the Template Name component have an extension?
 88  90
         String [] components
 89  90
             = StringUtils.split(res, String.valueOf(separator));
 90  
 
 91  90
         if (components[components.length -1 ].indexOf(TemplateService.EXTENSION_SEPARATOR) < 0)
 92  
         {
 93  6
             StringBuilder resBuf = new StringBuilder();
 94  6
             resBuf.append(res);
 95  6
             String [] templateComponents = StringUtils.split(template, String.valueOf(TemplateService.TEMPLATE_PARTS_SEPARATOR));
 96  
 
 97  
             // Only the extension of the Template name component is interesting...
 98  6
             int dotIndex = templateComponents[templateComponents.length -1].lastIndexOf(TemplateService.EXTENSION_SEPARATOR);
 99  6
             if (dotIndex < 0)
 100  
             {
 101  6
                 TemplateService templateService = (TemplateService)TurbineServices.getInstance().getService(TemplateService.SERVICE_NAME);
 102  
 
 103  6
                 if (StringUtils.isNotEmpty(templateService.getDefaultExtension()))
 104  
                 {
 105  0
                     resBuf.append(TemplateService.EXTENSION_SEPARATOR);
 106  0
                     resBuf.append(templateService.getDefaultExtension());
 107  
                 }
 108  6
             }
 109  
             else
 110  
             {
 111  0
                 resBuf.append(templateComponents[templateComponents.length -1].substring(dotIndex));
 112  
             }
 113  6
             res = resBuf.toString();
 114  
         }
 115  90
         return res;
 116  
     }
 117  
 }