Revision 41693 trunk/org.gvsig.desktop/org.gvsig.desktop.framework/org.gvsig.andami/src/main/java/org/gvsig/andami/impl/DefaultLocaleManager.java

View differences:

DefaultLocaleManager.java
23 23
import org.gvsig.andami.PluginsLocator;
24 24
import org.gvsig.andami.PluginsManager;
25 25
import org.gvsig.andami.config.generate.AndamiConfig;
26
import org.gvsig.andami.installer.translations.TranslationsInstallerFactory;
26 27
import org.gvsig.andami.ui.mdiFrame.MDIFrame;
28
import org.gvsig.installer.lib.api.InstallerLocator;
29
import org.gvsig.installer.lib.api.InstallerManager;
27 30
import org.gvsig.utils.XMLEntity;
28 31
import org.slf4j.Logger;
29 32
import org.slf4j.LoggerFactory;
......
41 44
    private static final String COUNTRY = "country";
42 45
    private static final String LANGUAGE = "language";
43 46
    private static final String REGISTERED_LOCALES_PERSISTENCE = "RegisteredLocales";
47
    
48
    private static final String LOCALE_CONFIG_FILENAME = "locale.config";
44 49

  
45 50
    private final Locale[] hardcoredLocales = new Locale[]{
46 51
        // Default supported locales
......
121 126
        return new Locale(language, country, variant);
122 127
    }
123 128

  
129
    public Set<Locale> loadLocalesFromConfing(File localesFile)  { 
130
        PropertiesConfiguration config = null;
131
        if (!localesFile.canRead()) {
132
            return null;
133
        }
134
        try {
135
            config = new PropertiesConfiguration(localesFile);
136
        } catch (Exception ex) {
137
            logger.warn("Can't open locale configuration '" + localesFile + "'.", ex);
138
            return null;
139
        }
140
        
141
        Set<Locale> locales = new HashSet<Locale>();
142
        List localeCodes = config.getList("locale");
143
        for (Object localeCode : localeCodes) {
144
            Locale locale = LocaleUtils.toLocale((String) localeCode);
145
            locales.add(locale);
146
        }
147
        return locales;
148
    }
149
    
124 150
    public Set<Locale> getDefaultLocales() {
125 151
        if (this.defaultLocales == null) {
126 152
            PluginsManager pluginsManager = PluginsLocator.getManager();
127
            File localesFile = new File(pluginsManager.getApplicationI18nFolder(), "locale.config");
128

  
129
            PropertiesConfiguration config = null;
130
            if (localesFile.canRead()) {
131
                try {
132
                    config = new PropertiesConfiguration(localesFile);
133
                } catch (Exception ex) {
134
                    logger.warn("Can't open configuration '" + localesFile + "'.", ex);
135
                }
136
            }
153
            File localesFile = new File(pluginsManager.getApplicationI18nFolder(), LOCALE_CONFIG_FILENAME);
154
            
155
            Set<Locale> locales = loadLocalesFromConfing(localesFile);
137 156
            defaultLocales = new HashSet<Locale>();
138
            if (config == null) {
157
            if( locales == null ) {
139 158
                for (int i = 0; i < hardcoredLocales.length; i++) {
140 159
                    defaultLocales.add(hardcoredLocales[i]);
141 160
                }
142 161
            } else {
143
                List localeCodes = config.getList("locale");
144
                for (Object localeCode : localeCodes) {
145
                    Locale locale = LocaleUtils.toLocale((String) localeCode);
146
                    defaultLocales.add(locale);
147
                }
162
                defaultLocales.addAll(locales);
148 163
            }
149

  
150 164
        }
151 165
        return this.defaultLocales;
152 166
    }
......
203 217
                    installedLocales.add(locale);
204 218
                }
205 219
            }
220
            Set<Locale> lfp = getAllLocalesFromPackages();
221
            installedLocales.addAll(lfp);
206 222
        }
207 223
        return Collections.unmodifiableSet(installedLocales);
208 224
    }
......
375 391
                });
376 392
        return value == null ? defaultValue : value;
377 393
    }
394
    
395
    private Set<Locale> getAllLocalesFromPackages() {
396
        Set<Locale> locales = new HashSet<Locale>();
397
        InstallerManager installerManager = InstallerLocator.getInstallerManager();
398
        List<File> folders = installerManager.getAddonFolders(TranslationsInstallerFactory.PROVIDER_NAME);
399
        for( File folder : folders ) {
400
            File file = new File(folder,LOCALE_CONFIG_FILENAME);
401
            Set<Locale> l = this.loadLocalesFromConfing(file);
402
            locales.addAll(l);
403
        }
404
        return locales;
405
    }
378 406
}

Also available in: Unified diff