Revision 41284

View differences:

trunk/org.gvsig.desktop/org.gvsig.desktop.plugin/org.gvsig.i18n.app/org.gvsig.i18n.app.mainplugin/src/main/resources-plugin/config.xml
25 25

  
26 26
-->
27 27
<plugin-config>
28
  	<alternativeNames name="org.gvsig.i18n.extension"/>
29
	<depends plugin-name="org.gvsig.app.mainplugin" />
30
	<depends plugin-name="org.gvsig.coreplugin.app.mainplugin" />
31
	<resourceBundle name="text" />
32
	<libraries library-dir="lib" />
33
	<extensions>
34
		<extension class-name="org.gvsig.i18n.extension.I18nExtension"
35
			description="Extensi?n de gesti?n de traducciones multiidioma" 
36
			active="true" 
37
			priority="1">
38
		</extension>
39
	</extensions>
28
    <alternativeNames name="org.gvsig.i18n.extension"/>
29
    <depends plugin-name="org.gvsig.app.mainplugin" />
30
    <depends plugin-name="org.gvsig.coreplugin.app.mainplugin" />
31
    <resourceBundle name="text" />
32
    <libraries library-dir="lib" />
33
    <extensions>
34
        <extension class-name="org.gvsig.i18n.extension.I18nExtension"
35
                           description="Extensi?n de gesti?n de traducciones multiidioma" 
36
                           active="true" 
37
                           priority="1">
38
        </extension>
39
        <extension class-name="org.gvsig.i18n.extension.ConsolideTranslationsExtension"
40
                           description="Extensi?n para consolidar en andami todas las traducciones" 
41
                           active="true" 
42
                           priority="1">
43
            <action 
44
                name="tools-devel-consolidate-translations"
45
                label="_Consolidate_all_translations" 
46
                position="908500201" 
47
                action-command="tools-devel-consolidate-translations"
48
                icon="tools-devel-consolidate-translations"
49
                tooltip="_Consolidate_all_translations" 
50
                accelerator=""
51
            />
52
            <menu 
53
                name="tools-devel-consolidate-translations"
54
                text="tools/Development/_Consolidate_all_translations" 
55
            />
56
        </extension>
57
    </extensions>
40 58
</plugin-config>
trunk/org.gvsig.desktop/org.gvsig.desktop.plugin/org.gvsig.i18n.app/org.gvsig.i18n.app.mainplugin/src/main/java/org/gvsig/i18n/extension/ConsolideTranslationsExtension.java
1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 3
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA 02110-1301, USA.
20
 *
21
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24
/*
25
 * AUTHORS (In addition to CIT):
26
 * 2008 {DiSiD Technologies}  {New extension for installation and update of text translations}
27
 */
28
package org.gvsig.i18n.extension;
29

  
30
import javax.swing.JOptionPane;
31
import org.gvsig.andami.PluginServices;
32
import org.gvsig.andami.plugins.Extension;
33
import org.gvsig.andami.ui.mdiFrame.MainFrame;
34
import org.gvsig.i18n.impl.TranslationsConsolider;
35
import org.slf4j.Logger;
36
import org.slf4j.LoggerFactory;
37

  
38
/**
39
 * Texts localization management extension.
40
 *
41
 * @author <a href="mailto:dcervera@disid.com">David Cervera</a>
42
 */
43
public class ConsolideTranslationsExtension extends Extension {
44

  
45
    private static final Logger logger = LoggerFactory.getLogger(ConsolideTranslationsExtension.class);
46

  
47
    private boolean executing = false;
48

  
49
    public synchronized void execute(String actionCommand) {
50
        final MainFrame main = PluginServices.getMainFrame();
51

  
52
        if ( "tools-devel-consolidate-translations".equalsIgnoreCase(actionCommand) ) {
53
            if ( this.executing ) {
54
                main.messageDialog("Process is running.", "Warning", JOptionPane.INFORMATION_MESSAGE);
55
                return;
56
            }
57
            this.executing = true;
58
            main.refreshControls();
59
            Thread process = new Thread(new Runnable() {
60
                public void run() {
61
                    try {
62
                        TranslationsConsolider consolider = new TranslationsConsolider();
63
                        consolider.consolide();
64
                        main.messageDialog("Consolidation of translations terminated.", "Information", JOptionPane.INFORMATION_MESSAGE);
65
                    } catch(Exception ex) {
66
                        logger.warn("There was errors consolidating translations.",ex);
67
                        main.messageDialog("There was errors consolidating translations.", "Warning", JOptionPane.WARNING_MESSAGE);
68
                    } finally {
69
                        executing = false;
70
                        main.refreshControls();
71
                    }
72
                }
73
            });
74
            process.start();
75
        }
76
    }
77

  
78
    public void initialize() {
79
        // Do nothing
80
    }
81

  
82
    public boolean isEnabled() {
83
        return ! this.executing;
84
    }
85

  
86
    public boolean isVisible() {
87
        return true;
88
    }
89
}
0 90

  
trunk/org.gvsig.desktop/org.gvsig.desktop.plugin/org.gvsig.i18n.app/org.gvsig.i18n.app.mainplugin/src/main/java/org/gvsig/i18n/impl/TranslationsConsolider.java
1
/*
2
 * To change this license header, choose License Headers in Project Properties.
3
 * To change this template file, choose Tools | Templates
4
 * and open the template in the editor.
5
 */
