6
|
1 |
/*
|
|
2 |
* reserved comment block
|
|
3 |
* DO NOT REMOVE OR ALTER!
|
|
4 |
*/
|
|
5 |
/*
|
|
6 |
* Copyright 1999-2004 The Apache Software Foundation.
|
|
7 |
*
|
|
8 |
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
9 |
* you may not use this file except in compliance with the License.
|
|
10 |
* You may obtain a copy of the License at
|
|
11 |
*
|
|
12 |
* http://www.apache.org/licenses/LICENSE-2.0
|
|
13 |
*
|
|
14 |
* Unless required by applicable law or agreed to in writing, software
|
|
15 |
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
16 |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
17 |
* See the License for the specific language governing permissions and
|
|
18 |
* limitations under the License.
|
|
19 |
*/
|
|
20 |
/*
|
|
21 |
* $Id: XPATHMessages.java,v 1.2.4.1 2005/09/01 14:57:34 pvedula Exp $
|
|
22 |
*/
|
|
23 |
package com.sun.org.apache.xpath.internal.res;
|
|
24 |
|
16953
|
25 |
import com.sun.org.apache.bcel.internal.util.SecuritySupport;
|
|
26 |
import com.sun.org.apache.xml.internal.res.XMLMessages;
|
6
|
27 |
import java.util.ListResourceBundle;
|
|
28 |
|
|
29 |
/**
|
|
30 |
* A utility class for issuing XPath error messages.
|
16953
|
31 |
*
|
6
|
32 |
* @xsl.usage internal
|
|
33 |
*/
|
16953
|
34 |
public class XPATHMessages extends XMLMessages {
|
6
|
35 |
|
16953
|
36 |
/**
|
|
37 |
* The language specific resource object for XPath messages.
|
|
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";
|
6
|
45 |
|
16953
|
46 |
/**
|
|
47 |
* Creates a message from the specified key and replacement arguments,
|
|
48 |
* localized to the given locale.
|
|
49 |
*
|
|
50 |
* @param msgKey The key for the message text.
|
|
51 |
* @param args The arguments to be used as replacement text in the message
|
|
52 |
* created.
|
|
53 |
*
|
|
54 |
* @return The formatted message string.
|
|
55 |
*/
|
|
56 |
public static final String createXPATHMessage(String msgKey, Object args[]) //throws Exception
|
6
|
57 |
{
|
16953
|
58 |
if (XPATHBundle == null) {
|
|
59 |
XPATHBundle = SecuritySupport.getResourceBundle(XPATH_ERROR_RESOURCES);
|
|
60 |
}
|
6
|
61 |
|
16953
|
62 |
if (XPATHBundle != null) {
|
|
63 |
return createXPATHMsg(XPATHBundle, msgKey, args);
|
|
64 |
} else {
|
|
65 |
return "Could not load any resource bundles.";
|
|
66 |
}
|
6
|
67 |
}
|
|
68 |
|
16953
|
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
|
|
80 |
{
|
|
81 |
if (XPATHBundle == null) {
|
|
82 |
XPATHBundle = SecuritySupport.getResourceBundle(XPATH_ERROR_RESOURCES);
|
|
83 |
}
|
6
|
84 |
|
16953
|
85 |
if (XPATHBundle != null) {
|
|
86 |
return createXPATHMsg(XPATHBundle, msgKey, args);
|
|
87 |
} else {
|
|
88 |
return "Could not load any resource bundles.";
|
|
89 |
}
|
6
|
90 |
}
|
|
91 |
|
16953
|
92 |
/**
|
|
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
|
6
|
105 |
{
|
|
106 |
|
16953
|
107 |
String fmsg = null;
|
|
108 |
boolean throwex = false;
|
|
109 |
String msg = null;
|
6
|
110 |
|
16953
|
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;
|
6
|
118 |
}
|
|
119 |
|
16953
|
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;
|
6
|
148 |
}
|
|
149 |
}
|