Author: tchemit Date: 2010-11-19 20:27:08 +0100 (Fri, 19 Nov 2010) New Revision: 1820 Url: http://nuiton.org/repositories/revision/i18n/1820 Log: Anomalie #672: I18n does not work when bundles are in none normalized directories (with accents and other...) Modified: trunk/nuiton-i18n/src/main/java/org/nuiton/i18n/bundle/I18nBundleUtil.java Modified: trunk/nuiton-i18n/src/main/java/org/nuiton/i18n/bundle/I18nBundleUtil.java =================================================================== --- trunk/nuiton-i18n/src/main/java/org/nuiton/i18n/bundle/I18nBundleUtil.java 2010-11-19 19:25:09 UTC (rev 1819) +++ trunk/nuiton-i18n/src/main/java/org/nuiton/i18n/bundle/I18nBundleUtil.java 2010-11-19 19:27:08 UTC (rev 1820) @@ -1,23 +1,23 @@ /* * #%L * I18n :: Api - * + * * $Id$ * $HeadURL$ * %% * Copyright (C) 2004 - 2010 CodeLutin * %% * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 of the * License, or (at your option) any later version. - * + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public + * + * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * <http://www.gnu.org/licenses/lgpl-3.0.html>. * #L% @@ -61,6 +61,11 @@ public static final String DIRECTORY_SEARCH_BUNDLE_PATTERN = "i18n"; + /** + * @deprecated since 2.0, this is not compatible with os, so do not used it + * any more. + */ + @Deprecated public static final String SEARCH_BUNDLE_PATTERN = ".*i18n/.+\\.properties"; private static final I18nBundleEntry[] EMPTY_I18N_BUNDLE_ENTRYS_ARRAY = @@ -247,7 +252,10 @@ // TODO deal with encoding in windows, this is very durty, // TODO but it works... File file = new File(fileName.replaceAll("%20", " ")); - + if (log.isDebugEnabled()) { + log.debug("url to search " + file); + log.debug("Is a exsting file or directory ? " + file.exists()); + } if (I18nUtil.isJar(fileName)) { // cas ou le ichier du classLoader est un fichier jar if (log.isDebugEnabled()) { @@ -548,7 +556,7 @@ protected static List<URL> getURLsFromJar(URL incomingURL, File jarfile) { - String pattern = SEARCH_BUNDLE_PATTERN; + String pattern = getSearchBundlePattern(); try { ZipInputStream zis = new ZipInputStream(new FileInputStream(jarfile)); try { @@ -589,9 +597,27 @@ } } + /** + * Compute the search pattern according to the {@link File#separator} on + * the underlying os. + * <p/> + * Under linux this is {@code .*i18n/.+\.properties}, and under windows this + * is {@code .*i18n\\\\.+\.properties}. + * + * @return the correct pattern + * @since 2.0 + */ + protected static String getSearchBundlePattern() { + + String result = ".*i18n"; + String path = File.separator; + result += "\\".equals(path) ? path + path : path; + return result + ".+\\.properties"; + } + protected static List<URL> getURLsFromDirectory(URL incomingURL, File repository) { - String pattern = SEARCH_BUNDLE_PATTERN; + String pattern = getSearchBundlePattern(); try { if (log.isDebugEnabled()) { log.debug("search '" + pattern + "' in " + repository);
participants (1)
-
tchemit@users.nuiton.org