6
package org.gvsig.i18n.impl;
7

  
8
import java.io.File;
9
import java.io.FileFilter;
10
import java.io.FileInputStream;
11
import java.io.FileOutputStream;
12
import java.io.IOException;
13
import java.util.ArrayList;
14
import java.util.Collections;
15
import java.util.Enumeration;
16
import java.util.HashMap;
17
import java.util.Iterator;
18
import java.util.List;
19
import java.util.Locale;
20
import java.util.Map;
21
import java.util.Properties;
22
import org.apache.commons.io.FileUtils;
23
import org.apache.commons.io.IOUtils;
24
import org.apache.commons.lang3.StringUtils;
25
import org.gvsig.andami.PluginServices;
26
import org.gvsig.andami.PluginsLocator;
27
import org.gvsig.andami.PluginsManager;
28
import org.gvsig.i18n.I18nManager;
29
import org.gvsig.tools.ToolsLocator;
30
import org.gvsig.tools.task.SimpleTaskStatus;
31
import org.gvsig.tools.task.TaskStatus;
32
import org.slf4j.Logger;
33
import org.slf4j.LoggerFactory;
34

  
35
/**
36
 *
37
 * @author usuario
38
 */
39
public class TranslationsConsolider {
40

  
41
    private static final Logger logger = LoggerFactory.getLogger(TranslationsConsolider.class);
42

  
43
    private I18nManager i18nManager = null;
44
    private PluginsManager pluginsManager = null;
45
    private Map<String, Map<String, String>> allTranslations = null;
46
    private Locale currentLocale = null;
47
    private Map<String, List<String>> keysInPlugins = null;
48

  
49
    public TranslationsConsolider() {
50
        this.pluginsManager = PluginsLocator.getManager();
51
        this.allTranslations = new HashMap<String, Map<String, String>>();
52
        this.currentLocale = this.getI18nManager().getCurrentLocale();
53
        this.keysInPlugins = new HashMap<String, List<String>>();
54
    }
55

  
56
    public void setCurrentLocale(Locale locale) {
57
        this.currentLocale = locale;
58
    }
59

  
60
    public Locale getCurrentLocale() {
61
        return this.currentLocale;
62
    }
63

  
64
    public I18nManager getI18nManager() {
65
        if ( this.i18nManager == null ) {
66
            this.i18nManager = I18nManagerImpl.getInstance();
67
        }
68
        return this.i18nManager;
69
    }
70

  
71
    public void addKey(String key, String pluginCode) {
72
        List<String> pluginCodes = this.keysInPlugins.get(key);
73
        if ( pluginCodes == null ) {
74
            pluginCodes = new ArrayList<String>();
75
            this.keysInPlugins.put(key, pluginCodes);
76
        }
77
        if ( !StringUtils.isBlank(pluginCode) ) {
78
            if ( !pluginCodes.contains(pluginCode) ) {
79
                pluginCodes.add(pluginCode);
80
            }
81
        }
82
    }
83

  
84
    public void addLocale(Locale locale) {
85
        if ( this.allTranslations.get(locale.toString()) == null ) {
86
            this.allTranslations.put(locale.toString().toLowerCase(), new HashMap<String, String>());
87
        }
88
    }
89

  
90
    public List<String> getPluginCodesOfKey(String key) {
91
        List<String> pluginCodes = this.keysInPlugins.get(key);
92
        return pluginCodes;
93
    }
94

  
95
    public Map<String, String> getTranslations(String locale) {
96
        Map<String, String> translations = this.allTranslations.get(locale.toString().toLowerCase());
97
        return translations;
98
    }
99

  
100
    public Map<String, String> getTranslations(Locale locale) {
101
        return this.getTranslations(locale.toString());
102
    }
103

  
104
    public void add(Locale locale, String key, String value, String pluginCode) {
105
        Map<String, String> translations = this.getTranslations(locale);
106
        if ( !translations.containsKey(key) ) {
107
            translations.put(key, value);
108
            this.addKey(key, pluginCode);
109
        }
110
    }
111

  
112
    public void add(Locale locale, Properties properties, String pluginCode) {
113
        this.addLocale(locale);
114
        Enumeration enumKeys = properties.keys();
115
        while ( enumKeys.hasMoreElements() ) {
116
            String key = (String) enumKeys.nextElement();
117
            String value = properties.getProperty(key);
118
            this.add(locale, key, value, pluginCode);
119
        }
120
    }
121

  
122
    public List<Locale> getLocales() {
123
        List<Locale> locales = new ArrayList<Locale>(this.allTranslations.size());
124
        Iterator<String> itLocales = this.allTranslations.keySet().iterator();
125
        while ( itLocales.hasNext() ) {
126
            Locale locale = new Locale(itLocales.next().toString());
127
            locales.add(locale);
128
        }
129
        return locales;
130
    }
131

  
132
    public List<String> getKeys() {
133
        List<String> keys = new ArrayList<String>(this.keysInPlugins.size());
134
        keys.addAll(this.keysInPlugins.keySet());
135
        Collections.sort(keys);
136
        return keys;
137
    }
138

  
139
    private String getResourceFileName(Locale locale) {
140
        StringBuilder fileName = new StringBuilder();
141
        fileName.append("text");
142
        if ( !StringUtils.isBlank(locale.getLanguage()) ) {
143
            fileName.append("_");
144
            fileName.append(locale.getLanguage());
145
        }
146
        if ( !StringUtils.isBlank(locale.getCountry()) ) {
147
            fileName.append("_");
148
            fileName.append(locale.getCountry());
149
        }
150
        if ( !StringUtils.isBlank(locale.getVariant()) ) {
151
            fileName.append("_");
152
            fileName.append(locale.getVariant());
153
        }
154
        fileName.append(".properties");
155
        return fileName.toString();
156
    }
157

  
158
    public String getTranslation(String locale, String key) {
159
        Map<String, String> translations = this.getTranslations(locale);
160
        if ( translations == null ) {
161
            logger.warn("Can't locate the translations for locale '" + locale + "'.");
162
            return null;
163
        }
164
        return translations.get(key);
165
    }
166

  
167
    public String getTranslation(Locale locale, String key) {
168
        return this.getTranslation(locale.toString(), key);
169
    }
170

  
171
    public String get(String key) {
172
        return this.getTranslation(currentLocale, key);
173
    }
174

  
175
    public void put(String key, String value) {
176
        this.add(currentLocale, key, value, null);
177
    }
178

  
179
    public void consolide() throws IOException {
180
        SimpleTaskStatus task = ToolsLocator.getTaskStatusManager().createDefaultSimpleTaskStatus("Consolide translations");
181
        task.setAutoremove(true);
182
        task.add();
183
        try {
184
            task.setTitle("Consolide translations");
185
            int n = this.loadAllTranslations(task);
186
            if( !task.isCancellationRequested() ) {
187
                this.storeAsProperties(task, n);
188
            }
189
        } finally {
190
            task.terminate();
191
        }
192
    }
193
    
194
    private int loadAllTranslations(SimpleTaskStatus task) {
195
        task.message("searching locales");
196
        Locale[] locales = this.getI18nManager().getInstalledLocales();
197

  
198
        List<PluginServices> plugins = this.pluginsManager.getPlugins();
199
        File appI18nFolder = pluginsManager.getApplicationI18nFolder();
200
        File[] subfolders = appI18nFolder.listFiles(new FileFilter() {
201
            public boolean accept(File file) {
202
                return file.isDirectory();
203
            }
204
        });
205
        int n = 1;
206
        task.setRangeOfValues(0, plugins.size() + subfolders.length + locales.length + 1);
207

  
208
        task.message("loading from andami.");
209
        task.setCurValue(n++);
210
        loadTranslation(locales, appI18nFolder, null);
211

  
212
        for ( File subfolder : subfolders ) {
213
            if( task.isCancellationRequested() ) {
214
                return n;
215
            }
216
            task.setCurValue(n++);
217
            if ( subfolder.isDirectory() ) {
218
                task.message("loading " + subfolder.getName());
219
                if ( "andami".equals(subfolder.getName()) ) {
220
                    loadTranslation(locales, appI18nFolder, "org.gvsig.andami");
221
                } else {
222
                    loadTranslation(locales, appI18nFolder, null);
223
                }
224
            }
225
        }
226

  
227
        for ( PluginServices plugin : plugins ) {
228
            if( task.isCancellationRequested() ) {
229
                return n;
230
            }
231
            if ( plugin != null ) {
232
                task.message("loading " + plugin.getPluginName());
233
                task.setCurValue(n++);
234
                loadTranslation(locales, plugin.getPluginDirectory(), plugin.getPluginName());
235
            }
236
        }
237
        return n;
238
    }
239

  
240
    private void loadTranslation(Locale[] locales, File folder, String pluginCode) {
241
        for ( Locale locale : locales ) {
242
            File f1 = new File(folder, getResourceFileName(locale));
243
            File f2 = new File(folder, "i18n/" + getResourceFileName(locale));
244
            if ( !f1.exists() && !f2.exists() ) {
245
                if ( "es".equals(locale.getLanguage()) ) {
246
                    f1 = new File(folder, "text.properties");
247
                    f2 = new File(folder, "i18n/text.properties");
248
                }
249
            }
250
            if ( f1.exists() ) {
251
                loadTranslation(locale, f1, pluginCode);
252
            }
253
            if ( f2.exists() ) {
254
                loadTranslation(locale, f2, pluginCode);
255
            }
256
        }
257
    }
258

  
259
    private void loadTranslation(Locale locale, File f, String pluginCode) {
260
        FileInputStream fins = null;
261
        try {
262
            Properties properties = new Properties();
263
            fins = new FileInputStream(f);
264
            properties.load(fins);
265
            this.add(locale, properties, pluginCode);
266
        } catch (IOException ex) {
267
            logger.warn("Error processing property file '" + f.getAbsolutePath() + "'.", ex);
268
        } finally {
269
            IOUtils.closeQuietly(fins);
270
        }
271
    }
272

  
273
    private void storeAsProperties(SimpleTaskStatus task, int pos) throws IOException {
274
        task.message("Prepraring to store");
275
        File folder = new File(this.pluginsManager.getApplicationI18nFolder(), "translations.all");
276
        if( !folder.exists() ) {
277
            FileUtils.forceMkdir(folder);
278
        }
279
        List<String> keys = this.getKeys();
280
        List<Locale> locales = this.getLocales();
281
        for ( Locale locale : locales ) {
282
            task.setCurValue(pos++);
283
            task.message("Storing "+locale.toString());
284
            Map<String, String> translations = this.getTranslations(locale);
285
            Properties properties = new Properties();
286
            for ( String key : keys ) {
287
                String value = this.getTranslation(locale, key);
288
                if( value == null ) {
289
                    value = "";
290
                }
291
                properties.setProperty(key, value);
292
            }
293
            File f = new File(folder, this.getResourceFileName(locale));
294
            FileOutputStream fos = null;
295
            try {
296
                fos = new FileOutputStream(f);
297
                properties.store(fos, null);
298
            } catch (Exception ex) {
299
                logger.warn("Can't write properties '" + f.getAbsolutePath() + "'.", ex);
300
            } finally {
301
                IOUtils.closeQuietly(fos);
302
            }
303

  
304
        }
305
        task.message("Storing plugin information");
306
        Properties properties = new Properties();
307
        for ( String key : keys ) {
308
            List<String> pluginCodes = this.keysInPlugins.get(key);
309
            StringBuilder ss = null;
310
            for ( String pluginCode : pluginCodes ) {
311
                if ( ss == null ) {
312
                    ss = new StringBuilder();
313
                } else {
314
                    ss.append(", ");
315
                }
316
                ss.append(pluginCode);
317
            }
318
            if ( ss == null ) {
319
                properties.setProperty(key, "");
320
            } else {
321
                properties.setProperty(key, ss.toString());
322
            }
323
        }
324
        FileOutputStream fos = null;
325
        File f = new File(folder, "keysbyplugin.properties");
326
        try {
327
            fos = new FileOutputStream(f);
328
            properties.store(fos, null);
329
        } catch (Exception ex) {
330
            logger.warn("Can't write properties '" + f.getAbsolutePath() + "'.", ex);
331
        } finally {
332
            IOUtils.closeQuietly(fos);
333
        }
334
        task.message("");
335
    }
336

  
337
    /*
338
     def storeAsDBF(self):
339
     maxl = 100
340
     for k in self.keys():
341
     if len(k) > maxl:
342
     maxl = len(k)
343
     #print "max key len: ", maxl
344
        
345
     folder = File(self.__pluginsManager.getApplicationFolder(),"i18n")
346
     f = File(folder,"translations.dbf")
347
     try:
348
     f.delete()
349
     except:
350
     print "Can't delete file "+f.getAbsolutePath()
351
     schema = createSchema() 
352
     schema.append( "ID" , "Integer" , 7)
353
     schema.append( "key" , "String" , maxl)
354
     schema.append( "locale" , "String" , 30)
355
     schema.append( "translation" , "String" , 200)
356
     schema.append( "plugins" , "String" , 200)
357

  
358
     table = createDBF( schema, File(folder,"translations.dbf"))
359

  
360
     locales = self.getI18nManager().getInstalledLocales()
361
     idCounter = 1
362
     for key in self.keys():
363
     for locale in locales:
364
     pluginCodes = ""
365
     for pluginCode in self.getPluginCodesOfKey(key):
366
     pluginCodes += pluginCode + " "
367
     pluginCodes = str(pluginCodes).strip()
368
        
369
     table.append(ID=idCounter, 
370
     key=key, 
371
     locale=locale.toString(), 
372
     translation=self.getTranslation(locale, key),
373
     plugins=pluginCodes
374
     )
375
     idCounter +=1
376
     table.commit()
377
  
378
     */
379
}
trunk/org.gvsig.desktop/org.gvsig.desktop.plugin/org.gvsig.app/org.gvsig.app.mainplugin/src/main/java/org/gvsig/app/extension/TranslationsPackageExtension.java
57 57
                    application.translate("_Translations_package"),
