mirror of
https://github.com/moparisthebest/davmail
synced 2025-02-28 09:21:49 -05:00
I18N: remove Locale.ROOT not available under Java 1.5
git-svn-id: http://svn.code.sf.net/p/davmail/code/trunk@546 3d1905a2-6b24-0410-a738-b14d5a86fcbd
This commit is contained in:
parent
0a42c44863
commit
dae31fbab8
@ -11,6 +11,7 @@ import java.util.ResourceBundle;
|
||||
* Internationalization message.
|
||||
*/
|
||||
public class BundleMessage {
|
||||
public static final Locale ROOT_LOCALE = new Locale("", "");
|
||||
protected static final String MESSAGE_BUNDLE_NAME = "davmailmessages";
|
||||
protected final String key;
|
||||
private final Object[] arguments;
|
||||
@ -20,7 +21,19 @@ public class BundleMessage {
|
||||
this.arguments = arguments;
|
||||
}
|
||||
|
||||
protected ResourceBundle getBundle(Locale locale) {
|
||||
public String format() {
|
||||
return format(null);
|
||||
}
|
||||
|
||||
public String format(Locale locale) {
|
||||
return BundleMessage.format(locale, key, arguments);
|
||||
}
|
||||
|
||||
public String formatLog() {
|
||||
return format(ROOT_LOCALE);
|
||||
}
|
||||
|
||||
protected static ResourceBundle getBundle(Locale locale) {
|
||||
if (locale == null) {
|
||||
return ResourceBundle.getBundle(MESSAGE_BUNDLE_NAME);
|
||||
} else {
|
||||
@ -28,11 +41,11 @@ public class BundleMessage {
|
||||
}
|
||||
}
|
||||
|
||||
public String format() {
|
||||
return format(null);
|
||||
public static String format(String key, Object... arguments) {
|
||||
return format(null, key, arguments);
|
||||
}
|
||||
|
||||
public String format(Locale locale) {
|
||||
public static String format(Locale locale, String key, Object... arguments) {
|
||||
Object[] formattedArguments = null;
|
||||
if (arguments != null) {
|
||||
formattedArguments = new Object[arguments.length];
|
||||
@ -60,17 +73,33 @@ public class BundleMessage {
|
||||
return MessageFormat.format(getBundle(locale).getString(key), formattedArguments);
|
||||
}
|
||||
|
||||
public static String format(String key, Object... arguments) {
|
||||
return MessageFormat.format(ResourceBundle.getBundle(MESSAGE_BUNDLE_NAME).getString(key), arguments);
|
||||
}
|
||||
|
||||
public static String format(Locale locale, String key, Object... arguments) {
|
||||
return MessageFormat.format(ResourceBundle.getBundle(MESSAGE_BUNDLE_NAME, locale).getString(key), arguments);
|
||||
}
|
||||
|
||||
public static String formatLog(String key, Object... arguments) {
|
||||
return MessageFormat.format(ResourceBundle.getBundle(MESSAGE_BUNDLE_NAME, Locale.ROOT).getString(key), arguments);
|
||||
return format(ROOT_LOCALE, key, arguments);
|
||||
}
|
||||
|
||||
public static class BundleMessageList extends ArrayList<BundleMessage>{}
|
||||
public static String getExceptionLogMessage(BundleMessage message, Exception e) {
|
||||
return getExceptionMessage(message, e, ROOT_LOCALE);
|
||||
}
|
||||
|
||||
public static String getExceptionMessage(BundleMessage message, Exception e) {
|
||||
return getExceptionMessage(message, e, null);
|
||||
}
|
||||
|
||||
public static String getExceptionMessage(BundleMessage message, Exception e, Locale locale) {
|
||||
StringBuilder buffer = new StringBuilder();
|
||||
if (message != null) {
|
||||
buffer.append(message.format(locale)).append(' ');
|
||||
}
|
||||
if (e instanceof DavMailException) {
|
||||
buffer.append(((DavMailException) e).getMessage(locale));
|
||||
} else if (e.getMessage() != null) {
|
||||
buffer.append(e.getMessage());
|
||||
} else {
|
||||
buffer.append(e.toString());
|
||||
}
|
||||
return buffer.toString();
|
||||
}
|
||||
|
||||
public static class BundleMessageList extends ArrayList<BundleMessage> {
|
||||
}
|
||||
}
|
||||
|
@ -25,7 +25,7 @@ public class DavMailException extends IOException {
|
||||
}
|
||||
|
||||
public String getLogMessage() {
|
||||
return message.format(Locale.ROOT);
|
||||
return message.formatLog();
|
||||
}
|
||||
|
||||
public BundleMessage getBundleMessage() {
|
||||
|
@ -2,7 +2,6 @@ package davmail.ui.tray;
|
||||
|
||||
import davmail.Settings;
|
||||
import davmail.BundleMessage;
|
||||
import davmail.exception.DavMailException;
|
||||
import davmail.exchange.NetworkDownException;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.apache.log4j.Priority;
|
||||
@ -11,7 +10,6 @@ import javax.imageio.ImageIO;
|
||||
import java.awt.*;
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.util.Locale;
|
||||
|
||||
|
||||
/**
|
||||
@ -50,32 +48,17 @@ public class DavGatewayTray {
|
||||
}
|
||||
|
||||
protected static void displayMessage(BundleMessage message, Priority priority) {
|
||||
LOGGER.log(priority, message.format(Locale.ROOT));
|
||||
LOGGER.log(priority, message.formatLog());
|
||||
if (davGatewayTray != null) {
|
||||
davGatewayTray.displayMessage(message.format(), priority);
|
||||
}
|
||||
}
|
||||
|
||||
protected static String getExceptionMessage(BundleMessage message, Exception e, Locale locale) {
|
||||
StringBuilder buffer = new StringBuilder();
|
||||
if (message != null) {
|
||||
buffer.append(message.format(locale)).append(' ');
|
||||
}
|
||||
if (e instanceof DavMailException) {
|
||||
buffer.append(((DavMailException)e).getMessage(locale));
|
||||
} else if (e.getMessage() != null) {
|
||||
buffer.append(e.getMessage());
|
||||
} else {
|
||||
buffer.append(e.toString());
|
||||
}
|
||||
return buffer.toString();
|
||||
}
|
||||
|
||||
protected static void displayMessage(BundleMessage message, Exception e, Priority priority) {
|
||||
LOGGER.log(priority, getExceptionMessage(message, e, Locale.ROOT), e);
|
||||
LOGGER.log(priority, BundleMessage.getExceptionLogMessage(message, e), e);
|
||||
if (davGatewayTray != null
|
||||
&& (!(e instanceof NetworkDownException) || isActive())) {
|
||||
davGatewayTray.displayMessage(getExceptionMessage(message, e, null), priority);
|
||||
davGatewayTray.displayMessage(BundleMessage.getExceptionMessage(message, e), priority);
|
||||
}
|
||||
if (davGatewayTray != null && e instanceof NetworkDownException) {
|
||||
davGatewayTray.inactiveIcon();
|
||||
|
Loading…
x
Reference in New Issue
Block a user