[lsc-changes] r521 - in lsc/trunk/src: main/java/org/lsc main/java/org/lsc/utils main/resources test/java/org/lsc test/java/org/lsc/utils/output

rschermesser at lsc-project.org rschermesser at lsc-project.org
Mon Nov 30 21:20:33 CET 2009


Author: rschermesser
Date: 2009-11-30 21:20:33 +0100 (Mon, 30 Nov 2009)
New Revision: 521

Removed:
   lsc/trunk/src/main/java/org/lsc/utils/I18n.java
   lsc/trunk/src/main/resources/lsc_en_US
   lsc/trunk/src/main/resources/lsc_fr_FR
Modified:
   lsc/trunk/src/main/java/org/lsc/AbstractSynchronize.java
   lsc/trunk/src/test/java/org/lsc/Ldap2LdapSyncTest.java
   lsc/trunk/src/test/java/org/lsc/utils/output/LdifLayoutTest.java
Log:
Removing i18n logging messages

Modified: lsc/trunk/src/main/java/org/lsc/AbstractSynchronize.java
===================================================================
--- lsc/trunk/src/main/java/org/lsc/AbstractSynchronize.java	2009-11-30 20:18:03 UTC (rev 520)
+++ lsc/trunk/src/main/java/org/lsc/AbstractSynchronize.java	2009-11-30 20:20:33 UTC (rev 521)
@@ -46,7 +46,6 @@
 package org.lsc;
 
 import java.util.HashMap;
-import java.util.Iterator;
 import java.util.Map;
 import java.util.Map.Entry;
 
@@ -69,7 +68,6 @@
 import org.lsc.jndi.JndiModifications;
 import org.lsc.jndi.JndiServices;
 import org.lsc.service.ISrcService;
-import org.lsc.utils.I18n;
 import org.lsc.utils.JScriptEvaluator;
 import org.lsc.utils.LSCStructuralLogger;
 import org.slf4j.Logger;
@@ -262,14 +260,16 @@
 			}
 		}
 
-		String totalsLogMessage = I18n.getMessage(null,
-						"org.lsc.messages.NB_CHANGES", new Object[]{
+		String totalsLogMessage = "All entries: {}, to modify entries: {}, modified entries: {}, errors: {}";
+
+		if (countError > 0) {
+			LSCStructuralLogger.GLOBAL.error(totalsLogMessage, new Object[]{
 							countAll, countInitiated, countCompleted,
 							countError});
-		if (countError > 0) {
-			LSCStructuralLogger.GLOBAL.error(totalsLogMessage);
 		} else {
-			LSCStructuralLogger.GLOBAL.warn(totalsLogMessage);
+			LSCStructuralLogger.GLOBAL.warn(totalsLogMessage, new Object[]{
+							countAll, countInitiated, countCompleted,
+							countError});
 		}
 	}
 
@@ -414,14 +414,15 @@
 			}
 		}
 
