Source Code Cross Referenced for I18N.java in  » Report » datavision-1.1.0 » jimm » 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 » Report » datavision 1.1.0 » jimm.util 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package jimm.util;
002:
003:        import java.util.HashMap;
004:        import java.util.ResourceBundle;
005:        import java.util.Locale;
006:        import java.util.MissingResourceException;
007:
008:        /**
009:         * This class finds the local version of any string. It also contains
010:         * a method for changing the language.
011:         * <p>
012:         * Each language should have a file called datavision_XX_YY.properties,
013:         * where XX is the language code (e.g., "en" for English, "fr" for French)
014:         * and YY is the country code (e.g., "US", "FR").
015:         *
016:         * @author Jim Menard, <a href="mailto:jimm@io.com">jimm@io.com</a>
017:         */
018:        public class I18N {
019:
020:            public static final String RESOURCE_FILE_PREFIX = "datavision";
021:            public static final String MENU_FILE_PREFIX = "menu";
022:            public static final String PAPER_FILE_PREFIX = "paper";
023:
024:            protected static Locale locale;
025:            protected static HashMap bundles;
026:
027:            // Initialize the language.
028:            static {
029:                setLanguage(Locale.getDefault());
030:            }
031:
032:            /**
033:             * Given a locale, start using the code short phrases for that lanuage.
034:             * Normally, you won't have to call this method. It gets called at startup
035:             * and sets the locale to the default one.
036:             *
037:             * @param l the new locale
038:             */
039:            public static void setLanguage(Locale l) {
040:                if (!l.equals(locale)) {
041:                    locale = l;
042:                    bundles = new HashMap();
043:                }
044:            }
045:
046:            /**
047:             * Returns the string corresponding to the specified string. Returns
048:             * <var>key</var> if <var>key</var> is either <code>null</code> or the
049:             * empty string. Reports an error if <var>key</var> does not exist.
050:             *
051:             * @param key the lookup key
052:             * @return the string corresponding to the specified lookup key
053:             * or <code>null</code> if there isn't one; if <var>key</var> is the
054:             * empty string, return it
055:             */
056:            public static String get(String key) {
057:                return get(RESOURCE_FILE_PREFIX, key);
058:            }
059:
060:            /**
061:             * Returns the string corresponding to the specified string in the bundle
062:             * file corresponding to the name <var>prefix</var>. Returns <var>key</var>
063:             * if <var>key</var> is either <code>null</code> or the empty string.
064:             * Reports an error if <var>key</var> does not exist.
065:             *
066:             * @param prefix the bundle file name prefix
067:             * @param key the lookup key
068:             * @return the string corresponding to the specified lookup key
069:             * or <code>null</code> if there isn't one; if <var>key</var> is the
070:             * empty string, return it
071:             */
072:            public static String get(String prefix, String key) {
073:                if (key == null || prefix == null || prefix.length() == 0)
074:                    return null;
075:                if (key.length() == 0)
076:                    return "";
077:
078:                String val = "";
079:                try {
080:                    ResourceBundle strings = getBundle(prefix);
081:                    val = strings.getString(key);
082:                    if (val == null)
083:                        val = key;
084:                    else
085:                        val = val.trim();
086:                } catch (MissingResourceException ex) {
087:                    val = key;
088:                }
089:                return val;
090:            }
091:
092:            /**
093:             * Returns the string corresponding to the specified string. Returns
094:             * <var>key</var> if <var>key</var> is either <code>null</code> or the
095:             * empty string. Reports <code>null</code> if <var>key</var> does not exist.
096:             *
097:             * @param key the lookup key
098:             * @return the string corresponding to the specified lookup key
099:             * or <code>null</code> if there isn't one; if <var>key</var> is the
100:             * empty string, return it
101:             */
102:            public static String getNullIfMissing(String key) {
103:                return getNullIfMissing(RESOURCE_FILE_PREFIX, key);
104:            }
105:
106:            /**
107:             * Returns the string corresponding to the specified string in the bundle
108:             * file corresponding to the name <var>prefix</var>. Returns <var>key</var>
109:             * if <var>key</var> is either <code>null</code> or the empty string.
110:             * Reports <code>null</code> if <var>key</var> does not exist.
111:             *
112:             * @param prefix the bundle file name prefix
113:             * @param key the lookup key
114:             * @return the string corresponding to the specified lookup key
115:             * or <code>null</code> if there isn't one; if <var>key</var> is the
116:             * empty string, return it
117:             */
118:            public static String getNullIfMissing(String prefix, String key) {
119:                if (key == null || prefix == null || prefix.length() == 0)
120:                    return null;
121:                if (key.length() == 0)
122:                    return "";
123:
124:                String val = null;
125:                try {
126:                    ResourceBundle strings = getBundle(prefix);
127:                    val = strings.getString(key);
128:                    if (val == null)
129:                        val = "";
130:                    else
131:                        val = val.trim();
132:                } catch (MissingResourceException ex) {
133:                    val = null;
134:                }
135:                return val;
136:            }
137:
138:            protected static ResourceBundle getBundle(String prefix) {
139:                ResourceBundle bundle = (ResourceBundle) bundles.get(prefix);
140:                if (bundle == null) {
141:                    bundle = ResourceBundle.getBundle(prefix, locale);
142:                    bundles.put(prefix, bundle);
143:                }
144:                return bundle;
145:            }
146:
147:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.