Source Code Cross Referenced for ScreenDefaultTemplateMapper.java in  » Web-Framework » TURBINE » org » apache » turbine » services » template » mapper » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Web Framework » TURBINE » org.apache.turbine.services.template.mapper 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package org.apache.turbine.services.template.mapper;
002:
003:        /*
004:         * Licensed to the Apache Software Foundation (ASF) under one
005:         * or more contributor license agreements.  See the NOTICE file
006:         * distributed with this work for additional information
007:         * regarding copyright ownership.  The ASF licenses this file
008:         * to you under the Apache License, Version 2.0 (the
009:         * "License"); you may not use this file except in compliance
010:         * with the License.  You may obtain a copy of the License at
011:         *
012:         *   http://www.apache.org/licenses/LICENSE-2.0
013:         *
014:         * Unless required by applicable law or agreed to in writing,
015:         * software distributed under the License is distributed on an
016:         * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017:         * KIND, either express or implied.  See the License for the
018:         * specific language governing permissions and limitations
019:         * under the License.
020:         */
021:
022:        import java.util.List;
023:        import java.util.ArrayList;
024:        import java.util.Arrays;
025:
026:        import org.apache.commons.lang.StringUtils;
027:
028:        import org.apache.commons.logging.Log;
029:        import org.apache.commons.logging.LogFactory;
030:
031:        import org.apache.turbine.services.template.TemplateEngineService;
032:        import org.apache.turbine.services.template.TemplateService;
033:        import org.apache.turbine.services.template.TurbineTemplate;
034:
035:        /**
036:         * This is a pretty simple mapper which returns template pathes for
037:         * a supplied template name. If the path does not exist, it looks for
038:         * a templated called "Default" in the same package.
039:         * This path can be used by the TemplateEngine to access
040:         * a certain resource to actually render the template.
041:         *
042:         * @author <a href="mailto:hps@intermeta.de">Henning P. Schmiedehausen</a>
043:         * @version $Id: ScreenDefaultTemplateMapper.java 534527 2007-05-02 16:10:59Z tv $
044:         */
045:
046:        public class ScreenDefaultTemplateMapper extends BaseTemplateMapper
047:                implements  Mapper {
048:            /** Logging */
049:            private static Log log = LogFactory
050:                    .getLog(ScreenDefaultTemplateMapper.class);
051:
052:            /**
053:             * Default C'tor. If you use this C'tor, you must use
054:             * the bean setter to set the various properties needed for
055:             * this mapper before first usage.
056:             */
057:            public ScreenDefaultTemplateMapper() {
058:            }
059:
060:            /**
061:             * Look for a given Template, then try the
062:             * default.
063:             *
064:             * @param template The template name.
065:             * @return The parsed module name.
066:             */
067:            public String doMapping(String template) {
068:                log.debug("doMapping(" + template + ")");
069:                // Copy our elements into an array
070:                List components = new ArrayList(
071:                        Arrays
072:                                .asList(StringUtils
073:                                        .split(
074:                                                template,
075:                                                String
076:                                                        .valueOf(TemplateService.TEMPLATE_PARTS_SEPARATOR))));
077:                int componentSize = components.size() - 1;
078:
079:                // This method never gets an empty string passed.
080:                // So this is never < 0
081:                String templateName = (String) components.get(componentSize);
082:                components.remove(componentSize--);
083:
084:                log.debug("templateName is " + templateName);
085:
086:                // Last element decides, which template Service to use...
087:                TemplateEngineService tes = TurbineTemplate
088:                        .getTemplateEngineService(templateName);
089:
090:                if (tes == null) {
091:                    return null;
092:                }
093:
094:                String defaultName = "Default.vm";
095:
096:                // This is an optimization. If the name we're looking for is
097:                // already the default name for the template, don't do a "first run"
098:                // which looks for an exact match.
099:                boolean firstRun = !templateName.equals(defaultName);
100:
101:                for (;;) {
102:                    String templatePackage = StringUtils.join(components
103:                            .iterator(), String.valueOf(separator));
104:
105:                    log.debug("templatePackage is now: " + templatePackage);
106:
107:                    StringBuffer testName = new StringBuffer();
108:
109:                    if (!components.isEmpty()) {
110:                        testName.append(templatePackage);
111:                        testName.append(separator);
112:                    }
113:
114:                    testName.append((firstRun) ? templateName : defaultName);
115:
116:                    // But the Templating service must look for the name with prefix
117:                    StringBuffer templatePath = new StringBuffer();
118:                    if (StringUtils.isNotEmpty(prefix)) {
119:                        templatePath.append(prefix);
120:                        templatePath.append(separator);
121:                    }
122:                    templatePath.append(testName);
123:
124:                    log.debug("Looking for " + templatePath);
125:
126:                    if (tes.templateExists(templatePath.toString())) {
127:                        log.debug("Found it, returning " + testName);
128:                        return testName.toString();
129:                    }
130:
131:                    if (firstRun) {
132:                        firstRun = false;
133:                    } else {
134:                        // We run this loop only two times. The
135:                        // first time with the 'real' name and the
136:                        // second time with "Default". The second time
137:                        // we will end up here and break the for(;;) loop.
138:                        break;
139:                    }
140:                }
141:
142:                log.debug("Returning default");
143:                return getDefaultName(template);
144:            }
145:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.