Index: lutinutil/src/java/org/codelutin/i18n/Language.java diff -u lutinutil/src/java/org/codelutin/i18n/Language.java:1.12 lutinutil/src/java/org/codelutin/i18n/Language.java:1.13 --- lutinutil/src/java/org/codelutin/i18n/Language.java:1.12 Sat Mar 22 23:26:31 2008 +++ lutinutil/src/java/org/codelutin/i18n/Language.java Sun Mar 23 06:02:24 2008 @@ -32,18 +32,17 @@ import java.io.FileOutputStream; import java.io.IOException; import java.net.URLClassLoader; -import java.net.URL; import java.util.Enumeration; import java.util.Locale; import java.util.MissingResourceException; import java.util.Properties; /** - * This class is used byte the i18n class. It encapsulates the translation - * resource for one language. + * This class is used by the i18n class. It encapsulates the translation + * resource for a given language and a given encoding. *

* The class offers a public static factory method : - * {@link #newLanguage(Locale, String,URL[])}. + * {@link #newLanguage(Locale, String)}. *

* Note : You SHOULD always use the factory method, since constructor does * not load i18n bundle resources. @@ -62,12 +61,11 @@ * * @param l la locale choisie * @param toEncoding l'encoding choisi - * @param extraUrl extra urls where to detect bundles * @return l'instance du language correspondant, initialisé */ - public static Language newLanguage(Locale l, String toEncoding, URL... extraUrl) { + public static Language newLanguage(Locale l, String toEncoding) { Language language = new Language(l, toEncoding); - language.init(extraUrl); + language.init(); return language; } @@ -93,24 +91,16 @@ this.encoding = toEncoding; } - protected Language(Locale l) { - this(l, I18n.UTF_8_ENCONDING); - } - /** * charge les traductions de la langue. *

* recherche dans un premier temps, les urls des bundles puis les charge. - * - * @param extraUrl extra urls where to detect bundles */ - protected void init(URL... extraUrl) { + protected void init() { // make sure the bundlemanager is init - I18nBundleManager.init(extraUrl); - + I18nBundleManager.init(); // load resources from bundles resource = new Properties(); - // get bundles for this locale I18nBundleManager.getInstance().load(this, resource); } @@ -172,8 +162,9 @@ * @return untranslated sentence */ public String untranslate(String sentence) { - if (resource == null) + if (resource == null) { return sentence; + } try { Enumeration e = resource.propertyNames(); // Look for the given sentence through all translations @@ -181,8 +172,9 @@ String key = (String) e.nextElement(); String translation = resource.getProperty(key); // If found returns the corresponding key - if (sentence.equals(translation)) + if (sentence.equals(translation)) { return key; + } } } catch (MissingResourceException eee) { // Well, this can't happen... @@ -203,6 +195,20 @@ return resource == null ? 0 : resource.size(); } + public void close() { + if (resource != null) { + log.info(this); + resource.clear(); + resource = null; + } + } + + @Override + protected void finalize() throws Throwable { + super.finalize(); + close(); + } + @Override public boolean equals(Object o) { if (this == o) return true; @@ -222,6 +228,6 @@ @Override public String toString() { - return "Language "; + return "Language "; } } \ No newline at end of file Index: lutinutil/src/java/org/codelutin/i18n/I18n.java diff -u lutinutil/src/java/org/codelutin/i18n/I18n.java:1.15 lutinutil/src/java/org/codelutin/i18n/I18n.java:1.16 --- lutinutil/src/java/org/codelutin/i18n/I18n.java:1.15 Sat Mar 22 23:29:24 2008 +++ lutinutil/src/java/org/codelutin/i18n/I18n.java Sun Mar 23 06:02:24 2008 @@ -23,14 +23,16 @@ * * @author Benjamin Poussin * Copyright Code Lutin - * @version $Revision: 1.15 $ + * @version $Revision: 1.16 $ * - * Mise a jour: $Date: 2008-03-22 23:29:24 $ + * Mise a jour: $Date: 2008-03-23 06:02:24 $ * par : $Author: tchemit $ */ package org.codelutin.i18n; +import org.codelutin.i18n.bundle.I18nBundleManager; + import java.net.URL; import java.text.MessageFormat; import java.util.Arrays; @@ -42,9 +44,9 @@ * you can either : *