58 58
                    WindowManager.MODE.WINDOW
59 59
            );
60
        } else if ( "tools-devel-consolidate-translations".equalsIgnoreCase(actionCommand) ) {
61

  
62 60
        }
63 61
    }
64 62

  
trunk/org.gvsig.desktop/org.gvsig.desktop.plugin/org.gvsig.app/org.gvsig.app.mainplugin/src/main/resources-plugin/config.xml
789 789
        icon="tools-devel-translations-package"
790 790
        accelerator=""
791 791
        />
792
      <action 
793
        name="tools-devel-consolidate-translations"
794
        label="_Consolidate_all_translations" 
795
        position="908500201" 
796
        action-command="tools-devel-consolidate-translations"
797
        icon="tools-devel-consolidate-translations"
798
        tooltip="_Consolidate_all_translations" 
799
        accelerator=""
800
        />
801 792

  
793

  
802 794
      <menu 
803 795
        name="tools-devel-translations-package"
804 796
        text="tools/Development/_Translations_package" 
805 797
        />
806
      <menu 
807
        name="tools-devel-consolidate-translations"
808
        text="tools/Development/_Consolidate_all_translations" 
809
        />
810 798

  
799

  
811 800
    </extension>
812 801

  
813 802
    <extension class-name="org.gvsig.app.extension.ShowDevelInfoExtension"
trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.installer/org.gvsig.installer.lib/org.gvsig.installer.lib.impl/src/main/java/org/gvsig/installer/lib/impl/info/InstallerInfoFileWriter.java
33 33
import java.io.FileOutputStream;
34 34
import java.io.IOException;
35 35
import java.io.OutputStream;
36
import java.net.URL;
37 36
import java.util.Properties;
37
import org.apache.commons.lang3.StringUtils;
38 38

  
39 39
import org.gvsig.installer.lib.api.PackageInfo;
40 40
import org.gvsig.installer.lib.api.PackageInfoWriter;
......
114 114
            properties.setProperty(InstallerInfoTags.DEPENDENCIES, toStr(installInfo.getDependencies()));
115 115
            properties.setProperty(InstallerInfoTags.SOURCES_URL, toStr(installInfo.getSourcesURL()));
116 116
            properties.setProperty(InstallerInfoTags.WEB_URL, toStr(installInfo.getWebURL()));
117
            properties.setProperty(InstallerInfoTags.DOWNLOAD_URL, toStr(installInfo.getDownloadURLAsString()));
118 117
            properties.setProperty(InstallerInfoTags.OWNER_URL, toStr(installInfo.getOwnerURL()));
119 118
            properties.setProperty(InstallerInfoTags.MODEL_VERSION, toStr(installInfo.getModelVersion()));
