mirror of
https://github.com/moparisthebest/davmail
synced 2025-02-28 09:21:49 -05:00
I18N: Do not apply i18n on log file
git-svn-id: http://svn.code.sf.net/p/davmail/code/trunk@543 3d1905a2-6b24-0410-a738-b14d5a86fcbd
This commit is contained in:
parent
cca0a21753
commit
871efb7831
@ -1,28 +1,59 @@
|
||||
package davmail;
|
||||
|
||||
import java.text.MessageFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Locale;
|
||||
import java.util.ResourceBundle;
|
||||
|
||||
/**
|
||||
* Internationalization message.
|
||||
*/
|
||||
public class BundleMessage {
|
||||
protected static final String MESSAGE_BUNDLE_NAME = "davmailmessages";
|
||||
protected static final ResourceBundle MESSAGE_BUNDLE = ResourceBundle.getBundle(MESSAGE_BUNDLE_NAME);
|
||||
protected static final String MESSAGE_BUNDLE_NAME = "davmailmessages";
|
||||
protected final String key;
|
||||
private final Object[] arguments;
|
||||
|
||||
public BundleMessage(String key, Object ... arguments) {
|
||||
public BundleMessage(String key, Object... arguments) {
|
||||
this.key = key;
|
||||
this.arguments = arguments;
|
||||
}
|
||||
|
||||
protected ResourceBundle getBundle(Locale locale) {
|
||||
if (locale == null) {
|
||||
return ResourceBundle.getBundle(MESSAGE_BUNDLE_NAME);
|
||||
} else {
|
||||
return ResourceBundle.getBundle(MESSAGE_BUNDLE_NAME, locale);
|
||||
}
|
||||
}
|
||||
|
||||
public String format() {
|
||||
return MessageFormat.format(MESSAGE_BUNDLE.getString(key), arguments);
|
||||
return format(null);
|
||||
}
|
||||
|
||||
public static String format(String key, Object ... arguments) {
|
||||
return MessageFormat.format(MESSAGE_BUNDLE.getString(key), arguments);
|
||||
public String format(Locale locale) {
|
||||
Object[] formattedArguments = null;
|
||||
if (arguments != null) {
|
||||
formattedArguments = new Object[arguments.length];
|
||||
for (int i = 0; i < arguments.length; i++) {
|
||||
if (arguments[i] instanceof BundleMessage) {
|
||||
formattedArguments[i] = ((BundleMessage) arguments[i]).format(locale);
|
||||
} else if (arguments[i] instanceof BundleMessageList) {
|
||||
StringBuilder buffer = new StringBuilder();
|
||||
for (BundleMessage bundleMessage:(BundleMessageList)arguments[i]) {
|
||||
buffer.append(bundleMessage.format(locale));
|
||||
}
|
||||
formattedArguments[i] = buffer.toString();
|
||||
} else {
|
||||
formattedArguments[i] = arguments[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
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 class BundleMessageList extends ArrayList<BundleMessage>{}
|
||||
}
|
||||
|
@ -77,24 +77,23 @@ public class DavGateway {
|
||||
serverList.add(new LdapServer(ldapPort));
|
||||
}
|
||||
|
||||
StringBuilder message = new StringBuilder();
|
||||
StringBuilder errorMessage = new StringBuilder();
|
||||
message.append(BundleMessage.format("LOG_DAVMAIL_GATEWAY_LISTENING"));
|
||||
BundleMessage.BundleMessageList messages = new BundleMessage.BundleMessageList();
|
||||
BundleMessage.BundleMessageList errorMessages = new BundleMessage.BundleMessageList();
|
||||
for (AbstractServer server : serverList) {
|
||||
try {
|
||||
server.bind();
|
||||
server.start();
|
||||
message.append(' ').append(BundleMessage.format("LOG_PROTOCOL_PORT", server.getProtocolName(), server.getPort()));
|
||||
messages.add(new BundleMessage("LOG_PROTOCOL_PORT", server.getProtocolName(), server.getPort()));
|
||||
} catch (BindException e) {
|
||||
errorMessage.append(' ').append(BundleMessage.format("LOG_PROTOCOL_PORT", server.getProtocolName(), server.getPort()));
|
||||
errorMessages.add(new BundleMessage("LOG_PROTOCOL_PORT", server.getProtocolName(), server.getPort()));
|
||||
} catch (IOException e) {
|
||||
errorMessage.append(' ').append(BundleMessage.format("LOG_PROTOCOL_PORT", server.getProtocolName(), server.getPort()));
|
||||
errorMessages.add(new BundleMessage("LOG_PROTOCOL_PORT", server.getProtocolName(), server.getPort()));
|
||||
}
|
||||
}
|
||||
|
||||
DavGatewayTray.info(new BundleMessage("LOG_MESSAGE", message.toString()));
|
||||
if (errorMessage.length() > 0) {
|
||||
DavGatewayTray.error(new BundleMessage("LOG_SOCKET_BIND_FAILED", errorMessage.toString()));
|
||||
DavGatewayTray.info(new BundleMessage("LOG_DAVMAIL_GATEWAY_LISTENING", messages));
|
||||
if (!errorMessages.isEmpty()) {
|
||||
DavGatewayTray.error(new BundleMessage("LOG_SOCKET_BIND_FAILED", errorMessages));
|
||||
}
|
||||
|
||||
// check for new version
|
||||
|
@ -10,6 +10,7 @@ import javax.imageio.ImageIO;
|
||||
import java.awt.*;
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.util.Locale;
|
||||
|
||||
|
||||
/**
|
||||
@ -48,130 +49,63 @@ public class DavGatewayTray {
|
||||
}
|
||||
|
||||
protected static void displayMessage(BundleMessage message, Priority priority) {
|
||||
displayMessage(message.format(), priority);
|
||||
}
|
||||
|
||||
protected static void displayMessage(String message, Priority priority) {
|
||||
LOGGER.log(priority, message);
|
||||
LOGGER.log(priority, message.format(Locale.ROOT));
|
||||
if (davGatewayTray != null) {
|
||||
davGatewayTray.displayMessage(message, priority);
|
||||
davGatewayTray.displayMessage(message.format(), priority);
|
||||
}
|
||||
}
|
||||
|
||||
protected static void displayMessage(BundleMessage message, Exception e, Priority priority) {
|
||||
displayMessage(message.format(), e, priority);
|
||||
}
|
||||
|
||||
protected static void displayMessage(String message, Exception e, Priority priority) {
|
||||
protected static String getExceptionMessage(BundleMessage message, Exception e, Locale locale) {
|
||||
StringBuilder buffer = new StringBuilder();
|
||||
if (message != null) {
|
||||
buffer.append(message).append(' ');
|
||||
buffer.append(message.format(locale)).append(' ');
|
||||
}
|
||||
if (e.getMessage() != null) {
|
||||
buffer.append(e.getMessage());
|
||||
} else {
|
||||
buffer.append(e.toString());
|
||||
}
|
||||
LOGGER.log(priority, buffer.toString(), e);
|
||||
return buffer.toString();
|
||||
}
|
||||
|
||||
protected static void displayMessage(BundleMessage message, Exception e, Priority priority) {
|
||||
LOGGER.log(priority, getExceptionMessage(message, e, Locale.ROOT), e);
|
||||
if (davGatewayTray != null
|
||||
&& (!(e instanceof NetworkDownException) || isActive())) {
|
||||
davGatewayTray.displayMessage(buffer.toString(), priority);
|
||||
davGatewayTray.displayMessage(getExceptionMessage(message, e, null), priority);
|
||||
}
|
||||
if (davGatewayTray != null && e instanceof NetworkDownException) {
|
||||
davGatewayTray.inactiveIcon();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated
|
||||
* @param message
|
||||
*/
|
||||
public static void debug(String message) {
|
||||
displayMessage(message, Priority.DEBUG);
|
||||
}
|
||||
|
||||
public static void debug(BundleMessage message) {
|
||||
displayMessage(message, Priority.DEBUG);
|
||||
}
|
||||
/**
|
||||
* @deprecated
|
||||
* @param message
|
||||
*/
|
||||
|
||||
public static void info(String message) {
|
||||
displayMessage(message, Priority.INFO);
|
||||
}
|
||||
|
||||
public static void info(BundleMessage message) {
|
||||
displayMessage(message, Priority.INFO);
|
||||
}
|
||||
/**
|
||||
* @deprecated
|
||||
* @param message
|
||||
*/
|
||||
|
||||
public static void warn(String message) {
|
||||
displayMessage(message, Priority.WARN);
|
||||
}
|
||||
|
||||
public static void warn(BundleMessage message) {
|
||||
displayMessage(message, Priority.WARN);
|
||||
}
|
||||
/**
|
||||
* @deprecated
|
||||
* @param message
|
||||
*/
|
||||
|
||||
public static void error(String message) {
|
||||
displayMessage(message, Priority.ERROR);
|
||||
}
|
||||
|
||||
public static void error(BundleMessage message) {
|
||||
displayMessage(message, Priority.ERROR);
|
||||
}
|
||||
|
||||
public static void error(Exception e) {
|
||||
displayMessage((String) null, e, Priority.ERROR);
|
||||
}
|
||||
/**
|
||||
* @deprecated
|
||||
* @param message
|
||||
*/
|
||||
|
||||
public static void debug(String message, Exception e) {
|
||||
displayMessage(message, e, Priority.DEBUG);
|
||||
displayMessage(null, e, Priority.ERROR);
|
||||
}
|
||||
|
||||
public static void debug(BundleMessage message, Exception e) {
|
||||
displayMessage(message, e, Priority.DEBUG);
|
||||
}
|
||||
/**
|
||||
* @deprecated
|
||||
* @param message
|
||||
*/
|
||||
|
||||
public static void info(String message, Exception e) {
|
||||
displayMessage(message, e, Priority.INFO);
|
||||
}
|
||||
/**
|
||||
* @deprecated
|
||||
* @param message
|
||||
*/
|
||||
|
||||
public static void warn(String message, Exception e) {
|
||||
displayMessage(message, e, Priority.WARN);
|
||||
}
|
||||
|
||||
public static void warn(BundleMessage message, Exception e) {
|
||||
displayMessage(message, e, Priority.WARN);
|
||||
}
|
||||
/**
|
||||
* @deprecated
|
||||
* @param message
|
||||
*/
|
||||
public static void error(String message, Exception e) {
|
||||
displayMessage(message, e, Priority.ERROR);
|
||||
}
|
||||
|
||||
public static void error(BundleMessage message, Exception e) {
|
||||
displayMessage(message, e, Priority.ERROR);
|
||||
|
@ -2,7 +2,7 @@ LOG_CLIENT_CLOSED_CONNECTION=Client closed connection
|
||||
LOG_CLOSE_CONNECTION_ON_TIMEOUT=Closing connection on timeout
|
||||
LOG_CONNECTION_CLOSED=Connection closed
|
||||
LOG_CONNECTION_FROM=Connection from {0} on port {1}
|
||||
LOG_DAVMAIL_GATEWAY_LISTENING=DavMail Gateway listening on
|
||||
LOG_DAVMAIL_GATEWAY_LISTENING=DavMail Gateway listening on {0}
|
||||
LOG_DAVMAIL_STARTED=DavMail Gateway started
|
||||
LOG_ERROR_CLOGING_CONFIG_FILE=Error closing configuration file
|
||||
LOG_ERROR_LOADING_OSXADAPTER=Error while loading the OSXAdapter
|
||||
@ -55,7 +55,7 @@ LOG_LISTING_EVENT=Listing event {0}/{1}
|
||||
LOG_MESSAGE={0}
|
||||
LOG_NEW_VERSION_AVAILABLE=A new version ({0}) of DavMail Gateway is available !
|
||||
LOG_OPEN_LINK_NOT_SUPPORTED=Open link not supported (tried AWT Desktop and SWT Program)
|
||||
LOG_PROTOCOL_PORT={0} port {1,number,#}
|
||||
LOG_PROTOCOL_PORT= {0} port {1,number,# }
|
||||
LOG_READ_CLIENT_AUTHORIZATION=< Authorization: ********
|
||||
LOG_READ_CLIENT_AUTH_PLAIN=< AUTH PLAIN ********
|
||||
LOG_READ_CLIENT_LINE=< {0}
|
||||
|
@ -2,7 +2,7 @@ LOG_CLIENT_CLOSED_CONNECTION=Connection ferm
|
||||
LOG_CLOSE_CONNECTION_ON_TIMEOUT=Connection fermée sur expiration
|
||||
LOG_CONNECTION_CLOSED=Connection fermée
|
||||
LOG_CONNECTION_FROM=Connection de {0} sur le port {1}
|
||||
LOG_DAVMAIL_GATEWAY_LISTENING=Passerelle DavMail en écoute sur
|
||||
LOG_DAVMAIL_GATEWAY_LISTENING=Passerelle DavMail en écoute sur {0}
|
||||
LOG_DAVMAIL_STARTED=Passerelle DavMail démarrée
|
||||
LOG_ERROR_CLOGING_CONFIG_FILE=Erreur à la fermeture du fichier de configuration
|
||||
LOG_ERROR_LOADING_OSXADAPTER=Erreur au chargement de OSXAdapter
|
||||
@ -55,7 +55,7 @@ LOG_LISTING_EVENT=Liste
|
||||
LOG_MESSAGE={0}
|
||||
LOG_NEW_VERSION_AVAILABLE=Une nouvelle version ({0}) de la Passerelle DavMail est disponible !
|
||||
LOG_OPEN_LINK_NOT_SUPPORTED=Ouverture de lien impossible (avec AWT Desktop et SWT Program)
|
||||
LOG_PROTOCOL_PORT=port {0} : {1,number,#}
|
||||
LOG_PROTOCOL_PORT= port {0} : {1,number,# }
|
||||
LOG_READ_CLIENT_AUTHORIZATION=< Authorization: ********
|
||||
LOG_READ_CLIENT_AUTH_PLAIN=< AUTH PLAIN ********
|
||||
LOG_READ_CLIENT_LINE=< {0}
|
||||
|
Loading…
x
Reference in New Issue
Block a user