Source Code Cross Referenced for BaseMapper.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.HashMap;
023:        import java.util.Map;
024:
025:        import org.apache.commons.lang.StringUtils;
026:
027:        import org.apache.turbine.services.template.TurbineTemplate;
028:        import org.apache.turbine.services.template.TemplateEngineService;
029:
030:        /**
031:         * A base class for the various mappers which contains common
032:         * code.
033:         *
034:         * @author <a href="mailto:hps@intermeta.de">Henning P. Schmiedehausen</a>
035:         * @version $Id: BaseMapper.java 534527 2007-05-02 16:10:59Z tv $
036:         */
037:
038:        public abstract class BaseMapper {
039:            /** True if this mapper should cache template -> name mappings */
040:            private boolean useCache = false;
041:
042:            /** Default cache size. Just a number out of thin air. Will be set at init time */
043:            private int cacheSize = 5;
044:
045:            /** The internal template -> name mapping cache */
046:            private Map templateCache = null;
047:
048:            /** The name of the default property to pull from the Template Engine Service if the default is requested */
049:            protected String defaultProperty;
050:
051:            /** The separator used to concatenate the result parts for this mapper. */
052:            protected char separator;
053:
054:            // Note: You might _not_ use TurbineTemplate.<xxx> in the C'tor and the init method.
055:            // The service isn't configured yet and if you do, the Broker will try to reinit the
056:            // Service which leads to an endless loop and a deadlock.
057:
058:            /**
059:             * Default C'tor. If you use this C'tor, you must use
060:             * the bean setter to set the various properties needed for
061:             * this mapper before first usage.
062:             */
063:            public BaseMapper() {
064:            }
065:
066:            /**
067:             * Get the CacheSize value.
068:             * @return the CacheSize value.
069:             */
070:            public int getCacheSize() {
071:                return cacheSize;
072:            }
073:
074:            /**
075:             * Set the CacheSize value.
076:             * @param cacheSize The new CacheSize value.
077:             */
078:            public void setCacheSize(int cacheSize) {
079:                this .cacheSize = cacheSize;
080:            }
081:
082:            /**
083:             * Get the UseCache value.
084:             * @return the UseCache value.
085:             */
086:            public boolean isUseCache() {
087:                return useCache;
088:            }
089:
090:            /**
091:             * Set the UseCache value.
092:             * @param newUseCache The new UseCache value.
093:             */
094:            public void setUseCache(boolean useCache) {
095:                this .useCache = useCache;
096:            }
097:
098:            /**
099:             * Get the DefaultProperty value.
100:             * @return the DefaultProperty value.
101:             */
102:            public String getDefaultProperty() {
103:                return defaultProperty;
104:            }
105:
106:            /**
107:             * Set the DefaultProperty value.
108:             * @param defaultProperty The new DefaultProperty value.
109:             */
110:            public void setDefaultProperty(String defaultProperty) {
111:                this .defaultProperty = defaultProperty;
112:            }
113:
114:            /**
115:             * Get the Separator value.
116:             * @return the Separator value.
117:             */
118:            public char getSeparator() {
119:                return separator;
120:            }
121:
122:            /**
123:             * Set the Separator value.
124:             * @param separator The new Separator value.
125:             */
126:            public void setSeparator(char separator) {
127:                this .separator = separator;
128:            }
129:
130:            /**
131:             * Initializes the Mapper. Must be called before the mapper might be used.
132:             */
133:            public void init() {
134:                if (useCache) {
135:                    templateCache = new HashMap(cacheSize);
136:                }
137:            }
138:
139:            /**
140:             * Returns the default name for the passed Template.
141:             * If the passed template has no extension,
142:             * the default extension is assumed.
143:             * If the template is empty, the default template is
144:             * returned.
145:             *
146:             * @param template The template name.
147:             *
148:             * @return the mapped default name for the template.
149:             */
150:
151:            public String getDefaultName(String template) {
152:                // We might get a Name without an extension passed. If yes, then we use
153:                // the Default extension
154:
155:                TemplateEngineService tes = TurbineTemplate
156:                        .getTemplateEngineService(template);
157:
158:                if (StringUtils.isEmpty(template) || (tes == null)) {
159:                    return TurbineTemplate.getDefaultTemplate();
160:                }
161:
162:                String defaultName = (String) tes
163:                        .getTemplateEngineServiceConfiguration().get(
164:                                defaultProperty);
165:
166:                return StringUtils.isEmpty(defaultName) ? TurbineTemplate
167:                        .getDefaultTemplate() : defaultName;
168:            }
169:
170:            /**
171:             * Return the first match name for the given template name.
172:             *
173:             * @param template The template name.
174:             *
175:             * @return The first matching class or template name.
176:             */
177:            public String getMappedName(String template) {
178:                if (StringUtils.isEmpty(template)) {
179:                    return null;
180:                }
181:
182:                if (useCache && templateCache.containsKey(template)) {
183:                    return (String) templateCache.get(template);
184:                }
185:
186:                String res = doMapping(template);
187:
188:                // Never cache "null" return values and empty Strings.
189:                if (useCache && StringUtils.isNotEmpty(res)) {
190:                    templateCache.put(template, res);
191:                }
192:
193:                return res;
194:            }
195:
196:            /**
197:             * The actual mapping implementation class. It
198:             * is guaranteed that never an empty or null
199:             * template name is passed to it. This might
200:             * return null.
201:             *
202:             * @param template The template name.
203:             * @return The mapped class or template name.
204:             */
205:            public abstract String doMapping(String template);
206:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.