119
            if( !StringUtils.isBlank(installInfo.getDownloadURLAsString()) ) {
120
                properties.setProperty(InstallerInfoTags.DOWNLOAD_URL, toStr(installInfo.getDownloadURLAsString()));
121
            }
120 122
            
121 123
            properties.store(os, "");
122 124
            os.close();
trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.installer/org.gvsig.installer.lib/org.gvsig.installer.lib.impl/pom.xml
19 19
        <artifactId>commons-io</artifactId>
20 20
      <scope>compile</scope>
21 21
    </dependency>
22
        <dependency>
23
        <groupId>org.apache.commons</groupId>
24
        <artifactId>commons-lang3</artifactId>
25
        <scope>compile</scope>
26
    </dependency>
22 27
    <dependency>
23 28
      <groupId>org.gvsig</groupId>
24 29
      <artifactId>org.gvsig.installer.lib.api</artifactId>
trunk/org.gvsig.desktop/org.gvsig.desktop.framework/org.gvsig.andami/src/main/java/org/gvsig/andami/PluginsManager.java
10 10
 *
11 11
 * This program is distributed in the hope that it will be useful,
12 12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 14
 * GNU General Public License for more details.
15 15
 *
16 16
 * You should have received a copy of the GNU General Public License
17 17
 * along with this program; if not, write to the Free Software
18 18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
19
 * MA 02110-1301, USA.
20 20
 *
21 21
 * For any additional information, do not hesitate to contact us
