Permalink
Browse files

- Added jg-messages*.properties files for English and German (https:/…

…/issues.jboss.org/browse/JGRP-1475)

- Added helper methods in Util to get i8n messages out of the resource bundle (https://issues.jboss.org/browse/JGRP-1475)
- Converting some exceptions to use internationalized messages (https://issues.jboss.org/browse/JGRP-1475)
  • Loading branch information...
1 parent 09c2b2d commit d676e9b260762d0b2c448d8438b7e925db714fd7 @belaban committed Sep 18, 2012
@@ -0,0 +1,6 @@
+
+ConfigurationError = [JGRP00001] configuration error: the following properties in {0} are not recognized: {1}
+ProtocolLoadError = [JGRP00002] unable to load protocol {0} (either with relative - {0} - or absolute - {1} - class name)
+FileNotFound = [JGRP00003] file \"{0}\" not found
+ParseError = [JGRP00004] parsing failure; the XML document is not correct: {0}
+ProtocolCreateError = [JGRP00005] failure creating protocol {0}: {1}
@@ -0,0 +1,7 @@
+ConfigurationError = [JGRP00001] Konfigurationsfehler: die folgenden Parameter in {0} sind nicht erlaubt: {1}
+ProtocolLoadError = [JGRP00002] Fehler beim Laden des Protokolls {0} (sowohl mit relativem - {0} - als auch absolutem - {1} - Pfadnamen)
+FileNotFound = [JGRP00003] Datei \"{0}\" nicht gefunden
+ParseError = [JGRP00004] Fehler beim Parsen von XML; das Dokument ist nicht korrekt: {0}
+ProtocolCreateError = [JGRP00005] Protokoll {0} konnte nicht instantiiert werden: {1}
+
+
@@ -208,6 +208,8 @@ public static InputStream getConfigStream(Object properties) throws IOException
static XmlConfigurator getXmlConfigurator(String properties) throws IOException {
XmlConfigurator returnValue=null;
InputStream configStream=getConfigStream(properties);
+ if(configStream == null && properties.endsWith(".xml"))
+ throw new FileNotFoundException(Util.getMessage("FileNotFound", properties));
if (configStream != null) {
checkJAXPAvailability();
@@ -56,11 +56,7 @@ public static XmlConfigurator getInstance(URL url, Boolean validate) throws java
try {
return getInstance(is, validate);
} finally {
- try {
- is.close();
- } catch (IOException e) {
- log.warn("Failed to close InputStream", e);
- }
+ Util.close(is);
}
}
@@ -174,13 +170,7 @@ public void error(SAXParseException exception) throws SAXException {
Element configElement = document.getDocumentElement();
return parse(configElement);
} catch (Exception x) {
- if (x instanceof java.io.IOException)
- throw (java.io.IOException) x;
- else {
- IOException tmp = new IOException();
- tmp.initCause(x);
- throw tmp;
- }
+ throw new IOException(Util.getMessage("ParseError", x.getLocalizedMessage()));
}
}
@@ -426,17 +426,12 @@ protected static Protocol createLayer(ProtocolStack stack, ProtocolConfiguration
}
catch(ClassNotFoundException e) {
}
- if(clazz == null) {
- throw new Exception("unable to load class for protocol " + protocol_name +
- " (either as an absolute - " + protocol_name + " - or relative - " +
- defaultProtocolName + " - package name)!");
- }
+ if(clazz == null)
+ throw new Exception(Util.getMessage("ProtocolLoadError", protocol_name, defaultProtocolName));
}
try {
retval=(Protocol)clazz.newInstance();
- if(retval == null)
- throw new Exception("creation of instance for protocol " + protocol_name + "failed !");
retval.setProtocolStack(stack);
removeDeprecatedProperties(retval, properties);
@@ -460,15 +455,11 @@ else if (ordered instanceof Method) {
}
}
- if(!properties.isEmpty()) {
- throw new IllegalArgumentException("the following properties in " + protocol_name
- + " are not recognized: " + properties);
- }
+ if(!properties.isEmpty())
+ throw new IllegalArgumentException(Util.getMessage("ConfigurationError", protocol_name, properties));
}
- catch(InstantiationException inst_ex) {
- log.error("an instance of " + protocol_name + " could not be created. Please check that it implements" +
- " interface Protocol and that is has a public empty constructor !");
- throw inst_ex;
+ catch(Throwable t) {
+ throw new Exception(Util.getMessage("ProtocolCreateError",protocol_name,t.getLocalizedMessage()));
}
return retval;
}
@@ -31,6 +31,7 @@
import java.nio.channels.WritableByteChannel;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
+import java.text.MessageFormat;
import java.text.NumberFormat;
import java.util.*;
import java.util.concurrent.*;
@@ -87,9 +88,14 @@
private static StackType ip_stack_type=_getIpStackType();
+ protected static ResourceBundle resource_bundle;
+
+
static {
+ resource_bundle=ResourceBundle.getBundle("jg-messages",Locale.getDefault(),Thread.currentThread().getContextClassLoader());
+
/* Trying to get value of resolve_dns. PropertyPermission not granted if
- * running in an untrusted environment with JNLP */
+ * running in an untrusted environment with JNLP */
try {
resolve_dns=Boolean.valueOf(System.getProperty("resolve.dns","false"));
}
@@ -205,6 +211,15 @@ public static String bold(String msg) {
return sb.toString();
}
+ public static String getMessage(String key) {
+ return key != null? resource_bundle.getString(key) : null;
+ }
+
+ public static String getMessage(String key, Object ... args) {
+ String msg=getMessage(key);
+ return msg != null? MessageFormat.format(msg, args) : null;
+ }
+
/**
* Blocks until all channels have the same view

0 comments on commit d676e9b

Please sign in to comment.