Revision 43067

View differences:

trunk/org.gvsig.desktop/org.gvsig.desktop.framework/org.gvsig.andami/src/main/java/org/gvsig/andami/PluginsLibrary.java
27 27
import org.gvsig.andami.firewall.DefaultFirewallConfiguration;
28 28
import org.gvsig.andami.impl.DefaultLocaleManager;
29 29
import org.gvsig.andami.impl.DefaultPluginsManager;
30
import org.gvsig.andami.installer.icontheme.IconThemeInstallerFactory.RegisterIconThemeInstaller;
30 31
import org.gvsig.andami.installer.translations.TranslationsInstallerFactory.RegisterTranslationsInstaller;
31 32
import org.gvsig.andami.ui.mdiManager.WindowInfo;
32 33
import org.gvsig.installer.lib.api.InstallerLibrary;
......
60 61

  
61 62
        caller.add(new WindowInfo.RegisterPersistence() );
62 63
        caller.add(new RegisterTranslationsInstaller() );
64
        caller.add(new RegisterIconThemeInstaller() );
63 65
        if( !caller.call() ) {
64 66
            throw new LibraryException(PluginsLibrary.class, caller.getExceptions());
65 67
        }
trunk/org.gvsig.desktop/org.gvsig.desktop.framework/org.gvsig.andami/src/main/java/org/gvsig/andami/installer/icontheme/IconThemeInstallerFactory.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
package org.gvsig.andami.installer.icontheme;
25

  
26
import org.gvsig.installer.lib.spi.InstallerProviderLocator;
27
import org.gvsig.tools.ToolsLocator;
28
import org.gvsig.tools.dynobject.DynClass;
29
import org.gvsig.tools.dynobject.DynObject;
30
import org.gvsig.tools.dynobject.DynObjectManager;
31
import org.gvsig.tools.service.spi.AbstractProviderFactory;
32
import org.gvsig.tools.service.spi.Provider;
33
import org.gvsig.tools.service.spi.ProviderManager;
34
import org.gvsig.tools.service.spi.ProviderServices;
35
import org.gvsig.tools.util.Callable;
36

  
37
public class IconThemeInstallerFactory extends
38
        AbstractProviderFactory {
39

  
40
    public static final String INSTALLER_NAME = "icontheme";
41
    public static final String INSTALLER_DESCRIPTION = "";
42

  
43
    private DynClass dynclass;
44

  
45
    @Override
46
    protected DynClass createParametersDynClass() {
47
        if ( dynclass == null ) {
48
            initialize();
49
        }
50
        return dynclass;
51
    }
52

  
53
    @Override
54
    protected Provider doCreate(DynObject parameters, ProviderServices services) {
55
        return new IconThemeInstaller(services);
56
    }
57

  
58
    @Override
59
    public void initialize() {
60
        if ( dynclass == null ) {
61
            DynObjectManager dynObjectManager = ToolsLocator.getDynObjectManager();
62
            dynclass = dynObjectManager.createDynClass(
63
                    INSTALLER_NAME,
64
                    INSTALLER_DESCRIPTION
65
            );
66
            dynObjectManager.add(dynclass);
67
        }
68
    }
69

  
70
    public static class RegisterIconThemeInstaller implements Callable {
71

  
72
        @Override
73
        public Object call() throws Exception {
74
            ProviderManager providerManager = InstallerProviderLocator.getProviderManager();
75
            providerManager.addProviderFactory(new IconThemeInstallerFactory());
76
            return true;
77
        }
78
    }
79
}
0 80

  
trunk/org.gvsig.desktop/org.gvsig.desktop.framework/org.gvsig.andami/src/main/java/org/gvsig/andami/installer/icontheme/IconThemeInstaller.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
package org.gvsig.andami.installer.icontheme;
26

  
27
import java.io.File;
28
import java.io.FileOutputStream;
29
import java.io.IOException;
30
import java.io.InputStream;
31
import java.util.zip.ZipEntry;
32
import java.util.zip.ZipException;
33
import java.util.zip.ZipInputStream;
34
import org.apache.commons.io.FileUtils;
35
import org.apache.commons.io.FilenameUtils;
36
import org.gvsig.installer.lib.api.PackageInfo;
37
import org.gvsig.installer.lib.api.execution.InstallPackageServiceException;
38
import org.gvsig.installer.lib.spi.InstallerInfoFileException;
39
import org.gvsig.installer.lib.spi.execution.InstallPackageProvider;
40
import org.gvsig.tools.ToolsLocator;
41
import org.gvsig.tools.service.spi.AbstractProvider;
42
import org.gvsig.tools.service.spi.ProviderServices;
43
import org.gvsig.tools.swing.api.ToolsSwingLocator;
44
import org.gvsig.tools.swing.icontheme.IconThemeManager;
45
import org.gvsig.tools.task.SimpleTaskStatus;
46
import org.gvsig.tools.task.TaskStatusManager;
47
import org.slf4j.Logger;
48
import org.slf4j.LoggerFactory;
49

  
50

  
51
public class IconThemeInstaller extends AbstractProvider implements InstallPackageProvider {
52

  
53
    private static final Logger logger = LoggerFactory.getLogger(IconThemeInstaller.class);
54
    
55
    private final int BUFFER = 2048;
56
    
57
    public IconThemeInstaller(ProviderServices providerServices) {
58
            super(providerServices);
59
    }
60

  
61
    @Override
62
    public void install(File applicationFolder, InputStream inputStream, PackageInfo packageInfo) throws InstallPackageServiceException {
63
        IconThemeManager iconThemeManager = ToolsSwingLocator.getIconThemeManager();
64
        File folder = iconThemeManager.getRepository().asFile();        
65
	logger.info("Installing package '"+packageInfo.getCode()+"' in '"+folder.getAbsolutePath()+"'.");
66
        try {
67
            if (!folder.exists()) {
68
                String s = "Can install package '"+packageInfo.getCode()+"', install folder '"+folder+"' does not exists.";
69
		logger.warn(s);
70
		throw new RuntimeException(s);
71
            }
72
            decompress(inputStream, folder);
73
        } catch (Exception e) {
74
            try {
75
                logger.warn("Can install package '"+packageInfo.getCode()+"'.", e);
76
                // if there is an exception, installLater is called
77
                installLater(applicationFolder, inputStream, packageInfo);
78
            } catch (IOException e1) {
79
                logger.warn("Can install package '"+packageInfo.getCode()+"'.", e1);
80
                throw new InstallPackageServiceException(e1);
81
            }
82
        }
83

  
84
    }
85

  
86
    private void decompress(InputStream inputStream, File folder) 
87
        throws ZipException, IOException, InstallerInfoFileException {
88

  
89
        ZipInputStream zis;
90
        ZipEntry entry;
91
        byte data[] = new byte[BUFFER];
92
        int count;
93

  
94
        TaskStatusManager manager = ToolsLocator.getTaskStatusManager();
95
        SimpleTaskStatus taskStatus = manager.createDefaultSimpleTaskStatus("Uncompressing...");
96

  
97
        manager.add(taskStatus);
98
        String entryName = "(header)";
99
        try {
100
            long readed = 0;
101
            zis = new ZipInputStream(inputStream);
102
            while ((entry = zis.getNextEntry()) != null) {
103
                entryName = FilenameUtils.separatorsToSystem(entry.getName());
104
                taskStatus.message(entryName);
105

  
106
                File file = new File(folder, entryName);
107
                if (entry.isDirectory()) {
108
        		file.mkdirs();                    
109
                } else {
110
                    if (file.exists()) {
111
                         FileUtils.forceDelete(file);
112
                    }
113
                    if( !file.getParentFile().exists() ) {
114
                        FileUtils.forceMkdir(file.getParentFile());
115
                    }
116
                    logger.debug("extracting " + file.getAbsolutePath());
117
                    try (FileOutputStream fos = new FileOutputStream(file)) {
118
                        while ((count = zis.read(data, 0, BUFFER)) != -1) {
119
                            fos.write(data, 0, count);
120
                            readed += count;
121
                            taskStatus.setCurValue(readed);
122
                        }
123
                        fos.flush();
124
                    }
125
                }
126
            }
127
            zis.close();
128
        } catch(Exception ex) {
129
                logger.warn("Problems uncompresing 'translations' (last entry '"+entryName+"'.",ex);
130
                throw ex;
131
        } finally {
132
            taskStatus.remove();
133

  
134
        }
135
    }
136

  
137
    
138
    @Override
139
    public void installLater(File applicationDirectory, InputStream inputStream, PackageInfo packageInfo) throws InstallPackageServiceException, IOException {
140
        logger.warn("installLater is not implementes.");
141
    }
142

  
143
}
trunk/org.gvsig.desktop/org.gvsig.desktop.framework/org.gvsig.andami/src/main/java/org/gvsig/andami/Launcher.java
3195 3195
        PluginsManager pluginsManager = PluginsLocator.getManager();
