DOMMessageFormatter.java
4.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
/*
* Decompiled with CFR 0_118.
*/
package com.day.jcr.vault.util.xml.xerces.dom;
import java.text.MessageFormat;
import java.util.Locale;
import java.util.MissingResourceException;
import java.util.PropertyResourceBundle;
import java.util.ResourceBundle;
public class DOMMessageFormatter {
public static final String DOM_DOMAIN = "http://www.w3.org/dom/DOMTR";
public static final String XML_DOMAIN = "http://www.w3.org/TR/1998/REC-xml-19980210";
public static final String SERIALIZER_DOMAIN = "http://apache.org/xml/serializer";
private static ResourceBundle domResourceBundle = null;
private static ResourceBundle xmlResourceBundle = null;
private static ResourceBundle serResourceBundle = null;
private static Locale locale = null;
DOMMessageFormatter() {
locale = Locale.getDefault();
}
public static String formatMessage(String domain, String key, Object[] arguments) throws MissingResourceException {
String msg2;
ResourceBundle resourceBundle = DOMMessageFormatter.getResourceBundle(domain);
if (resourceBundle == null) {
DOMMessageFormatter.init();
resourceBundle = DOMMessageFormatter.getResourceBundle(domain);
if (resourceBundle == null) {
throw new MissingResourceException("Unknown domain" + domain, null, key);
}
}
try {
msg2 = key + ": " + resourceBundle.getString(key);
if (arguments != null) {
try {
msg2 = MessageFormat.format(msg2, arguments);
}
catch (Exception e) {
msg2 = resourceBundle.getString("FormatFailed");
msg2 = msg2 + " " + resourceBundle.getString(key);
}
}
}
catch (MissingResourceException e) {
String msg2 = resourceBundle.getString("BadMessageKey");
throw new MissingResourceException(key, msg2, key);
}
if (msg2 == null) {
msg2 = key;
if (arguments.length > 0) {
StringBuffer str = new StringBuffer(msg2);
str.append('?');
for (int i = 0; i < arguments.length; ++i) {
if (i > 0) {
str.append('&');
}
str.append(String.valueOf(arguments[i]));
}
}
}
return msg2;
}
static ResourceBundle getResourceBundle(String domain) {
if (domain == "http://www.w3.org/dom/DOMTR" || domain.equals("http://www.w3.org/dom/DOMTR")) {
return domResourceBundle;
}
if (domain == "http://www.w3.org/TR/1998/REC-xml-19980210" || domain.equals("http://www.w3.org/TR/1998/REC-xml-19980210")) {
return xmlResourceBundle;
}
if (domain == "http://apache.org/xml/serializer" || domain.equals("http://apache.org/xml/serializer")) {
return serResourceBundle;
}
return null;
}
public static void init() {
if (locale != null) {
domResourceBundle = PropertyResourceBundle.getBundle("com.day.jcr.vault.fs.util.xml.apache.xerces.internal.impl.msg.DOMMessages", locale);
serResourceBundle = PropertyResourceBundle.getBundle("com.day.jcr.vault.fs.util.xml.apache.xerces.internal.impl.msg.XMLSerializerMessages", locale);
xmlResourceBundle = PropertyResourceBundle.getBundle("com.day.jcr.vault.fs.util.xml.apache.xerces.internal.impl.msg.XMLMessages", locale);
} else {
domResourceBundle = PropertyResourceBundle.getBundle("com.day.jcr.vault.fs.util.xml.apache.xerces.internal.impl.msg.DOMMessages");
serResourceBundle = PropertyResourceBundle.getBundle("com.day.jcr.vault.fs.util.xml.apache.xerces.internal.impl.msg.XMLSerializerMessages");
xmlResourceBundle = PropertyResourceBundle.getBundle("com.day.jcr.vault.fs.util.xml.apache.xerces.internal.impl.msg.XMLMessages");
}
}
public static void setLocale(Locale dlocale) {
locale = dlocale;
}
}