Source Code Cross Referenced for XMLMessages.java in  » XML » xalan » org » apache » xml » res » 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 » XML » xalan » org.apache.xml.res 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 1999-2004 The Apache Software Foundation.
003:         *
004:         * Licensed under the Apache License, Version 2.0 (the "License");
005:         * you may not use this file except in compliance with the License.
006:         * You may obtain a copy of the License at
007:         *
008:         *     http://www.apache.org/licenses/LICENSE-2.0
009:         *
010:         * Unless required by applicable law or agreed to in writing, software
011:         * distributed under the License is distributed on an "AS IS" BASIS,
012:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013:         * See the License for the specific language governing permissions and
014:         * limitations under the License.
015:         */
016:        /*
017:         * $Id: XMLMessages.java,v 1.7 2005/01/23 00:52:40 mcnamara Exp $
018:         */
019:        package org.apache.xml.res;
020:
021:        import java.util.ListResourceBundle;
022:        import java.util.Locale;
023:        import java.util.MissingResourceException;
024:        import java.util.ResourceBundle;
025:
026:        /**
027:         * A utility class for issuing XML error messages.
028:         * @xsl.usage internal
029:         */
030:        public class XMLMessages {
031:
032:            /** The local object to use.  */
033:            protected Locale fLocale = Locale.getDefault();
034:
035:            /** The language specific resource object for XML messages.  */
036:            private static ListResourceBundle XMLBundle = null;
037:
038:            /** The class name of the XML error message string table.    */
039:            private static final String XML_ERROR_RESOURCES = "org.apache.xml.res.XMLErrorResources";
040:
041:            /** String to use if a bad message code is used. */
042:            protected static final String BAD_CODE = "BAD_CODE";
043:
044:            /** String to use if the message format operation failed.  */
045:            protected static final String FORMAT_FAILED = "FORMAT_FAILED";
046:
047:            /**
048:             * Set the Locale object to use.
049:             * 
050:             * @param locale non-null reference to Locale object.
051:             */
052:            public void setLocale(Locale locale) {
053:                fLocale = locale;
054:            }
055:
056:            /**
057:             * Get the Locale object that is being used.
058:             * 
059:             * @return non-null reference to Locale object.
060:             */
061:            public Locale getLocale() {
062:                return fLocale;
063:            }
064:
065:            /**
066:             * Creates a message from the specified key and replacement
067:             * arguments, localized to the given locale.
068:             *
069:             * @param msgKey    The key for the message text.
070:             * @param args      The arguments to be used as replacement text
071:             *                  in the message created.
072:             *
073:             * @return The formatted message string.
074:             */
075:            public static final String createXMLMessage(String msgKey,
076:                    Object args[]) {
077:                if (XMLBundle == null)
078:                    XMLBundle = loadResourceBundle(XML_ERROR_RESOURCES);
079:
080:                if (XMLBundle != null) {
081:                    return createMsg(XMLBundle, msgKey, args);
082:                } else
083:                    return "Could not load any resource bundles.";
084:            }
085:
086:            /**
087:             * Creates a message from the specified key and replacement
088:             * arguments, localized to the given locale.
089:             *
090:             * @param fResourceBundle The resource bundle to use.
091:             * @param msgKey  The message key to use.
092:             * @param args      The arguments to be used as replacement text
093:             *                  in the message created.
094:             *
095:             * @return The formatted message string.
096:             */
097:            public static final String createMsg(
098:                    ListResourceBundle fResourceBundle, String msgKey,
099:                    Object args[]) //throws Exception
100:            {
101:
102:                String fmsg = null;
103:                boolean throwex = false;
104:                String msg = null;
105:
106:                if (msgKey != null)
107:                    msg = fResourceBundle.getString(msgKey);
108:
109:                if (msg == null) {
110:                    msg = fResourceBundle.getString(BAD_CODE);
111:                    throwex = true;
112:                }
113:
114:                if (args != null) {
115:                    try {
116:
117:                        // Do this to keep format from crying.
118:                        // This is better than making a bunch of conditional
119:                        // code all over the place.
120:                        int n = args.length;
121:
122:                        for (int i = 0; i < n; i++) {
123:                            if (null == args[i])
124:                                args[i] = "";
125:                        }
126:
127:                        fmsg = java.text.MessageFormat.format(msg, args);
128:                    } catch (Exception e) {
129:                        fmsg = fResourceBundle.getString(FORMAT_FAILED);
130:                        fmsg += " " + msg;
131:                    }
132:                } else
133:                    fmsg = msg;
134:
135:                if (throwex) {
136:                    throw new RuntimeException(fmsg);
137:                }
138:
139:                return fmsg;
140:            }
141:
142:            /**
143:             * Return a named ResourceBundle for a particular locale.  This method mimics the behavior
144:             * of ResourceBundle.getBundle().
145:             *
146:             * @param className The class name of the resource bundle.
147:             * @return the ResourceBundle
148:             * @throws MissingResourceException
149:             */
150:            public static ListResourceBundle loadResourceBundle(String className)
151:                    throws MissingResourceException {
152:                Locale locale = Locale.getDefault();
153:
154:                try {
155:                    return (ListResourceBundle) ResourceBundle.getBundle(
156:                            className, locale);
157:                } catch (MissingResourceException e) {
158:                    try // try to fall back to en_US if we can't load
159:                    {
160:
161:                        // Since we can't find the localized property file,
162:                        // fall back to en_US.
163:                        return (ListResourceBundle) ResourceBundle.getBundle(
164:                                className, new Locale("en", "US"));
165:                    } catch (MissingResourceException e2) {
166:
167:                        // Now we are really in trouble.
168:                        // very bad, definitely very bad...not going to get very far
169:                        throw new MissingResourceException(
170:                                "Could not load any resource bundles."
171:                                        + className, className, "");
172:                    }
173:                }
174:            }
175:
176:            /**
177:             * Return the resource file suffic for the indicated locale
178:             * For most locales, this will be based the language code.  However
179:             * for Chinese, we do distinguish between Taiwan and PRC
180:             *
181:             * @param locale the locale
182:             * @return an String suffix which can be appended to a resource name
183:             */
184:            protected static String getResourceSuffix(Locale locale) {
185:
186:                String suffix = "_" + locale.getLanguage();
187:                String country = locale.getCountry();
188:
189:                if (country.equals("TW"))
190:                    suffix += "_" + country;
191:
192:                return suffix;
193:            }
194:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.