22 22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
......
32 32
import org.gvsig.installer.lib.api.PackageInfo;
33 33

  
34 34
public interface PluginsManager {
35

  
35 36
    /**
36
     * Return the associated pluginServices to the extension class passed as parameter.
37
     * Return the associated pluginServices to the extension class passed as
38
     * parameter.
39
     *
37 40
     * @param extension
38 41
     * @return plugin services
39 42
     */
40 43
    public PluginServices getPlugin(Class<? extends IExtension> extension);
41
	
44

  
42 45
    /**
43 46
     * Return the associated pluginServices to the object passed as parameter.
47
     *
44 48
     * @param object
45 49
     * @return plugin services
46 50
     */
......
48 52

  
49 53
    /**
50 54
     * Return the associated pluginServices to the extension plugin.
55
     *
51 56
     * @param pluginName, name of the plugin
52 57
     * @return plugin services
53
     */	
58
     */
54 59
    public PluginServices getPlugin(String pluginName);
55
	
56
	/**
57
	 * Get the package info associated to the plugin of the extension.
58
	 * 
59
	 * @param extension extension of the plugin 
60
	 * @return plugin package info 
61
	 */
62
	public PackageInfo getPackageInfo(Class<? extends IExtension> extension);
63
	
64
	/**
65
	 * Get the package info associated to the plugin with the specified name.
66
	 * 
67
	 * @param pluginName, name of the plugin
68
	 * @return plugin package info 
69
	 */
70
	public PackageInfo getPackageInfo(String pluginName);
71 60

  
72
	/**
73
	 * Get the package info associated to the application.
74
	 * 
75
	 * @return application package info
76
	 */
77
	public PackageInfo getPackageInfo();
78
	
79
	/**
80
	 * Return the list of plugins loaded in the application
81
	 * @return list of plugins
82
	 */
83
	public List<PluginServices> getPlugins();
84
	
85 61
    /**
62
     * Get the package info associated to the plugin of the extension.
63
     *
64
     * @param extension extension of the plugin
65
     * @return plugin package info
66
     */
67
    public PackageInfo getPackageInfo(Class<? extends IExtension> extension);
68

  
69
    /**
70
     * Get the package info associated to the plugin with the specified name.
71
     *
72
     * @param pluginName, name of the plugin
73
     * @return plugin package info
74
     */
75
    public PackageInfo getPackageInfo(String pluginName);
76

  
77
    /**
78
     * Get the package info associated to the application.
79
     *
80
     * @return application package info
81
     */
82
    public PackageInfo getPackageInfo();
83

  
84
    /**
85
     * Return the list of plugins loaded in the application
86
     *
87
     * @return list of plugins
88
     */
89
    public List<PluginServices> getPlugins();
90

  
91
    /**
86 92
     * Gets the instance of the extension whose class is provided.
87
     * 
93
     *
88 94
     * @param extension, class of the extension to retrieve
89
     * 
95
     *
90 96
     * @return The instance of the extension, or null if the instance does
91
     *         not exist.
97
     * not exist.
92 98
     */
93
	public IExtension getExtension(Class<? extends IExtension> extension);
94
	
95
	/**
96
	 * Return an iterator over al extensions loaded in the application.
97
	 * 
98
	 * @return iterator over extensions
99
	 */
100
	public Iterator<IExtension> getExtensions();
101
	
102
	/**
103
	 * Set an extension to control the visivility of all the extensions
104
	 * of the application.
105
	 * 
106
	 * @param extension
107
	 */
108
	public void setExclusiveUIExtension(ExclusiveUIExtension extension);
109
	
110
	/**
111
	 * Return the ExclusiveUIExtension installed in the application or
112
	 * null.
113
	 * @return
114
	 */
115
	public ExclusiveUIExtension getExclusiveUIExtension();
99
    public IExtension getExtension(Class<? extends IExtension> extension);
116 100

  
117
	
118
	/**
119
	 * @deprecated use {@link #translate(String)}
120
	 * @see {@link #translate(String)}
121
	 */
101
    /**
102
     * Return an iterator over al extensions loaded in the application.
103
     *
104
     * @return iterator over extensions
105
     */
106
    public Iterator<IExtension> getExtensions();
107

  
108
    /**
109
     * Set an extension to control the visivility of all the extensions
110
     * of the application.
111
     *
112
     * @param extension
113
     */
114
    public void setExclusiveUIExtension(ExclusiveUIExtension extension);
115

  
116
    /**
117
     * Return the ExclusiveUIExtension installed in the application or
118
     * null.
119
     *
120
     * @return
121
     */
122
    public ExclusiveUIExtension getExclusiveUIExtension();
123

  
124
    /**
125
     * @deprecated use {@link #translate(String)}
126
     * @see {@link #translate(String)}
127
     */
122 128
    public String getText(Object obj, String msg);
123 129

  
124 130
    /**
125 131
     * Translate the message key to the current language used
126 132
     * in the application.
127
     *  
133
     *
128 134
     * @param msg key to translate
129
     * @return message traslated or the key 
135
     * @return message traslated or the key
130 136
     */
131 137
    public String translate(String msg);
132
    
138

  
133 139
    /**
134 140
     * Returns the main application folder, where the application is installed.
135
     * 
141
     *
136 142
     * @return the main application folder
137 143
     */
138 144
    public File getApplicationFolder();
139 145

  
140 146
    /**
141 147
     * Returns the default folder with the installable package bundles.
142
     * 
148
     *
143 149
     * @return the default folder with the installable package bundles
144 150
     */
145 151
    public File getInstallFolder();
146 152

  
147 153
    /**
148 154
     * Returns the application folder in the home of user.
149
     * 
155
     *
150 156
     * @return the main application folder
151 157
     */
152 158
    public File getApplicationHomeFolder();
153 159

  
160

  
154 161
    /**
162
     * Returns the default folder where the internationalization files are installed.
163
     *
164
     * @return the default folder where the internationalization files are installed.
165
     */
166
    public File getApplicationI18nFolder();
167
    
168
    /**
155 169
     * Returns the plugins folder.
156
     * 
170
     *
157 171
     * @return the plugins folder
158 172
     * @deprecated use {@link #getPluginsFolders()}
159 173
     */
160 174
    public File getPluginsFolder();
161
    
175

  
162 176
    /**
163 177
     * Returns a list of folder on the plugins are instaleds.
164
     * 
178
     *
165 179
     * @return list of folders File of the plugins.
166 180
     */
167 181
    public List<File> getPluginsFolders();
168
    
169 182

  
170 183
    /**
171 184
     * @deprecated @see {@link #getPluginsFolders()}
172 185
     */
173
	public File getPluginsDirectory();
174
	
175
	/**
176
	 * This method allows plugins to require the execution of
177
	 * tasks
178
	 * 
179
	 * @param task
180
	 * @param in_event_thread
181
	 * @param priority
182
	 */
183
	public void addAdditionalTask(Runnable task, boolean in_event_thread, int priority);
184
	
185
	/**
186
	 * This method executes the tasks required by the plugins. 
187
	 * 
188
	 * @return
189
	 */
190
	public void executeAdditionalTasks();
186
    public File getPluginsDirectory();
191 187

  
188
    /**
189
     * This method allows plugins to require the execution of
190
     * tasks
191
     *
192
     * @param task
193
     * @param in_event_thread
194
     * @param priority
195
     */
196
    public void addAdditionalTask(Runnable task, boolean in_event_thread, int priority);
197

  
198
    /**
199
     * This method executes the tasks required by the plugins.
200
     *
201
     * @return
202
     */
203
    public void executeAdditionalTasks();
204

  
192 205
}
trunk/org.gvsig.desktop/org.gvsig.desktop.framework/org.gvsig.andami/src/main/java/org/gvsig/andami/installer/translations/TranslationsInstaller.java
33 33
import java.util.zip.ZipInputStream;
34 34
import org.apache.commons.io.FileUtils;
35 35
import org.apache.commons.io.FilenameUtils;
36
import org.gvsig.andami.PluginsLocator;
37
import org.gvsig.andami.PluginsManager;
36 38
import org.gvsig.installer.lib.api.PackageInfo;
37 39
import org.gvsig.installer.lib.api.execution.InstallPackageServiceException;
38 40
import org.gvsig.installer.lib.spi.InstallerInfoFileException;
......
57 59
    }
