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