Source Code Cross Referenced for Messages.java in  » Content-Management-System » contineo » org » contineo » web » i18n » 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 » Content Management System » contineo » org.contineo.web.i18n 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package org.contineo.web.i18n;
002:
003:        import org.contineo.util.config.FacesConfigurator;
004:
005:        import org.contineo.web.util.Constants;
006:
007:        import java.text.MessageFormat;
008:
009:        import java.util.AbstractMap;
010:        import java.util.ArrayList;
011:        import java.util.List;
012:        import java.util.Locale;
013:        import java.util.MissingResourceException;
014:        import java.util.ResourceBundle;
015:        import java.util.Set;
016:
017:        import javax.faces.application.FacesMessage;
018:        import javax.faces.context.FacesContext;
019:
020:        /**
021:         * A class for retrieval of localized messages. All bundles declared in
022:         * faces-config.xml are searched but in the opposite order they are declared in
023:         * the file. The first key match wins.
024:         *
025:         * @author Marco Meschieri
026:         * @version $Id:$
027:         * @since 3.0
028:         */
029:        public class Messages extends AbstractMap<String, String> {
030:            /**
031:             * The list of bundles in which keys will be searched
032:             */
033:            private static List<String> bundles = new ArrayList<String>();
034:
035:            public Messages() {
036:                // a static class
037:            }
038:
039:            public static String getMessage(String key, Locale locale) {
040:                if (bundles.isEmpty()) {
041:                    FacesConfigurator config = new FacesConfigurator();
042:                    bundles = config.getBundles();
043:                }
044:
045:                // Iterate over bundles in reverse order
046:                for (int i = bundles.size() - 1; i >= 0; i--) {
047:                    String path = bundles.get(i);
048:                    ResourceBundle bundle = ResourceBundle.getBundle(path,
049:                            locale);
050:
051:                    try {
052:                        return bundle.getString(key);
053:                    } catch (MissingResourceException e) {
054:                        // Continue
055:                    }
056:                }
057:
058:                return key;
059:            }
060:
061:            public static String getMessage(String key) {
062:                FacesContext facesContext = FacesContext.getCurrentInstance();
063:                Locale locale = (Locale) facesContext.getExternalContext()
064:                        .getSessionMap().get(Constants.LOCALE);
065:
066:                if (locale == null) {
067:                    locale = facesContext.getApplication().getDefaultLocale();
068:                }
069:
070:                return getMessage(key, locale);
071:            }
072:
073:            public static String getMessage(String key, String val0) {
074:                String msg = getMessage(key);
075:
076:                return MessageFormat.format(msg, new Object[] { val0 });
077:            }
078:
079:            public static void addLocalizedWarn(String message) {
080:                addWarn(Messages.getMessage(message));
081:            }
082:
083:            public static void addWarn(String message) {
084:                addMessage(FacesMessage.SEVERITY_WARN, null, message, message);
085:            }
086:
087:            public static void addLocalizedError(String message) {
088:                addError(Messages.getMessage(message));
089:            }
090:
091:            public static void addError(String message) {
092:                addMessage(FacesMessage.SEVERITY_ERROR, null, message, message);
093:            }
094:
095:            public static void addLocalizedInfo(String message) {
096:                addInfo(Messages.getMessage(message));
097:            }
098:
099:            public static void addInfo(String message) {
100:                addMessage(FacesMessage.SEVERITY_INFO, null, message, message);
101:            }
102:
103:            public static void addMessage(FacesMessage.Severity severity,
104:                    String summary, String detail) {
105:                addMessage(severity, null, summary, detail);
106:            }
107:
108:            /**
109:             * Adds a message in the jsf queue
110:             *
111:             * @param severity The severity level
112:             * @param clientId The componentID (null can be accepted)
113:             * @param summary The summary part(bundle key)
114:             * @param detail The detail part(bundle key)
115:             */
116:            public static void addMessage(FacesMessage.Severity severity,
117:                    String clientId, String summary, String detail) {
118:                FacesContext facesContext = FacesContext.getCurrentInstance();
119:                FacesMessage message = new FacesMessage(severity, summary,
120:                        detail);
121:                facesContext.addMessage(clientId, message);
122:            }
123:
124:            @Override
125:            public Set<java.util.Map.Entry<String, String>> entrySet() {
126:                return null;
127:            }
128:
129:            @Override
130:            public String get(Object key) {
131:                return Messages.getMessage(key.toString());
132:            }
133:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.