Source Code Cross Referenced for MessageUtil.java in  » Report » pentaho-report » org » pentaho » messages » 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 » pentaho report » org.pentaho.messages 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 2006 Pentaho Corporation.  All rights reserved. 
003:         * This software was developed by Pentaho Corporation and is provided under the terms 
004:         * of the Mozilla Public License, Version 1.1, or any later version. You may not use 
005:         * this file except in compliance with the license. If you need a copy of the license, 
006:         * please go to http://www.mozilla.org/MPL/MPL-1.1.txt. The Original Code is the Pentaho 
007:         * BI Platform.  The Initial Developer is Pentaho Corporation.
008:         *
009:         * Software distributed under the Mozilla Public License is distributed on an "AS IS" 
010:         * basis, WITHOUT WARRANTY OF ANY KIND, either express or  implied. Please refer to 
011:         * the license for the specific language governing your rights and limitations.
012:         *
013:         * @created Jul 13, 2005 
014:         * @author Marc Batchelor
015:         * 
016:         */
017:
018:        package org.pentaho.messages;
019:
020:        import java.text.MessageFormat;
021:        import java.util.ResourceBundle;
022:
023:        public class MessageUtil {
024:
025:            /**
026:             * Get a formatted error message. The message consists of two parts. The first part is the
027:             * error numeric Id associated with the key used to identify the message in the resource file.
028:             * For instance, suppose the error key is MyClass.ERROR_0068_TEST_ERROR. The first
029:             * part of the error msg would be "0068". The second part of the returned string
030:             * is simply the <code>msg</code> parameter.
031:             * 
032:             * Currently the format is:
033:             * error key - error msg
034:             * For instance:
035:             * "0068 - A test error message."
036:             * 
037:             * @param key String containing the key that was used to obtain the <code>msg</code> parameter
038:             * from the resource file.
039:             * @param msg String containing the message that was obtained from the resource file using
040:             * the <code>key</code> parameter.
041:             * @return String containing the formatted error message.
042:             */
043:            public static String formatErrorMessage(String key, String msg) {
044:                int end = key.indexOf(".ERROR_"); //$NON-NLS-1$
045:                end = (end < 0) ? key.length() : Math.min(end
046:                        + ".ERROR_0000".length(), key.length()); //$NON-NLS-1$
047:                return Messages
048:                        .getString(
049:                                "MESSUTIL.ERROR_FORMAT_MASK", key.substring(0, end), msg); //$NON-NLS-1$
050:            }
051:
052:            /**
053:             * Get the message from the specified resource bundle using the specified key.
054:             * 
055:             * @param bundle ResourceBundle containing the desired String
056:             * @param key String containing the key to locate the desired String in the ResourceBundle.
057:             * @return String containing the message from the specified resource bundle accessed
058:             * using the specified key
059:             */
060:            public static String getString(ResourceBundle bundle, String key) {
061:                try {
062:                    return bundle.getString(key);
063:                } catch (Exception e) {
064:                    return '!' + key + '!';
065:                }
066:            }
067:
068:            /**
069:             * Get a message from the specified resource bundle using the specified key,
070:             * and format it. see <code>formatErrorMessage</code> for details on how the
071:             * message is formatted.
072:             * 
073:             * @param bundle ResourceBundle containing the desired String
074:             * @param key String containing the key to locate the desired String in the ResourceBundle.
075:             * @return String containing the formatted message.
076:             */
077:            public static String getErrorString(ResourceBundle bundle,
078:                    String key) {
079:                return formatErrorMessage(key, getString(bundle, key));
080:            }
081:
082:            public static String getString(ResourceBundle bundle, String key,
083:                    String param1) {
084:                try {
085:                    Object[] args = { param1 };
086:                    return MessageFormat.format(bundle.getString(key), args);
087:                } catch (Exception e) {
088:                    return '!' + key + '!';
089:                }
090:            }
091:
092:            public static String getErrorString(ResourceBundle bundle,
093:                    String key, String param1) {
094:                return formatErrorMessage(key, getString(bundle, key, param1));
095:            }
096:
097:            public static String getString(ResourceBundle bundle, String key,
098:                    String param1, String param2) {
099:                try {
100:                    Object[] args = { param1, param2 };
101:                    return MessageFormat.format(bundle.getString(key), args);
102:                } catch (Exception e) {
103:                    return '!' + key + '!';
104:                }
105:            }
106:
107:            public static String getErrorString(ResourceBundle bundle,
108:                    String key, String param1, String param2) {
109:                return formatErrorMessage(key, getString(bundle, key, param1,
110:                        param2));
111:            }
112:
113:            public static String getString(ResourceBundle bundle, String key,
114:                    String param1, String param2, String param3) {
115:                try {
116:                    Object[] args = { param1, param2, param3 };
117:                    return MessageFormat.format(bundle.getString(key), args);
118:                } catch (Exception e) {
119:                    return '!' + key + '!';
120:                }
121:            }
122:
123:            public static String getErrorString(ResourceBundle bundle,
124:                    String key, String param1, String param2, String param3) {
125:                return formatErrorMessage(key, getString(bundle, key, param1,
126:                        param2, param3));
127:            }
128:
129:            public static String getString(ResourceBundle bundle, String key,
130:                    String param1, String param2, String param3, String param4) {
131:                try {
132:                    Object[] args = { param1, param2, param3, param4 };
133:                    return MessageFormat.format(bundle.getString(key), args);
134:                } catch (Exception e) {
135:                    return '!' + key + '!';
136:                }
137:            }
138:
139:            public static String getErrorString(ResourceBundle bundle,
140:                    String key, String param1, String param2, String param3,
141:                    String param4) {
142:                return formatErrorMessage(key, getString(bundle, key, param1,
143:                        param2, param3, param4));
144:            }
145:
146:            public static String formatMessage(String pattern, String param1) {
147:                try {
148:                    Object[] args = { param1 };
149:                    return MessageFormat.format(pattern, args);
150:                } catch (Exception e) {
151:                    return '!' + pattern + '!';
152:                }
153:            }
154:
155:            public static String formatMessage(String pattern, String param1,
156:                    String param2) {
157:                try {
158:                    Object[] args = { param1, param2 };
159:                    return MessageFormat.format(pattern, args);
160:                } catch (Exception e) {
161:                    return '!' + pattern + '!';
162:                }
163:
164:            }
165:
166:            public static String formatMessage(String pattern, String param1,
167:                    String param2, String param3) {
168:                try {
169:                    Object[] args = { param1, param2, param3 };
170:                    return MessageFormat.format(pattern, args);
171:                } catch (Exception e) {
172:                    return '!' + pattern + '!';
173:                }
174:            }
175:
176:            public static String formatMessage(String pattern, String param1,
177:                    String param2, String param3, String param4) {
178:                try {
179:                    Object[] args = { param1, param2, param3, param4 };
180:                    return MessageFormat.format(pattern, args);
181:                } catch (Exception e) {
182:                    return '!' + pattern + '!';
183:                }
184:            }
185:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.