%line | %branch | |||||||||
---|---|---|---|---|---|---|---|---|---|---|
org.apache.turbine.services.template.mapper.ScreenTemplateMapper |
|
|
1 | package org.apache.turbine.services.template.mapper; |
|
2 | ||
3 | /* |
|
4 | * Copyright 2001-2005 The Apache Software Foundation. |
|
5 | * |
|
6 | * Licensed under the Apache License, Version 2.0 (the "License") |
|
7 | * you may not use this file except in compliance with the License. |
|
8 | * You may obtain a copy of the License at |
|
9 | * |
|
10 | * http://www.apache.org/licenses/LICENSE-2.0 |
|
11 | * |
|
12 | * Unless required by applicable law or agreed to in writing, software |
|
13 | * distributed under the License is distributed on an "AS IS" BASIS, |
|
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
15 | * See the License for the specific language governing permissions and |
|
16 | * limitations under the License. |
|
17 | */ |
|
18 | ||
19 | import org.apache.commons.lang.StringUtils; |
|
20 | ||
21 | import org.apache.turbine.services.template.TemplateEngineService; |
|
22 | import org.apache.turbine.services.template.TemplateService; |
|
23 | import org.apache.turbine.services.template.TurbineTemplate; |
|
24 | ||
25 | /** |
|
26 | * This is a pretty simple mapper which returns template pathes for |
|
27 | * a supplied template name. This path can be used by the TemplateEngine |
|
28 | * to access a certain resource to actually render the template. |
|
29 | * |
|
30 | * @author <a href="mailto:hps@intermeta.de">Henning P. Schmiedehausen</a> |
|
31 | * @version $Id: ScreenTemplateMapper.java 264148 2005-08-29 14:21:04Z henning $ |
|
32 | */ |
|
33 | ||
34 | public class ScreenTemplateMapper |
|
35 | extends BaseTemplateMapper |
|
36 | implements Mapper |
|
37 | { |
|
38 | /** |
|
39 | * Default C'tor. If you use this C'tor, you must use |
|
40 | * the bean setter to set the various properties needed for |
|
41 | * this mapper before first usage. |
|
42 | */ |
|
43 | public ScreenTemplateMapper() |
|
44 | 44 | { |
45 | 44 | } |
46 | ||
47 | /** |
|
48 | * Check, whether the provided name exists. Returns null |
|
49 | * if the screen does not exist. |
|
50 | * |
|
51 | * @param template The template name. |
|
52 | * @return The matching screen name. |
|
53 | */ |
|
54 | public String doMapping(String template) |
|
55 | { |
|
56 | 14 | String [] components = StringUtils.split(template, String.valueOf(TemplateService.TEMPLATE_PARTS_SEPARATOR)); |
57 | ||
58 | // Last element decides, which template Service to use... |
|
59 | 14 | TemplateEngineService tes = |
60 | TurbineTemplate.getTemplateEngineService(components[components.length - 1]); |
|
61 | ||
62 | 14 | String templatePackage = StringUtils.join(components, String.valueOf(separator)); |
63 | ||
64 | // But the Templating service must look for the name with prefix |
|
65 | 14 | StringBuffer testPath = new StringBuffer(); |
66 | 14 | if (StringUtils.isNotEmpty(prefix)) |
67 | { |
|
68 | 14 | testPath.append(prefix); |
69 | 14 | testPath.append(separator); |
70 | } |
|
71 | 14 | testPath.append(templatePackage); |
72 | ||
73 | 14 | return (tes != null && tes.templateExists(testPath.toString())) |
74 | ? templatePackage |
|
75 | : null; |
|
76 | } |
|
77 | } |
|
78 | ||
79 | ||
80 | ||
81 |
This report is generated by jcoverage, Maven and Maven JCoverage Plugin. |