------------------------------------------------------------ revno: 12087 committer: Lars Helge Ă˜verland <larshe...@gmail.com> branch nick: dhis2 timestamp: Sat 2013-09-14 19:39:13 +0200 message: Pushed sorting of locales to service layer added: dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/comparator/LocaleNameComparator.java modified: dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/i18n/DefaultI18nService.java dhis-2/dhis-services/dhis-service-i18n/src/main/java/org/hisp/dhis/i18n/resourcebundle/DefaultResourceBundleManager.java dhis-2/dhis-services/dhis-service-i18n/src/main/java/org/hisp/dhis/i18n/resourcebundle/ResourceBundleManager.java dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/settings/user/action/GetGeneralSettingsAction.java
-- lp:dhis2 https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk Your team DHIS 2 developers is subscribed to branch lp:dhis2. To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription
=== added file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/comparator/LocaleNameComparator.java' --- dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/comparator/LocaleNameComparator.java 1970-01-01 00:00:00 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/comparator/LocaleNameComparator.java 2013-09-14 17:39:13 +0000 @@ -0,0 +1,47 @@ +package org.hisp.dhis.common.comparator; + +/* + * Copyright (c) 2004-2013, University of Oslo + * 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 HISP 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. + */ + +import java.util.Comparator; +import java.util.Locale; + +/** + * @author Lars Helge Overland + */ +public class LocaleNameComparator + implements Comparator<Locale> +{ + public static final LocaleNameComparator INSTANCE = new LocaleNameComparator(); + + @Override + public int compare( Locale o1, Locale o2 ) + { + return o1.getDisplayName().compareTo( o2.getDisplayName() ); + } +} === modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/i18n/DefaultI18nService.java' --- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/i18n/DefaultI18nService.java 2013-08-23 16:05:01 +0000 +++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/i18n/DefaultI18nService.java 2013-09-14 17:39:13 +0000 @@ -38,7 +38,6 @@ import java.util.Arrays; import java.util.Collection; import java.util.Collections; -import java.util.Comparator; import java.util.HashMap; import java.util.Hashtable; import java.util.List; @@ -47,6 +46,7 @@ import org.hisp.dhis.common.IdentifiableObject; import org.hisp.dhis.common.NameableObject; +import org.hisp.dhis.common.comparator.LocaleNameComparator; import org.hisp.dhis.dataelement.DataElement; import org.hisp.dhis.system.util.LocaleUtils; import org.hisp.dhis.translation.Translation; @@ -95,13 +95,7 @@ } } - Collections.sort( locales, new Comparator<Locale>() - { - public int compare( Locale l1, Locale l2 ) - { - return l1.getDisplayName().compareTo( l2.getDisplayName() ); - } - } ); + Collections.sort( locales, LocaleNameComparator.INSTANCE ); } // ------------------------------------------------------------------------- === modified file 'dhis-2/dhis-services/dhis-service-i18n/src/main/java/org/hisp/dhis/i18n/resourcebundle/DefaultResourceBundleManager.java' --- dhis-2/dhis-services/dhis-service-i18n/src/main/java/org/hisp/dhis/i18n/resourcebundle/DefaultResourceBundleManager.java 2013-08-23 16:05:01 +0000 +++ dhis-2/dhis-services/dhis-service-i18n/src/main/java/org/hisp/dhis/i18n/resourcebundle/DefaultResourceBundleManager.java 2013-09-14 17:39:13 +0000 @@ -28,6 +28,7 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +import org.hisp.dhis.common.comparator.LocaleNameComparator; import org.hisp.dhis.i18n.locale.LocaleManager; import org.hisp.dhis.i18n.util.PathUtils; @@ -37,9 +38,12 @@ import java.net.JarURLConnection; import java.net.URL; import java.net.URLDecoder; +import java.util.ArrayList; import java.util.Collection; +import java.util.Collections; import java.util.Enumeration; import java.util.HashSet; +import java.util.List; import java.util.Locale; import java.util.MissingResourceException; import java.util.ResourceBundle; @@ -53,8 +57,6 @@ * @author Torgeir Lorange Ostby * @author Pham Thi Thuy * @author Nguyen Dang Quang - * @version $Id: DefaultResourceBundleManager.java 6335 2008-11-20 11:11:26Z - * larshelg $ */ public class DefaultResourceBundleManager implements ResourceBundleManager @@ -122,7 +124,7 @@ } } - public Collection<Locale> getAvailableLocales() + public List<Locale> getAvailableLocales() throws ResourceBundleManagerException { ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); @@ -134,16 +136,22 @@ throw new ResourceBundleManagerException( "Failed to find global resource bundle" ); } + List<Locale> locales = null; + if ( url.toExternalForm().startsWith( "jar:" ) ) { - return getAvailableLocalesFromJar( url ); + locales = new ArrayList<Locale>( getAvailableLocalesFromJar( url ) ); } else { String dirPath = new File( url.getFile() ).getParent(); - return getAvailableLocalesFromDir( dirPath ); + locales = new ArrayList<Locale>( getAvailableLocalesFromDir( dirPath ) ); } + + Collections.sort( locales, LocaleNameComparator.INSTANCE ); + + return locales; } private Collection<Locale> getAvailableLocalesFromJar( URL url ) === modified file 'dhis-2/dhis-services/dhis-service-i18n/src/main/java/org/hisp/dhis/i18n/resourcebundle/ResourceBundleManager.java' --- dhis-2/dhis-services/dhis-service-i18n/src/main/java/org/hisp/dhis/i18n/resourcebundle/ResourceBundleManager.java 2013-08-23 16:05:01 +0000 +++ dhis-2/dhis-services/dhis-service-i18n/src/main/java/org/hisp/dhis/i18n/resourcebundle/ResourceBundleManager.java 2013-09-14 17:39:13 +0000 @@ -28,7 +28,7 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -import java.util.Collection; +import java.util.List; import java.util.Locale; import java.util.ResourceBundle; @@ -47,5 +47,5 @@ ResourceBundle getGlobalResourceBundle( Locale locale ) throws ResourceBundleManagerException; - Collection<Locale> getAvailableLocales() throws ResourceBundleManagerException; + List<Locale> getAvailableLocales() throws ResourceBundleManagerException; } === modified file 'dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/settings/user/action/GetGeneralSettingsAction.java' --- dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/settings/user/action/GetGeneralSettingsAction.java 2013-09-06 15:53:07 +0000 +++ dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/settings/user/action/GetGeneralSettingsAction.java 2013-09-14 17:39:13 +0000 @@ -28,15 +28,13 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +import static org.hisp.dhis.user.UserSettingService.DEFAULT_ANALYSIS_DISPLAY_PROPERTY; +import static org.hisp.dhis.user.UserSettingService.KEY_ANALYSIS_DISPLAY_PROPERTY; +import static org.hisp.dhis.user.UserSettingService.KEY_DISPLAY_OPTION_SET_AS_RADIO_BUTTON; import static org.hisp.dhis.user.UserSettingService.KEY_MESSAGE_EMAIL_NOTIFICATION; import static org.hisp.dhis.user.UserSettingService.KEY_MESSAGE_SMS_NOTIFICATION; -import static org.hisp.dhis.user.UserSettingService.KEY_ANALYSIS_DISPLAY_PROPERTY; -import static org.hisp.dhis.user.UserSettingService.DEFAULT_ANALYSIS_DISPLAY_PROPERTY; -import static org.hisp.dhis.user.UserSettingService.KEY_DISPLAY_OPTION_SET_AS_RADIO_BUTTON; import java.util.ArrayList; -import java.util.Collections; -import java.util.Comparator; import java.util.List; import java.util.Locale; import java.util.SortedMap; @@ -51,8 +49,6 @@ /** * @author Chau Thu Tran - * @version $ GetAvailableUserSettingsAction.java May 31, 2011 9:31:54 AM $ - * */ public class GetGeneralSettingsAction implements Action @@ -178,40 +174,19 @@ throws Exception { // --------------------------------------------------------------------- - // Get available locales + // Get available UI locales // --------------------------------------------------------------------- availableLocales = new ArrayList<Locale>( resourceBundleManager.getAvailableLocales() ); - Collections.sort( availableLocales, new Comparator<Locale>() - { - public int compare( Locale locale0, Locale locale1 ) - { - return locale0.getDisplayName().compareTo( locale1.getDisplayName() ); - } - } ); - currentLocale = localeManager.getCurrentLocale(); - if ( !availableLocales.contains( currentLocale ) ) - { - currentLocale = localeManager.getFallbackLocale(); - } - // --------------------------------------------------------------------- - // Get available locales in db + // Get available DB locales // --------------------------------------------------------------------- availableLocalesDb = new ArrayList<Locale>( i18nService.getAvailableLocales() ); - Collections.sort( availableLocalesDb, new Comparator<Locale>() - { - public int compare( Locale locale0, Locale locale1 ) - { - return locale0.getDisplayName().compareTo( locale1.getDisplayName() ); - } - } ); - currentLocaleDb = i18nService.getCurrentLocale(); // ---------------------------------------------------------------------
_______________________________________________ Mailing list: https://launchpad.net/~dhis2-devs Post to : dhis2-devs@lists.launchpad.net Unsubscribe : https://launchpad.net/~dhis2-devs More help : https://help.launchpad.net/ListHelp