Source Code Cross Referenced for ResManager.java in  » J2EE » Enhydra-Application-Framework » org » enhydra » 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 » J2EE » Enhydra Application Framework » org.enhydra.i18n 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Enhydra Java Application Server Project
003:         *
004:         * The contents of this file are subject to the Enhydra Public License
005:         * Version 1.1 (the "License"); you may not use this file except in
006:         * compliance with the License. You may obtain a copy of the License on
007:         * the Enhydra web site ( http://www.enhydra.org/ ).
008:         *
009:         * Software distributed under the License is distributed on an "AS IS"
010:         * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
011:         * the License for the specific terms governing rights and limitations
012:         * under the License.
013:         *
014:         * The Initial Developer of the Enhydra Application Server is Lutris
015:         * Technologies, Inc. The Enhydra Application Server and portions created
016:         * by Lutris Technologies, Inc. are Copyright Lutris Technologies, Inc.
017:         * All Rights Reserved.
018:         *
019:         * Contributor(s):
020:         *
021:         * $Id: ResManager.java,v 1.3 2007-10-19 10:05:39 sinisa Exp $
022:         */
023:
024:        package org.enhydra.i18n;
025:
026:        import java.text.MessageFormat;
027:        import java.util.Hashtable;
028:        import java.util.ResourceBundle;
029:
030:        import com.lutris.logging.LogChannel;
031:        import com.lutris.logging.Logger;
032:
033:        //import org.apache.log4j.Logger;
034:
035:        /**
036:         *
037:         * Some helper functions for handeling i18n issues. One instance of this class
038:         * should be created for each resource bundle.<P>
039:         *
040:         * The ResManager is created by a call to <CODE>getResourceManager()</CODE>
041:         * the parameter is the name of the package that contails the Res class.
042:         * e.g. ResManager rez = getResourceBundle("org.enhydra.mypackagename");<P>
043:         *
044:         * To use the ResManager make a call to any of the <CODE>format()</CODE>
045:         * methods. In the default resource bundle the key is the same as the value.
046:         * So to display "I am 2 years old" call rez.format("I am {0} years old",2);
047:         * If the string "I am {0} years old" is in the bundle the value is returned. If
048:         * string is not found in the bundle the key is returned and an error is logged
049:         * to I18N_DEBUG. To see these errors add DEBUG_I18N to Server.LogToFile[] and
050:         * Server.LogToStderr[] in multiserver.conf.
051:         *
052:         *
053:         * @author Peter Johnson
054:         */
055:
056:        public class ResManager {
057:
058:            /**
059:             * The ResourceBundle for this locale.
060:             */
061:
062:            //    private ResourceBundle bundle;
063:            //    private String bundleName;
064:            // v. strahinja, 22 sep 2002
065:            //      private LogChannel logChannel;
066:            // v. strahinja, 22 sep 2002
067:            //      private int logLevelDebug;
068:            // v. strahinja, 22 sep 2002
069:            //      private int logLevelInfo;
070:            static private Hashtable bundles = new Hashtable();
071:
072:            //    static Logger logger = Logger.getLogger(ResManager.class.getName());
073:
074:            private ResManager(String packageName) {
075:                //	bundleName = packageName + ".Res";
076:                // not ready yet.
077:                // bundle = ResourceBundle.getBundle(bundleName);
078:
079:                // Add DEBUG_I18N to the multiserver.conf file to log ResManager issues
080:                // v. strahinja, 22 sep 2002
081:                //   	logChannel = Logger.getCentralLogger().getChannel("Multiserver");
082:                // v. strahinja, 22 sep 2002
083:                //      logLevelDebug = logChannel.getLevel("I18N_DEBUG");
084:                // v. strahinja, 22 sep 2002
085:                //      logLevelInfo = logChannel.getLevel("I18N_INFO");
086:            }
087:
088:            /**
089:             * Returns a resource manager assocated with the package name.
090:             * An instance of the Res class is created the first time the method is
091:             * called.
092:             *
093:             * @param clazz     A class from the package that Rez is in.
094:             *
095:             */
096:            public static ResManager getResManager(Class clazz) {
097:
098:                // build a package name from the
099:                String packageName = clazz.getName();
100:                int lastDot = packageName.lastIndexOf('.');
101:                if (lastDot != -1)
102:                    packageName = packageName.substring(0, lastDot);
103:
104:                return getResManager(packageName);
105:            }
106:
107:            /**
108:             * Returns a resource manager assocated with the package name.
109:             * An instance of the Res class is created the first time the method is
110:             * called.
111:             *
112:             * @param packageName	The package name that holds the Res class
113:             *
114:             */
115:            public static ResManager getResManager(String packageName) {
116:                ResManager rez = (ResManager) bundles.get(packageName);
117:                if (rez == null) {
118:                    rez = new ResManager(packageName);
119:                    bundles.put(packageName, rez);
120:                }
121:                return rez;
122:            }
123:
124:            private String getString(String key) {
125:                // just return the key for now.
126:                return key;
127:                /*
128:                String msg;
129:                try {
130:                    msg = bundle.getString(key);
131:                }
132:                catch (MissingResourceException ex) {
133:                    msg = key;
134:
135:                    // Couldn't find the key log to I18N_INFO
136:                    //logChannel.write(logLevelInfo,key + " (String is missing from resource bundle \"" + bundleName+"\" )");
137:                }
138:                logChannel.write(logLevelDebug,key + " => " + msg);
139:                return msg;
140:                 */
141:            }
142:
143:            /**
144:             * Returns a string that has been obtained from the resource manager
145:             *
146:             * @param key           The string that is the key to the translated message
147:             *
148:             */
149:            public String format(String key) {
150:                return getString(key);
151:            }
152:
153:            /**
154:             * Returns a string that has been obtained from the resource manager then
155:             * formatted using the passed parameters.
156:             *
157:             * @param key           The string that is the key to the translated message
158:             * @param o0            The param passed to format replaces {0}
159:             *
160:             */
161:            public String format(String pattern, Object o0) {
162:                return MessageFormat.format(getString(pattern),
163:                        new Object[] { o0 });
164:            }
165:
166:            /**
167:             * Returns a string that has been obtained from the resource manager then
168:             * formatted using the passed parameters.
169:             *
170:             * @param key           The string that is the key to the translated message
171:             * @param o0            The param passed to format replaces {0}
172:             * @param o1            The param passed to format replaces {1}
173:             *
174:             */
175:            public String format(String pattern, Object o0, Object o1) {
176:                return MessageFormat.format(getString(pattern), new Object[] {
177:                        o0, o1 });
178:            }
179:
180:            /**
181:             * Returns a string that has been obtained from the resource manager then
182:             * formatted using the passed parameters.
183:             *
184:             * @param key           The string that is the key to the translated message
185:             * @param o0            The param passed to format replaces {0}
186:             * @param o1            The param passed to format replaces {1}
187:             * @param o2            The param passed to format replaces {2}
188:             *
189:             */
190:            public String format(String pattern, Object o0, Object o1, Object o2) {
191:                return MessageFormat.format(getString(pattern), new Object[] {
192:                        o0, o1, o2 });
193:            }
194:
195:            /**
196:             * Returns a string that has been obtained from the resource manager then
197:             * formatted using the passed parameters.
198:             *
199:             * @param key           The string that is the key to the translated message
200:             * @param o0            The param passed to format replaces {0}
201:             * @param o1            The param passed to format replaces {1}
202:             * @param o2            The param passed to format replaces {2}
203:             * @param o3            The param passed to format replaces {3}
204:             *
205:             */
206:            public String format(String pattern, Object o0, Object o1,
207:                    Object o2, Object o3) {
208:                return MessageFormat.format(getString(pattern), new Object[] {
209:                        o0, o1, o2, o3 });
210:            }
211:
212:            // add more if you need them...
213:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.