Source Code Cross Referenced for LocaleUtil.java in  » ERP-CRM-Financial » sakai » org » sakaiproject » jsf » util » 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 » ERP CRM Financial » sakai » org.sakaiproject.jsf.util 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**********************************************************************************
002:         *
003:         * $Id: LocaleUtil.java 21053 2007-02-06 18:03:57Z ray@media.berkeley.edu $
004:         *
005:         ***********************************************************************************
006:         *
007:         * Copyright (c) 2007 The Regents of the University of California
008:         *
009:         * Licensed under the Educational Community License, Version 1.0 (the "License");
010:         * you may not use this file except in compliance with the License.
011:         * You may obtain a copy of the License at
012:         *
013:         *      http://www.opensource.org/licenses/ecl1.php
014:         *
015:         * Unless required by applicable law or agreed to in writing, software
016:         * distributed under the License is distributed on an "AS IS" BASIS,
017:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
018:         * See the License for the specific language governing permissions and
019:         * limitations under the License.
020:         *
021:         **********************************************************************************/package org.sakaiproject.jsf.util;
022:
023:        import java.lang.reflect.Constructor;
024:        import java.lang.reflect.InvocationTargetException;
025:        import java.lang.reflect.Method;
026:        import java.util.Locale;
027:        import java.util.ResourceBundle;
028:
029:        import javax.faces.context.FacesContext;
030:
031:        import org.apache.commons.logging.Log;
032:        import org.apache.commons.logging.LogFactory;
033:
034:        /**
035:         * Instead of using standard methods of deciding which locale should be used
036:         * when loading a resource, Sakai tools are requested to go through the Sakai-specific
037:         * ResourceLoader class, which lets Sakai-specific settings such as site
038:         * preferences be taken into account.
039:         * 
040:         * Currently the ResourceLoader functionality is not behind an
041:         * interface, and so direct references to the class will drag in dependencies
042:         * on framework features. To keep the Sakai JSF tag library self-sufficient,
043:         * this utility class uses JavaBean-style introspection to load and use
044:         * the ResourceLoader class if it's available, or to fall back to the standard
045:         * UIViewRoot  "getLocale()" method.
046:         * 
047:         * Note that we only use the "getLocale()" method in ResourceLoader.
048:         * For details, see the comments to SAK-6886.
049:         */
050:        public class LocaleUtil {
051:            private static final Log log = LogFactory.getLog(LocaleUtil.class);
052:
053:            private static Object sakaiResourceLoader = null;
054:            private static Method sakaiResourceLoaderGetLocale;
055:            private static boolean isInitialized = false;
056:
057:            private static void init() {
058:                if (!isInitialized) {
059:                    // Try to load the Sakai localization class.
060:                    try {
061:                        Class sakaiResourceLoaderClass = Class
062:                                .forName("org.sakaiproject.util.ResourceLoader");
063:                        if (log.isDebugEnabled())
064:                            log.debug("Found Sakai ResourceLoader class");
065:                        Constructor sakaiResourceLoaderConstructor = sakaiResourceLoaderClass
066:                                .getConstructor();
067:                        sakaiResourceLoaderGetLocale = sakaiResourceLoaderClass
068:                                .getMethod("getLocale");
069:                        sakaiResourceLoader = sakaiResourceLoaderConstructor
070:                                .newInstance();
071:                    } catch (ClassNotFoundException e) {
072:                        if (log.isDebugEnabled())
073:                            log
074:                                    .debug("Did not find Sakai ResourceLoader class; will use standard JSF localization");
075:                    } catch (SecurityException e) {
076:                        if (log.isErrorEnabled())
077:                            log.error("Will use standard JSF localization", e);
078:                    } catch (NoSuchMethodException e) {
079:                        if (log.isErrorEnabled())
080:                            log.error("Will use standard JSF localization", e);
081:                    } catch (IllegalArgumentException e) {
082:                        if (log.isErrorEnabled())
083:                            log.error("Will use standard JSF localization", e);
084:                    } catch (InstantiationException e) {
085:                        if (log.isErrorEnabled())
086:                            log.error("Will use standard JSF localization", e);
087:                    } catch (IllegalAccessException e) {
088:                        if (log.isErrorEnabled())
089:                            log.error("Will use standard JSF localization", e);
090:                    } catch (InvocationTargetException e) {
091:                        if (log.isErrorEnabled())
092:                            log.error("Will use standard JSF localization", e);
093:                    }
094:                    isInitialized = true;
095:                }
096:            }
097:
098:            public static Locale getLocale(FacesContext context) {
099:                Locale locale = null;
100:                init();
101:                if (sakaiResourceLoader != null) {
102:                    try {
103:                        locale = (Locale) sakaiResourceLoaderGetLocale
104:                                .invoke(sakaiResourceLoader);
105:                    } catch (IllegalArgumentException e) {
106:                        if (log.isErrorEnabled())
107:                            log.error(e);
108:                    } catch (IllegalAccessException e) {
109:                        if (log.isErrorEnabled())
110:                            log.error(e);
111:                    } catch (InvocationTargetException e) {
112:                        if (log.isErrorEnabled())
113:                            log.error(e);
114:                    }
115:                } else {
116:                    // Use standard JSF approach.
117:                    locale = context.getViewRoot().getLocale();
118:                }
119:                return locale;
120:            }
121:
122:            public static String getLocalizedString(FacesContext context,
123:                    String bundleName, String key) {
124:                String localized = null;
125:                Locale locale = getLocale(context);
126:                ResourceBundle rb = ResourceBundle
127:                        .getBundle(bundleName, locale);
128:                if (log.isDebugEnabled())
129:                    log.debug("getLocalizedString; locale="
130:                            + locale.getDisplayName() + ", bundleName="
131:                            + bundleName + ", rb=" + rb.getLocale()
132:                            + ", rb getCountry()="
133:                            + rb.getLocale().getCountry());
134:                localized = rb.getString(key);
135:                return localized;
136:            }
137:
138:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.