001    package org.apache.turbine.services.template.mapper;
002    
003    
004    /*
005     * Licensed to the Apache Software Foundation (ASF) under one
006     * or more contributor license agreements.  See the NOTICE file
007     * distributed with this work for additional information
008     * regarding copyright ownership.  The ASF licenses this file
009     * to you under the Apache License, Version 2.0 (the
010     * "License"); you may not use this file except in compliance
011     * with the License.  You may obtain a copy of the License at
012     *
013     *   http://www.apache.org/licenses/LICENSE-2.0
014     *
015     * Unless required by applicable law or agreed to in writing,
016     * software distributed under the License is distributed on an
017     * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
018     * KIND, either express or implied.  See the License for the
019     * specific language governing permissions and limitations
020     * under the License.
021     */
022    
023    
024    import org.apache.commons.lang.StringUtils;
025    import org.apache.turbine.services.template.TemplateService;
026    
027    /**
028     * The most primitive mapper. It is used for the page objects in the
029     * Template service. It never caches and simply returns what is given to it.
030     *
031     * @author <a href="mailto:hps@intermeta.de">Henning P. Schmiedehausen</a>
032     * @version $Id: DirectMapper.java 1078552 2011-03-06 19:58:46Z tv $
033     */
034    public class DirectMapper
035        extends BaseMapper
036        implements Mapper
037    {
038        /**
039         * Default C'tor. If you use this C'tor, you must use
040         * the bean setter to set the various properties needed for
041         * this mapper before first usage.
042         */
043        public DirectMapper()
044        {
045            super();
046        }
047    
048        /**
049         * Strip off a possible extension, replace all "," with "."
050         *
051         * about,directions,Driving.vm --> about.directions.Driving
052         *
053         * @param template The template name.
054         * @return A class name for the given template.
055         */
056        @Override
057        public String doMapping(String template)
058        {
059            String [] components
060                = StringUtils.split(template, String.valueOf(TemplateService.TEMPLATE_PARTS_SEPARATOR));
061    
062            String className = components[components.length - 1];
063    
064            // Strip off a possible Extension
065            int dotIndex = className.lastIndexOf(TemplateService.EXTENSION_SEPARATOR);
066            className = (dotIndex < 0) ? className : className.substring(0, dotIndex);
067            components[components.length -1] = className;
068    
069            // Class names are always separated by "."
070            return StringUtils.join(components, String.valueOf(separator));
071        }
072    }