58 60

  
59 61
    public void install(File applicationFolder, InputStream inputStream, PackageInfo packageInfo) throws InstallPackageServiceException {
60
        File i18nFolder = new File(applicationFolder,"i18n");
62
        PluginsManager pluginsManager = PluginsLocator.getManager();
63
        File i18nFolder = pluginsManager.getApplicationI18nFolder();
61 64
        
62
	logger.info("Installing package '"+packageInfo.getCode()+"' in '"+applicationFolder.getAbsolutePath()+"'.");
65
	logger.info("Installing package '"+packageInfo.getCode()+"' in '"+i18nFolder.getAbsolutePath()+"'.");
63 66
        try {
64 67
            if (!i18nFolder.exists()) {
65 68
		logger.warn("Can install package '"+packageInfo.getCode()+"', install folder '"+i18nFolder+"' does not exists.");
......
101 104

  
102 105
                File file = new File(folder, entryName);
103 106
                if (entry.isDirectory()) {
104
                    logger.debug("ignore folders in 'translations' package (" + entryName+").");
107
        		file.mkdirs();                    
105 108
                } else {
106 109
                    if (file.exists()) {
107
                            FileUtils.forceDelete(file);
110
                         FileUtils.forceDelete(file);
108 111
                    }
112
                    if( !file.getParentFile().exists() ) {
113
                        FileUtils.forceMkdir(file.getParentFile());
114
                    }
109 115
                    logger.debug("extracting " + file.getAbsolutePath());
110 116
                    FileOutputStream fos = new FileOutputStream(file);
111 117
                    while ((count = zis.read(data, 0, BUFFER)) != -1) {
trunk/org.gvsig.desktop/org.gvsig.desktop.framework/org.gvsig.andami/src/main/java/org/gvsig/andami/installer/packagebuilder/options/ProgressOption.java
28 28
import java.io.FileNotFoundException;
29 29
import java.io.FileOutputStream;
30 30
import java.io.OutputStream;
31
import java.net.URL;
31 32

  
32 33
import javax.swing.JOptionPane;
33 34
import javax.swing.JPanel;
......
107 108
        this.progressPanel.bind(taskStatus);
108 109

  
109 110
        try {
110

  
111
            String downloadURL = wizard.getPackageInfo().getDownloadURLAsString();
112
            wizard.getPackageInfo().setDownloadURL("");
113
            
111 114
            MakePackageService makePackageService =
112 115
                InstallerLocator.getInstallerManager().createMakePackage(
113 116
                    wizard.getFolderToPackaging(), wizard.getPackageInfo());
......
119 122
            if (indexOutputStream != null) {
120 123
                taskStatus.message(getText("_Creating_index"));
121 124
                makePackageService.createPackageIndex(
122
                     wizard.getDownloadURL(), indexOutputStream);
125
                        wizard.getDownloadURL(), indexOutputStream);
123 126
            }
127
            
128
            wizard.getPackageInfo().setDownloadURL(downloadURL);
124 129
            taskStatus.terminate();
125 130

  
126 131
            // Set the finished text
trunk/org.gvsig.desktop/org.gvsig.desktop.framework/org.gvsig.andami/src/main/java/org/gvsig/andami/impl/DefaultPluginsManager.java
76 76
	}
77 77

  
78 78
	public PluginServices getPlugin(Object obj) {
79
            return this.getPlugin(obj.getClass());
79
            if( obj instanceof IExtension ) {
80
                return this.getPlugin(obj.getClass());
81
            }
82
            PluginClassLoader loader = (PluginClassLoader) obj.getClass().getClassLoader();
83
            String pluginName = loader.getPluginName();
84
            return this.getPlugin(pluginName);
80 85
	}
81 86

  
82 87
        public PluginServices getPlugin(String pluginName) {
......
238 243
        }
239 244
        
240 245
    }
246

  
247
    public File getApplicationI18nFolder() {
248
        return new File(this.getApplicationFolder(),"i18n");
249
    }
250

  
241 251
    
242 252
    
243 253
}
trunk/org.gvsig.desktop/org.gvsig.desktop.framework/org.gvsig.andami/src/main/java/org/gvsig/andami/Launcher.java
76 76
import java.util.Properties;
77 77
import java.util.Set;
78 78
import java.util.TreeSet;
79
import java.util.logging.Level;
79 80
import java.util.prefs.Preferences;
80 81

  
81 82
import javax.swing.ImageIcon;
......
978 979
		// Try to get theme from a plugin
979 980
		File pluginsDir = new File(pluginsDirectory);
980 981
		if (!pluginsDir.isAbsolute()) {
981
			pluginsDir = new File(System.getProperty("user.dir"),
982
					pluginsDirectory);
982
                    pluginsDir = new File(getApplicationFolder(), pluginsDirectory);
983 983
		}
984 984
		if (pluginsDir.exists()) {
985 985
			logger.info("search andami-theme in plugins folder.");
......
3004 3004
	 * Swing are configured.
3005 3005
	 * 
3006 3006
	 */
3007
	private static void configureLocales(String[] args) {
3008
		// Configurar el locale
3009
		String localeStr = null;
3007
    private static void configureLocales(String[] args) {
3008
        // Configurar el locale
3009
        String localeStr = null;
3010 3010

  
3011
		localeStr = PluginServices.getArgumentByName("language");
3012
		if (localeStr == null) {
3013
			localeStr = andamiConfig.getLocaleLanguage();
3014
		}
3015
		localeStr = normalizeLanguageCode(localeStr);
3016
		locale = getLocale(localeStr, andamiConfig.getLocaleCountry(),
3017
				andamiConfig.getLocaleVariant());
3018
		Locale.setDefault(locale);
3019
		JComponent.setDefaultLocale(locale);
3020
		org.gvsig.i18n.Messages.addLocale(locale);
3021
		// add english and spanish as fallback languages
3022
		if (localeStr.equals("es") || localeStr.equals("ca")
3023
				|| localeStr.equals("gl") || localeStr.equals("eu")
3024
				|| localeStr.equals("va")) {
3025
			// prefer Spanish for languages spoken in Spain
3026
			org.gvsig.i18n.Messages.addLocale(new Locale("es"));
3027
			org.gvsig.i18n.Messages.addLocale(new Locale("en"));
3028
		} else {
3029
			// prefer English for the rest
3030
			org.gvsig.i18n.Messages.addLocale(new Locale("en"));
3031
			org.gvsig.i18n.Messages.addLocale(new Locale("es"));
3032
		}
3011
        localeStr = PluginServices.getArgumentByName("language");
3012
        if ( localeStr == null ) {
3013
            localeStr = andamiConfig.getLocaleLanguage();
3014
        }
3015
        localeStr = normalizeLanguageCode(localeStr);
3016
        locale = getLocale(localeStr, andamiConfig.getLocaleCountry(),
3017
                andamiConfig.getLocaleVariant());
3018
        Locale.setDefault(locale);
3019
        JComponent.setDefaultLocale(locale);
3020
        org.gvsig.i18n.Messages.addLocale(locale);
3021
        // add english and spanish as fallback languages
3022
        if ( localeStr.equals("es") || localeStr.equals("ca")
3023
                || localeStr.equals("gl") || localeStr.equals("eu")
3024
                || localeStr.equals("va") ) {
3025
            // prefer Spanish for languages spoken in Spain
3026
            org.gvsig.i18n.Messages.addLocale(new Locale("es"));
3027
            org.gvsig.i18n.Messages.addLocale(new Locale("en"));
3028
        } else {
3029
            // prefer English for the rest
3030
            org.gvsig.i18n.Messages.addLocale(new Locale("en"));
3031
            org.gvsig.i18n.Messages.addLocale(new Locale("es"));
3032
        }
3033 3033

  
3034 3034
        // Create classloader for the i18n resources in the
3035 3035
        // andami and user i18n folder. Those values will have
3036 3036
        // precedence over any other values added afterwards
3037
        File andamiI18nFolder =
3038
            new File(System.getProperty("user.dir"), "i18n");
3037
        File appI18nFolder  = new File(getApplicationFolder(), "i18n");
3039 3038
        File userI18nFolder = new File(getAppHomeDir(), "i18n");
3040
        if( !userI18nFolder.exists() ) {
3041
        	try {
3042
				FileUtils.forceMkdir(userI18nFolder);
3043
			} catch (IOException e) {
3044
				logger.info("Can't create i18n folder in gvSIG home ("+userI18nFolder+").",e);
3045
			}
3039
        if ( !userI18nFolder.exists() ) {
3040
            try {
3041
                FileUtils.forceMkdir(userI18nFolder);
3042
            } catch (IOException e) {
3043
                logger.info("Can't create i18n folder in gvSIG home (" + userI18nFolder + ").", e);
3044
            }
3046 3045
        }
3047

  
3048 3046
        logger.info("Loading i18n resources from the application and user "
3049
            + "folders: {}, {}", andamiI18nFolder, userI18nFolder);
3047
                + "folders: {}, {}", appI18nFolder, userI18nFolder);
3050 3048

  
3051
        URL[] i18nURLs;
3052
        try {
3053
            i18nURLs =
3054
                new URL[] { userI18nFolder.toURI().toURL(),
3055
                    andamiI18nFolder.toURI().toURL() };
3056
            ClassLoader i18nClassLoader = new URLClassLoader(i18nURLs);
3057
            org.gvsig.i18n.Messages.addResourceFamily("text", i18nClassLoader,
3049
        URL[] i18nURLs = getURLsFromI18nFolders(userI18nFolder, appI18nFolder);
3050
        ClassLoader i18nClassLoader = new URLClassLoader(i18nURLs);
3051
        org.gvsig.i18n.Messages.addResourceFamily("text", i18nClassLoader,
3058 3052
                "Andami Launcher");
3059
        } catch (MalformedURLException e) {
3060
            logger.error("Error loading i18n resources from the application "
3061
                + "and user folders: " + andamiI18nFolder + ", "
3062
                + userI18nFolder, e);
3063
        }
3064 3053

  
3054
        // Los ficheros de traducciones estan ahora fuera del jar, en la
3055
        // Carpeta i18n/andami de la instalacion, asi que esto ya no hace falta.
3056
        //
3065 3057
        // Finally load the andami own i18n resources
3066
        org.gvsig.i18n.Messages.addResourceFamily("org.gvsig.andami.text",
3067
            "Andami Launcher");
3068
	}
3058
        // org.gvsig.i18n.Messages.addResourceFamily("org.gvsig.andami.text",
3059
        // "Andami Launcher");
3060
    }
3069 3061

  
3062
        private static URL[] getURLsFromI18nFolders(File userFolder, File appFolder) {
3063
            List<URL> urls = new ArrayList<URL>();
3064
            File[] files = new File[] { userFolder, appFolder };
3065
            for( int n1=0; n1<files.length; n1++ ) {
3066
                File folder = files[n1];
3067
                try {
3068
                    urls.add(folder.toURI().toURL());
3069
                } catch (MalformedURLException ex) {
3070
                    logger.warn("Can't convert file to url (file="+userFolder.getAbsolutePath()+").", ex);
3071
                    return null;
3072
                }
3073
                File[] subFiles = folder.listFiles();
3074
                for( int n2=0; n2<subFiles.length; n2++ ) {
3075
                    File subFolder = subFiles[n2];
3076
                    if( subFolder.isDirectory() ) {
3077
                        try {
3078
                            urls.add(subFolder.toURI().toURL());
3079
                        } catch (MalformedURLException ex) {
3080
                            logger.warn("Can't convert file to url (file="+subFolder.getAbsolutePath()+").", ex);
3081
                            return null;
3082
                        }
3083
                    }
3084
                }
3085
            }
3086
            return urls.toArray(new URL[urls.size()]);
3087
        }
3088
        
3070 3089
	/**
3071 3090
	 * Gets Home Directory location of the application into users home folder.
3072 3091
	 * 
trunk/org.gvsig.desktop/org.gvsig.desktop.framework/org.gvsig.andami/pom.xml
222 222
    <dependency>
223 223
        <groupId>org.apache.commons</groupId>
224 224
        <artifactId>commons-lang3</artifactId>
225
        <scope>runtime</scope>
225
        <scope>compile</scope>
226 226
    </dependency>
227 227
    <dependency>
228 228
      <groupId>org.swinglabs</groupId>

Also available in: Unified diff