Source Code Cross Referenced for StringManager.java in  » Database-Client » squirrel-sql-2.6.5a » net » sourceforge » squirrel_sql » fw » 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 » Database Client » squirrel sql 2.6.5a » net.sourceforge.squirrel_sql.fw.util 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package net.sourceforge.squirrel_sql.fw.util;
002:
003:        /*
004:         * Copyright (C) 2003 Colin Bell
005:         * colbell@users.sourceforge.net
006:         *
007:         * This library is free software; you can redistribute it and/or
008:         * modify it under the terms of the GNU Lesser General Public
009:         * License as published by the Free Software Foundation; either
010:         * version 2.1 of the License, or (at your option) any later version.
011:         *
012:         * This library is distributed in the hope that it will be useful,
013:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
014:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
015:         * Lesser General Public License for more details.
016:         *
017:         * You should have received a copy of the GNU Lesser General Public
018:         * License along with this library; if not, write to the Free Software
019:         * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
020:         */
021:        import java.text.MessageFormat;
022:        import java.util.Locale;
023:        import java.util.MissingResourceException;
024:        import java.util.ResourceBundle;
025:        import java.net.URLClassLoader;
026:        import java.net.URL;
027:
028:        import net.sourceforge.squirrel_sql.fw.util.log.ILogger;
029:        import net.sourceforge.squirrel_sql.fw.util.log.LoggerController;
030:
031:        /**
032:         * This class defines i18nized strings. These strings are stored in a file
033:         * with a base name I18NStrings.properties in each package directory.
034:         *
035:         * @author <A HREF="mailto:colbell@users.sourceforge.net">Colin Bell</A>
036:         */
037:        public class StringManager {
038:            /** Logger for this class. */
039:            private static ILogger s_log = LoggerController
040:                    .createLogger(StringManager.class);
041:
042:            /** Contains the localised strings. */
043:            private ResourceBundle _rsrcBundle;
044:            private String _bundleBaseName;
045:            private URL[] _bundleLoaderUrLs = new URL[0];
046:
047:            /**
048:             * Ctor specifying the package name. Attempt to load a resource bundle
049:             * from the package directory.
050:             *
051:             * @param	packageName	Name of package
052:             * @param	classLoader	Class loader to use
053:             */
054:            StringManager(String packageName, ClassLoader loader) {
055:                super ();
056:                _bundleBaseName = packageName + ".I18NStrings";
057:                _rsrcBundle = ResourceBundle.getBundle(_bundleBaseName, Locale
058:                        .getDefault(), loader);
059:
060:                if (loader instanceof  URLClassLoader) {
061:                    _bundleLoaderUrLs = ((URLClassLoader) loader).getURLs();
062:                }
063:
064:            }
065:
066:            /**
067:             * Retrieve the localized string for the passed key. If it isn't found
068:             * an error message is returned instead.
069:             *
070:             * @param	key		Key to retrieve string for.
071:             *
072:             * @return	Localized string or error message.
073:             *
074:             * @throws	IllegalArgumentException
075:             * 			Thrown if <TT>null</TT> <TT>key</TT> passed.
076:             */
077:            public String getString(String key) {
078:                if (key == null) {
079:                    throw new IllegalArgumentException("key == null");
080:                }
081:
082:                try {
083:                    return _rsrcBundle.getString(key);
084:                } catch (MissingResourceException ex) {
085:                    StringBuffer sb = new StringBuffer();
086:                    sb.append("No resource string found for key '" + key
087:                            + "' in bundle " + _bundleBaseName + "\n\n");
088:
089:                    if (0 < _bundleLoaderUrLs.length) {
090:                        sb
091:                                .append("The following classpath entries are available to the bundle loader:\n");
092:                        for (int i = 0; i < _bundleLoaderUrLs.length; i++) {
093:                            sb.append(_bundleLoaderUrLs[i]).append("\n");
094:                        }
095:                    }
096:                    s_log.error(sb.toString());
097:                    return "No resource found for key " + key;
098:                }
099:            }
100:
101:            /**
102:             * Retrieve the localized string for the passed key and format it with the
103:             * passed arguments.
104:             *
105:             * @param   key     Key to retrieve string for.
106:             * @param   args    Any string arguments that should be used as values to 
107:             *                  parameters found in the localized string.
108:             *                   
109:             * @return  Localized string or error message.
110:             *
111:             * @throws  IllegalArgumentException
112:             *          Thrown if <TT>null</TT> <TT>key</TT> passed.
113:             */
114:            public String getString(String key, String[] args) {
115:                return getString(key, (Object[]) args);
116:            }
117:
118:            /**
119:             * Retrieve the localized string for the passed key and format it with the
120:             * passed arguments.
121:             *
122:             * @param	key		Key to retrieve string for.
123:             * @param   args    Any string arguments that should be used as values to 
124:             *                  parameters found in the localized string. 
125:             *
126:             * @return	Localized string or error message.
127:             *
128:             * @throws	IllegalArgumentException
129:             * 			Thrown if <TT>null</TT> <TT>key</TT> passed.
130:             */
131:            public String getString(String key, Object... args) {
132:                if (key == null) {
133:                    throw new IllegalArgumentException("key == null");
134:                }
135:
136:                if (args == null) {
137:                    args = new Object[0];
138:                }
139:
140:                final String str = getString(key);
141:                try {
142:                    return MessageFormat.format(str, args);
143:                } catch (IllegalArgumentException ex) {
144:                    String msg = "Error formatting i18 string. Key is '" + key
145:                            + "'";
146:                    s_log.error(msg, ex);
147:                    return msg + ": " + ex.toString();
148:                }
149:            }
150:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.