3196 3196
        IconThemeManager iconManager = ToolsSwingLocator.getIconThemeManager();
3197 3197

  
3198
        File f = new File(pluginsManager.getApplicationFolder(), "icon-theme");
3198
        File f = new File(pluginsManager.getApplicationHomeFolder(), "icon-theme");
3199 3199
        if (!f.exists()) {
3200 3200
            try {
3201 3201
                f.mkdir();
......
3203 3203
                // Do nothing
3204 3204
            }
3205 3205
        }
3206
        iconManager.getRepository().add(f, "_Global");
3206
        iconManager.getRepository().add(f, "_User");
3207 3207

  
3208
        f = new File(pluginsManager.getApplicationHomeFolder(), "icon-theme");
3208
        f = new File(pluginsManager.getApplicationFolder(), "icon-theme");
3209 3209
        if (!f.exists()) {
3210 3210
            try {
3211 3211
                f.mkdir();
......
3213 3213
                // Do nothing
3214 3214
            }
3215 3215
        }
3216
        iconManager.getRepository().add(f, "_User");
3216
        iconManager.getRepository().add(f, "_Global");
3217 3217

  
3218 3218
        Preferences prefs = Preferences.userRoot().node("gvsig.icontheme");
3219 3219
        String defaultThemeID = prefs.get("default-theme", null);

Also available in: Unified diff