-		String totalsLogMessage = I18n.getMessage(null,
-						"org.lsc.messages.NB_CHANGES", new Object[]{
+		String totalsLogMessage = "All entries: {}, to modify entries: {}, modified entries: {}, errors: {}";
+		if (countError > 0) {
+			LSCStructuralLogger.DESTINATION.error(totalsLogMessage, new Object[]{
 							countAll, countInitiated, countCompleted,
 							countError});
-		if (countError > 0) {
-			LSCStructuralLogger.DESTINATION.error(totalsLogMessage);
 		} else {
-			LSCStructuralLogger.DESTINATION.warn(totalsLogMessage);
+			LSCStructuralLogger.DESTINATION.warn(totalsLogMessage, new Object[]{
+							countAll, countInitiated, countCompleted,
+							countError});
 		}
 	}
 
@@ -445,9 +446,9 @@
 			str = "";
 		}
 
-		LOGGER.error(I18n.getMessage(null,
-						"org.lsc.messages.SYNC_ERROR", new Object[]{
-							(jm != null ? jm.getDistinguishName() : ""), str, "", except}), except);
+		LOGGER.error("Error while synchronizing ID {}: {}\n{}", new Object[]{
+							(jm != null ? jm.getDistinguishName() : ""), str, "", except});
+		LOGGER.debug(except.toString(), except);
 
 		if (jm != null) {
 			LOGGER.error(jm.toString());
@@ -468,37 +469,28 @@
 					final String syncName) {
 		switch (jm.getOperation()) {
 			case ADD_ENTRY:
-				LSCStructuralLogger.DESTINATION.info(I18n.getMessage(null,
-								"org.lsc.messages.ADD_ENTRY", new Object[]{jm.getDistinguishName(),
-									syncName}));
-
+				LSCStructuralLogger.DESTINATION.info("# Adding new entry {} for {}",
+								jm.getDistinguishName(), syncName);
 				break;
 
 			case MODIFY_ENTRY:
-				LSCStructuralLogger.DESTINATION.info(I18n.getMessage(null,
-								"org.lsc.messages.UPDATE_ENTRY", new Object[]{
-									jm.getDistinguishName(), syncName}));
-
+				LSCStructuralLogger.DESTINATION.info("# Updating entry {} for {}",
+								jm.getDistinguishName(), syncName);
 				break;
 
 			case MODRDN_ENTRY:
-				LSCStructuralLogger.DESTINATION.info(I18n.getMessage(null,
-								"org.lsc.messages.RENAME_ENTRY", new Object[]{
-									jm.getDistinguishName(), syncName}));
-
+				LSCStructuralLogger.DESTINATION.info("# Renaming entry {} for {}",
+									jm.getDistinguishName(), syncName);
 				break;
 
 			case DELETE_ENTRY:
-				LSCStructuralLogger.DESTINATION.info(I18n.getMessage(null,
-								"org.lsc.messages.REMOVE_ENTRY", new Object[]{
-									jm.getDistinguishName(), syncName}));
-
+				LSCStructuralLogger.DESTINATION.info("# Removing entry {} for {}",
+									jm.getDistinguishName(), syncName);
 				break;
 
 			default:
-				LSCStructuralLogger.DESTINATION.info(I18n.getMessage(null,
-								"org.lsc.messages.UNKNOWN_CHANGE", new Object[]{
-									jm.getDistinguishName(), syncName}));
+				LSCStructuralLogger.DESTINATION.info("Error: unknown changetype ({} for {})",
+									jm.getDistinguishName(), syncName);
 		}
 
 		LSCStructuralLogger.DESTINATION.info(jm.toString());
@@ -530,9 +522,8 @@
 				break;
 
 			default:
-				LSCStructuralLogger.DESTINATION.debug(I18n.getMessage(null,
-								"org.lsc.messages.UNKNOWN_CHANGE", new Object[]{
-									jm.getDistinguishName(), syncName}));
+				LSCStructuralLogger.DESTINATION.debug("Error: unknown changetype ({} for {})",
+									jm.getDistinguishName(), syncName);
 		}
 
 		LSCStructuralLogger.DESTINATION.debug(jm.toString());

Deleted: lsc/trunk/src/main/java/org/lsc/utils/I18n.java
===================================================================
--- lsc/trunk/src/main/java/org/lsc/utils/I18n.java	2009-11-30 20:18:03 UTC (rev 520)
+++ lsc/trunk/src/main/java/org/lsc/utils/I18n.java	2009-11-30 20:20:33 UTC (rev 521)
@@ -1,271 +0,0 @@
-/*
- ****************************************************************************
- * Ldap Synchronization Connector provides tools to synchronize
- * electronic identities from a list of data sources including
- * any database with a JDBC connector, another LDAP directory,
- * flat files...
- *
- *                  ==LICENSE NOTICE==
- * 
- * Copyright (c) 2008, LSC Project 
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
-
- *    * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *     * Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *     * Neither the name of the LSC Project nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- * 
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
- * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
- * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
- * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
- * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- *                  ==LICENSE NOTICE==
- *
- *               (c) 2008 - 2009 LSC Project
- *         Sebastien Bahloul <seb at lsc-project.org>
- *         Thomas Chemineau <thomas at lsc-project.org>
- *         Jonathan Clarke <jon at lsc-project.org>
- *         Remy-Christophe Schermesser <rcs at lsc-project.org>
- ****************************************************************************
- */
-package org.lsc.utils;
-
-import java.io.File;
-import java.io.IOException;
-import java.net.MalformedURLException;
-import java.net.URL;
-import java.util.Enumeration;
-import java.util.HashMap;
-import java.util.Locale;
-import java.util.Map;
-import java.util.MissingResourceException;
-import java.util.ResourceBundle;
-
-import org.apache.commons.lang.StringUtils;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.lsc.Configuration;
-
-/**
- * Support different languages
- * 
- * @author Sebastien Bahloul <sbahloul at linagora.com>
- */
-public class I18n {
-
-	/** The logger */
-	private static Logger LOGGER = LoggerFactory.getLogger(I18n.class);
-
-	/** The messages in the current language */
-	private ResourceBundle messages;
-
-	/** the instance */
-	private static I18n instance;
-
-	/** the current locale used to get the message */
-	private Locale currentLocale;
-
-	/** The directory containing the language specific files */
-	private static final String localeDirectory = "resources";
-
-	/** Change according the project name with the '_' character */
-	private static final String PROJECT_NAME = "lsc";
-	private static String sep = System.getProperty("file.separator");
-
-	/**
-	 * Get the private instance
-	 * 
-	 * @return the local instance
-	 */
-	private static I18n getInstance() {
-		if (instance == null || instance.messages == null) {
-			instance = new I18n();
-			instance.defaultInitialize();
-		}
-		return instance;
-	}
-
-	/**
-	 * Get the private instance specifying the locale to use.
-	 * 
-	 * @param locale
-	 *            the locale to use
-	 * @return the local instance
-	 */
-	private static I18n getInstance(final Locale locale) {
-		if (instance == null || instance.messages == null) {
-			instance = new I18n();
-			try {
-				instance.setLocaleAndLoadMessages(locale);
-			} catch (IOException ie) {
-				instance.defaultInitialize();
-			}
-		}
-		return instance;
-	}
-
-	/**
-	 * Initialize by default the resources loading engine
-	 * 
-	 * @throw java.lang.RuntimeException if the corresponding locale or file not found
-	 */
-	private void defaultInitialize() {
-		Locale currentLocale = null;
-		String lang = System.getenv("LANG");
-		if (lang != null) {
-			if (lang.indexOf('.') > 0) {
-				lang = lang.substring(0, lang.indexOf('.'));
-			}
-		} else {
-			LOGGER.info("No environemental LANG variable found. Defaulting to en_US.");
-			lang = "en_US";
-		}
-		
-		for(Locale locale: Locale.getAvailableLocales()) {
-			if (lang.compareToIgnoreCase(locale.toString()) == 0) {
-				currentLocale = locale;
-				break;
-			}
-		}
-		if (currentLocale != null) {
-			try {
-				setLocaleAndLoadMessages(currentLocale);
-			} catch (IOException e) {
-				LOGGER.error("Unable to open the locale message file for {} ! Exiting...", currentLocale);
-				throw new RuntimeException("Unable to find locale : " + lang + " ! Exiting ...");
-			}
-		} else {
-			LOGGER.error("Unable to find locale : {} ! Exiting ...", lang);
-			throw new RuntimeException("Unable to find locale : " + lang + " ! Exiting ...");
-		}
-	}
-
-	/**
-	 * Simple setter for the locale to use.
-	 * @param locale the locale to use.
-	 */
-	public static void setLocale(Locale locale) throws IOException {
-		getInstance(locale);
-	}
-
-	private void setLocaleAndLoadMessages(Locale locale) throws IOException {
-		currentLocale = locale;
-		LOGGER.debug("Setting locale to {}", locale);
-		try {
-			messages = ResourceBundle.getBundle(
-							PROJECT_NAME,
-							currentLocale,
-							new I18nCustomClassLoader());
-		} catch (MissingResourceException e) {
-			LOGGER.error(e.toString());
-			LOGGER.debug(e.toString(), e);
-			throw e;
-		}
-	}
-
-	public String getLocalizedMessage(String code) {
-		return getInstance().getLocalizedMessage(code);
-	}
-
-	public String getMessage(String code) {
-		try {
-			return messages.getString(code);
-		} catch (MissingResourceException mre) {
-			LOGGER.error("I18n layer: unknown code {}", code);
-		}
-		return null;
-	}
-
-	public static String getMessage(Object obj, String code) {
-		return getInstance().getMessage((obj != null ? obj.getClass().getName() + "." : "") + code);
-	}
-
-	public static String getMessage(Object obj, String code, Object param1) {
-		return getMessage(obj, code, new Object[]{param1});
-	}
-
-	public static String getMessage(Object obj, String code, Object param1, Object param2) {
-		return getMessage(obj, code, new Object[]{param1, param2});
-	}
-
-	public static String getMessage(Object obj, String code, Object param1, Object param2, Object param3) {
-		return getMessage(obj, code, new Object[]{param1, param2, param3});
-	}
-
-	public static String getMessage(Object obj, String code, Object[] objs) {
-		String message = getMessage(obj, code);
-		if (message != null) {
-			for (int i = 0; i < objs.length; i++) {
-				if (objs[i] != null && message.indexOf("{" + i + "}") >= 0) {
-					try {
-						message = StringUtils.replace(message, "{" + i + "}", objs[i].toString());
-					} catch (IllegalArgumentException e) {
-						LOGGER.error(e.toString());
-						LOGGER.debug(e.toString(), e);
-					}
-				}
-			}
-		}
-		return message;
-	}
-
-	/**
-	 * Return messages from locale chosen starting with a specified string.
-	 * 
-	 * @param prefix
-	 * @return the map with the corresponding key / value pairs
-	 */
-	private Map<String, String> getKeysStarting(String prefix) {
-		Map<String, String> m = new HashMap<String, String>();
-		Enumeration<String> messagesNameEnum = messages.getKeys();
-		while (messagesNameEnum.hasMoreElements()) {
-			String messageName = messagesNameEnum.nextElement();
-			if (messageName.startsWith(prefix)) {
-				m.put(messageName, messages.getString(messageName));
-			}
-		}
-		return m;
-	}
-
-	/**
-	 * Return messages from locale chosen starting with a specified string.
-	 * 
-	 * @param prefix
-	 *            the string to use to test the messages name
-	 * @return the map with the corresponding key / value pairs
-	 */
-	public static Map<String, String> getKeysStartingWith(String prefix) {
-		return getInstance().getKeysStarting(prefix);
-	}
-
-	/**
-	 * Private ClassLoader to load locales from disk.
-	 */
-	private static class I18nCustomClassLoader extends ClassLoader {
-
-		@Override
-		protected URL findResource(String arg0) {
-			File f = new File(Configuration.getConfigurationDirectory() + arg0);
-			try {
-				return f.toURI().toURL();
-			} catch (MalformedURLException e) {
-			}
-			return super.findResource(arg0);
-		}
-	}
-}

Deleted: lsc/trunk/src/main/resources/lsc_en_US
===================================================================
--- lsc/trunk/src/main/resources/lsc_en_US	2009-11-30 20:18:03 UTC (rev 520)
+++ lsc/trunk/src/main/resources/lsc_en_US	2009-11-30 20:20:33 UTC (rev 521)
@@ -1,8 +0,0 @@
-org.lsc.messages.ADD_ENTRY = \# Adding new entry {0} for {1} 
-org.lsc.messages.RENAME_ENTRY = \# Renaming entry {0} for {1}
-org.lsc.messages.REMOVE_ENTRY = \# Removing entry {0} for {1} 
-org.lsc.messages.UPDATE_ENTRY = \# Updating entry {0} for {1} 
-org.lsc.messages.UNKNOWN_CHANGETYPE = Error: unknown changetype ({0} for {1})
-org.lsc.messages.NB_CHANGES = \# All entries: {0}, to modify entries: {1}, modified entries: {2}, errors: {3}
-org.lsc.messages.SYNC_ERROR = Error while synchronizing ID {0}: {1}\n{2}
-

Deleted: lsc/trunk/src/main/resources/lsc_fr_FR
===================================================================
--- lsc/trunk/src/main/resources/lsc_fr_FR	2009-11-30 20:18:03 UTC (rev 520)
+++ lsc/trunk/src/main/resources/lsc_fr_FR	2009-11-30 20:20:33 UTC (rev 521)
@@ -1,7 +0,0 @@
-org.lsc.messages.ADD_ENTRY = \# Ajout du nouvel enregistrement {0} pour {1} 
-org.lsc.messages.RENAME_ENTRY = \# Renommage de l'enregistrement {0} pour {1} 
-org.lsc.messages.REMOVE_ENTRY = \# Retrait de l'enregistrement {0} pour {1} 
-org.lsc.messages.UPDATE_ENTRY = \# Mise à jour de l'enregistrement {0} pour {1} 
-org.lsc.messages.UNKNOWN_CHANGETYPE = Erreur: type de changement inconnu ({0} pour {1})
-org.lsc.messages.NB_CHANGES = \# Nombre d'enregistrement(s) pris en compte: {0}, nombre d'enregistrement(s) à reporter: {1}, nombre d'enregistrements reporté(s): {2}, nombre d'erreurs: {3}
-org.lsc.messages.SYNC_ERROR = Erreur rencontrée sur l'identifiant {0}: {1}\n{2}

Modified: lsc/trunk/src/test/java/org/lsc/Ldap2LdapSyncTest.java
===================================================================
--- lsc/trunk/src/test/java/org/lsc/Ldap2LdapSyncTest.java	2009-11-30 20:18:03 UTC (rev 520)
+++ lsc/trunk/src/test/java/org/lsc/Ldap2LdapSyncTest.java	2009-11-30 20:20:33 UTC (rev 521)
@@ -63,7 +63,6 @@
 import org.lsc.jndi.JndiServices;
 import org.lsc.jndi.SimpleJndiSrcService;
 import org.lsc.service.ISrcService;
-import org.lsc.utils.I18n;
 import org.lsc.utils.directory.LDAP;
 
 /**
@@ -91,9 +90,6 @@
 	@Override
 	protected void setUp() throws Exception {
 		super.setUp();
-
-		// force the locale to en_US to avoid I18N errors with foreign LANG
-		I18n.setLocale(Locale.US);
 	}
 
 	/**

Modified: lsc/trunk/src/test/java/org/lsc/utils/output/LdifLayoutTest.java
===================================================================
--- lsc/trunk/src/test/java/org/lsc/utils/output/LdifLayoutTest.java	2009-11-30 20:18:03 UTC (rev 520)
+++ lsc/trunk/src/test/java/org/lsc/utils/output/LdifLayoutTest.java	2009-11-30 20:20:33 UTC (rev 521)
@@ -45,7 +45,6 @@
  */
 package org.lsc.utils.output;
 
-import org.lsc.utils.*;
 import ch.qos.logback.classic.Level;
 import ch.qos.logback.classic.Logger;
 import ch.qos.logback.classic.LoggerContext;
@@ -54,7 +53,6 @@
 import java.io.IOException;
 import java.util.ArrayList;
 import java.util.List;
-import java.util.Locale;
 
 import javax.naming.directory.BasicAttribute;
 import javax.naming.directory.DirContext;
@@ -103,7 +101,6 @@
 		layout.setPattern("%m%n");
 		layout.start();
 
-		I18n.setLocale(Locale.US);
 		assertEquals("dn:: Z2l2ZW5OYW1lPVPDqWJhc3RpZW4sZGM9bHNjLXByb2plY3QsZGM9b3Jn\nchangetype: add\ncn: name\nsn:: PG5vbiBzYWZlIHN0cmluZz4=\ngivenName:: U8OpYmFzdGllbg==\ndescription: \n\n",
 						layout.doLayout(loggingEvent));
 
@@ -135,7 +132,6 @@
 		layout.setPattern("%m%n");
 		layout.start();
 
-		I18n.setLocale(Locale.US);
 		assertEquals("dn: dc=lsc-project,dc=org\n" +
 						"changetype: modify\n" +
 						"replace: cn\n" +
@@ -168,7 +164,6 @@
 		layout.setPattern("%m%n");
 		layout.start();
 
-		I18n.setLocale(Locale.US);
 		assertEquals("dn: uid=a,dc=lsc-project,dc=org\nchangetype: delete\n\n",
 						layout.doLayout(loggingEvent));
 	}



More information about the lsc-changes mailing list