Source Code Cross Referenced for I18nSupport.java in  » Web-Framework » calyxo » de » odysseus » calyxo » base » 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 » calyxo » de.odysseus.calyxo.base 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 2004, 2005, 2006 Odysseus Software GmbH
003:         *
004:         * Licensed under the Apache License, Version 2.0 (the "License");
005:         * you may not use this file except in compliance with the License.
006:         * You may obtain a copy of the License at
007:         *
008:         *     http://www.apache.org/licenses/LICENSE-2.0
009:         *
010:         * Unless required by applicable law or agreed to in writing, software
011:         * distributed under the License is distributed on an "AS IS" BASIS,
012:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013:         * See the License for the specific language governing permissions and
014:         * limitations under the License.
015:         */
016:        package de.odysseus.calyxo.base;
017:
018:        import java.util.HashMap;
019:        import java.util.Locale;
020:        import java.util.Map;
021:
022:        import javax.servlet.http.HttpServletRequest;
023:        import javax.servlet.jsp.PageContext;
024:
025:        /**
026:         * Abstract internationalization support class. There is one instance
027:         * per module, which may be retreived via the <code>getInstance()</code>
028:         * methods.
029:         * 
030:         * I18n support includes determination of a request's desired locale,
031:         * resource lookup and message construction(a message is a resource
032:         * with parameters).
033:         * 
034:         * The basic principle here is, that internationalized content may be
035:         * determined by specifying a locale, a bundle name and a resource key.
036:         * Beyond that, there are no further requirements.
037:         * 
038:         * Bundle aliases may be registered using the <code>addBundleAlias</code>
039:         * method.
040:         * 
041:         * @author Christoph Beck
042:         */
043:        public abstract class I18nSupport {
044:
045:            /**
046:             * Module scope key where the i18n support instance is stored.
047:             */
048:            public static final String I18N_SUPPORT_KEY = "de.odysseus.calyxo.base.i18n";
049:
050:            /**
051:             * Bundle aliases map
052:             */
053:            private Map aliases = new HashMap();
054:
055:            /**
056:             * Lookup i18n support for module determined by specified request
057:             */
058:            public static final I18nSupport getInstance(
059:                    HttpServletRequest request) {
060:                ModuleContext context = ModuleSupport.getInstance(request)
061:                        .getModuleContext(request);
062:                return (I18nSupport) context.getAttribute(I18N_SUPPORT_KEY);
063:            }
064:
065:            /**
066:             * Convenience method.
067:             * @see #getInstance(HttpServletRequest)
068:             */
069:            public static final I18nSupport getInstance(PageContext pageContext) {
070:                return getInstance((HttpServletRequest) pageContext
071:                        .getRequest());
072:            }
073:
074:            /**
075:             * Lookup i18n support for specified module
076:             */
077:            public static final I18nSupport getInstance(ModuleContext context) {
078:                return (I18nSupport) context.getAttribute(I18N_SUPPORT_KEY);
079:            }
080:
081:            /**
082:             * Set bundle alias.
083:             * When resolving resources and messages, bundle names may be
084:             * aliased. The alias will be removed if the specified bundle
085:             * is <code>null</code> or equal to the alias name.
086:             * Otherwise, bundle names passed to subsequent calls of
087:             * {@link #getMessage(Locale, String, String, Object[])}
088:             * and {@link #getResource(Locale, String, String)} will be
089:             * aliased as specified here.
090:             * 
091:             * @param alias the alias name
092:             * @param bundle the bundle name
093:             */
094:            public void setBundleAlias(String alias, String bundle) {
095:                if (bundle == null || bundle.equals(alias)) {
096:                    aliases.remove(alias);
097:                } else {
098:                    aliases.put(alias, bundle);
099:                }
100:            }
101:
102:            /**
103:             * Get unaliased bundle name.
104:             * @param bundle the bundle name or alias
105:             * @return if the specified bundle name is an alias set with {@link #setBundleAlias(String, String)},
106:             * the associated name is returned. Otherwise, the specified bundle name is returned. 
107:             */
108:            public String resolveBundle(String bundle) {
109:                return aliases.containsKey(bundle) ? (String) aliases
110:                        .get(bundle) : bundle;
111:            }
112:
113:            /**
114:             * Get the desired locale for the specified request.
115:             * An implementation may choose to cache the locale
116:             * in session scope and answer that value here.
117:             */
118:            public abstract Locale getLocale(HttpServletRequest request);
119:
120:            /**
121:             * Convenience method.
122:             * @see #getLocale(HttpServletRequest)
123:             */
124:            public final Locale getLocale(PageContext pageContext) {
125:                return getLocale((HttpServletRequest) pageContext.getRequest());
126:            }
127:
128:            /**
129:             * Set the desired locale for the specified request.
130:             * An implementation may choose to cache the locale set here
131:             * in session scope and answer that value in subsequent calls
132:             * of <code>getLocale()</code> methods.
133:             */
134:            public abstract void setLocale(HttpServletRequest request,
135:                    Locale locale);
136:
137:            /**
138:             * Convenience method.
139:             * @see #setLocale(HttpServletRequest, Locale)
140:             */
141:            public void setLocale(PageContext pageContext, Locale locale) {
142:                setLocale((HttpServletRequest) pageContext.getRequest(), locale);
143:            }
144:
145:            /**
146:             * Get a resource string.
147:             * @param locale the desired locale
148:             * @param bundle the bundle name or alias
149:             * @param key the resource key
150:             * @return resource string
151:             */
152:            public final String getResource(Locale locale, String bundle,
153:                    String key) {
154:                return lookupResource(locale, resolveBundle(bundle), key);
155:            }
156:
157:            /**
158:             * Lookup a resource string.
159:             * @param locale the desired locale
160:             * @param bundle the bundle name
161:             * @param key the resource key
162:             * @return resource string
163:             */
164:            protected abstract String lookupResource(Locale locale,
165:                    String bundle, String key);
166:
167:            /**
168:             * Get a message string
169:             * @param locale the desired locale
170:             * @param bundle the bundle name or alias
171:             * @param key the resource key
172:             * @param args message arguments
173:             * @return message string
174:             */
175:            public final String getMessage(Locale locale, String bundle,
176:                    String key, Object[] args) {
177:                return lookupMessage(locale, resolveBundle(bundle), key, args);
178:            }
179:
180:            /**
181:             * Lookup a message string
182:             * @param locale the desired locale
183:             * @param bundle the bundle name
184:             * @param key the resource key
185:             * @param args message arguments
186:             * @return message string
187:             */
188:            protected abstract String lookupMessage(Locale locale,
189:                    String bundle, String key, Object[] args);
190:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.