20 /* |
20 /* |
21 * $Id: XPATHMessages.java,v 1.2.4.1 2005/09/01 14:57:34 pvedula Exp $ |
21 * $Id: XPATHMessages.java,v 1.2.4.1 2005/09/01 14:57:34 pvedula Exp $ |
22 */ |
22 */ |
23 package com.sun.org.apache.xpath.internal.res; |
23 package com.sun.org.apache.xpath.internal.res; |
24 |
24 |
|
25 import com.sun.org.apache.bcel.internal.util.SecuritySupport; |
|
26 import com.sun.org.apache.xml.internal.res.XMLMessages; |
25 import java.util.ListResourceBundle; |
27 import java.util.ListResourceBundle; |
26 |
|
27 import com.sun.org.apache.xml.internal.res.XMLMessages; |
|
28 |
28 |
29 /** |
29 /** |
30 * A utility class for issuing XPath error messages. |
30 * A utility class for issuing XPath error messages. |
|
31 * |
31 * @xsl.usage internal |
32 * @xsl.usage internal |
32 */ |
33 */ |
33 public class XPATHMessages extends XMLMessages |
34 public class XPATHMessages extends XMLMessages { |
34 { |
|
35 /** The language specific resource object for XPath messages. */ |
|
36 private static ListResourceBundle XPATHBundle = null; |
|
37 |
35 |
38 /** The class name of the XPath error message string table. */ |
36 /** |
39 private static final String XPATH_ERROR_RESOURCES = |
37 * The language specific resource object for XPath messages. |
40 "com.sun.org.apache.xpath.internal.res.XPATHErrorResources"; |
38 */ |
|
39 private static ListResourceBundle XPATHBundle = null; |
|
40 /** |
|
41 * The class name of the XPath error message string table. |
|
42 */ |
|
43 private static final String XPATH_ERROR_RESOURCES = |
|
44 "com.sun.org.apache.xpath.internal.res.XPATHErrorResources"; |
41 |
45 |
42 /** |
46 /** |
43 * Creates a message from the specified key and replacement |
47 * Creates a message from the specified key and replacement arguments, |
44 * arguments, localized to the given locale. |
48 * localized to the given locale. |
45 * |
49 * |
46 * @param msgKey The key for the message text. |
50 * @param msgKey The key for the message text. |
47 * @param args The arguments to be used as replacement text |
51 * @param args The arguments to be used as replacement text in the message |
48 * in the message created. |
52 * created. |
49 * |
53 * |
50 * @return The formatted message string. |
54 * @return The formatted message string. |
51 */ |
55 */ |
52 public static final String createXPATHMessage(String msgKey, Object args[]) //throws Exception |
56 public static final String createXPATHMessage(String msgKey, Object args[]) //throws Exception |
53 { |
57 { |
54 if (XPATHBundle == null) |
58 if (XPATHBundle == null) { |
55 XPATHBundle = loadResourceBundle(XPATH_ERROR_RESOURCES); |
59 XPATHBundle = SecuritySupport.getResourceBundle(XPATH_ERROR_RESOURCES); |
|
60 } |
56 |
61 |
57 if (XPATHBundle != null) |
62 if (XPATHBundle != null) { |
58 { |
63 return createXPATHMsg(XPATHBundle, msgKey, args); |
59 return createXPATHMsg(XPATHBundle, msgKey, args); |
64 } else { |
60 } |
65 return "Could not load any resource bundles."; |
61 else |
66 } |
62 return "Could not load any resource bundles."; |
|
63 } |
|
64 |
|
65 /** |
|
66 * Creates a message from the specified key and replacement |
|
67 * arguments, localized to the given locale. |
|
68 * |
|
69 * @param msgKey The key for the message text. |
|
70 * @param args The arguments to be used as replacement text |
|
71 * in the message created. |
|
72 * |
|
73 * @return The formatted warning string. |
|
74 */ |
|
75 public static final String createXPATHWarning(String msgKey, Object args[]) //throws Exception |
|
76 { |
|
77 if (XPATHBundle == null) |
|
78 XPATHBundle = loadResourceBundle(XPATH_ERROR_RESOURCES); |
|
79 |
|
80 if (XPATHBundle != null) |
|
81 { |
|
82 return createXPATHMsg(XPATHBundle, msgKey, args); |
|
83 } |
|
84 else |
|
85 return "Could not load any resource bundles."; |
|
86 } |
|
87 |
|
88 /** |
|
89 * Creates a message from the specified key and replacement |
|
90 * arguments, localized to the given locale. |
|
91 * |
|
92 * @param fResourceBundle The resource bundle to use. |
|
93 * @param msgKey The message key to use. |
|
94 * @param args The arguments to be used as replacement text |
|
95 * in the message created. |
|
96 * |
|
97 * @return The formatted message string. |
|
98 */ |
|
99 public static final String createXPATHMsg(ListResourceBundle fResourceBundle, |
|
100 String msgKey, Object args[]) //throws Exception |
|
101 { |
|
102 |
|
103 String fmsg = null; |
|
104 boolean throwex = false; |
|
105 String msg = null; |
|
106 |
|
107 if (msgKey != null) |
|
108 msg = fResourceBundle.getString(msgKey); |
|
109 |
|
110 if (msg == null) |
|
111 { |
|
112 msg = fResourceBundle.getString(XPATHErrorResources.BAD_CODE); |
|
113 throwex = true; |
|
114 } |
67 } |
115 |
68 |
116 if (args != null) |
69 /** |
|
70 * Creates a message from the specified key and replacement arguments, |
|
71 * localized to the given locale. |
|
72 * |
|
73 * @param msgKey The key for the message text. |
|
74 * @param args The arguments to be used as replacement text in the message |
|
75 * created. |
|
76 * |
|
77 * @return The formatted warning string. |
|
78 */ |
|
79 public static final String createXPATHWarning(String msgKey, Object args[]) //throws Exception |
117 { |
80 { |
118 try |
81 if (XPATHBundle == null) { |
119 { |
82 XPATHBundle = SecuritySupport.getResourceBundle(XPATH_ERROR_RESOURCES); |
120 |
|
121 // Do this to keep format from crying. |
|
122 // This is better than making a bunch of conditional |
|
123 // code all over the place. |
|
124 int n = args.length; |
|
125 |
|
126 for (int i = 0; i < n; i++) |
|
127 { |
|
128 if (null == args[i]) |
|
129 args[i] = ""; |
|
130 } |
83 } |
131 |
84 |
132 fmsg = java.text.MessageFormat.format(msg, args); |
85 if (XPATHBundle != null) { |
133 } |
86 return createXPATHMsg(XPATHBundle, msgKey, args); |
134 catch (Exception e) |
87 } else { |
135 { |
88 return "Could not load any resource bundles."; |
136 fmsg = fResourceBundle.getString(XPATHErrorResources.FORMAT_FAILED); |
89 } |
137 fmsg += " " + msg; |
|
138 } |
|
139 } |
|
140 else |
|
141 fmsg = msg; |
|
142 |
|
143 if (throwex) |
|
144 { |
|
145 throw new RuntimeException(fmsg); |
|
146 } |
90 } |
147 |
91 |
148 return fmsg; |
92 /** |
149 } |
93 * Creates a message from the specified key and replacement arguments, |
|
94 * localized to the given locale. |
|
95 * |
|
96 * @param fResourceBundle The resource bundle to use. |
|
97 * @param msgKey The message key to use. |
|
98 * @param args The arguments to be used as replacement text in the message |
|
99 * created. |
|
100 * |
|
101 * @return The formatted message string. |
|
102 */ |
|
103 public static final String createXPATHMsg(ListResourceBundle fResourceBundle, |
|
104 String msgKey, Object args[]) //throws Exception |
|
105 { |
150 |
106 |
|
107 String fmsg = null; |
|
108 boolean throwex = false; |
|
109 String msg = null; |
|
110 |
|
111 if (msgKey != null) { |
|
112 msg = fResourceBundle.getString(msgKey); |
|
113 } |
|
114 |
|
115 if (msg == null) { |
|
116 msg = fResourceBundle.getString(XPATHErrorResources.BAD_CODE); |
|
117 throwex = true; |
|
118 } |
|
119 |
|
120 if (args != null) { |
|
121 try { |
|
122 |
|
123 // Do this to keep format from crying. |
|
124 // This is better than making a bunch of conditional |
|
125 // code all over the place. |
|
126 int n = args.length; |
|
127 |
|
128 for (int i = 0; i < n; i++) { |
|
129 if (null == args[i]) { |
|
130 args[i] = ""; |
|
131 } |
|
132 } |
|
133 |
|
134 fmsg = java.text.MessageFormat.format(msg, args); |
|
135 } catch (Exception e) { |
|
136 fmsg = fResourceBundle.getString(XPATHErrorResources.FORMAT_FAILED); |
|
137 fmsg += " " + msg; |
|
138 } |
|
139 } else { |
|
140 fmsg = msg; |
|
141 } |
|
142 |
|
143 if (throwex) { |
|
144 throw new RuntimeException(fmsg); |
|
145 } |
|
146 |
|
147 return fmsg; |
|
148 } |
151 } |
149 } |