##### Coverage Report - org.apache.turbine.services.template.mapper.BaseTemplateMapper

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