KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > turbine > services > template > mapper > DirectMapper


1 package org.apache.turbine.services.template.mapper;
2
3 /*
4  * Copyright 2001-2004 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.TemplateService;
22
23 /**
24  * The most primitive mapper. It is used for the page objects in the
25  * Template service. It never caches and simply returns what is given to it.
26  *
27  * @author <a HREF="mailto:hps@intermeta.de">Henning P. Schmiedehausen</a>
28  * @version $Id: DirectMapper.java,v 1.1.2.2 2004/05/20 03:06:48 seade Exp $
29  */

30 public class DirectMapper
31     extends BaseMapper
32     implements Mapper
33 {
34     /**
35      * Default C'tor. If you use this C'tor, you must use
36      * the bean setter to set the various properties needed for
37      * this mapper before first usage.
38      */

39     public DirectMapper()
40     {
41     }
42
43     /**
44      * Strip off a possible extension, replace all "," with "."
45      *
46      * about,directions,Driving.vm --> about.directions.Driving
47      *
48      * @param template The template name.
49      * @return A class name for the given template.
50      */

51     public String JavaDoc doMapping(String JavaDoc template)
52     {
53         String JavaDoc [] components
54             = StringUtils.split(template, String.valueOf(TemplateService.TEMPLATE_PARTS_SEPARATOR));
55
56         String JavaDoc className = components[components.length - 1];
57
58         // Strip off a possible Extension
59
int dotIndex = className.lastIndexOf(TemplateService.EXTENSION_SEPARATOR);
60         className = (dotIndex < 0) ? className : className.substring(0, dotIndex);
61         components[components.length -1] = className;
62
63         // Class names are always separated by "."
64
return StringUtils.join(components, String.valueOf(separator));
65     }
66 }
67
Popular Tags