Statistics
| Revision:

svn-gvsig-desktop / 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 / DefaultInstallerProviderServices.java @ 43126

History | View | Annotate | Download (6.57 KB)

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
 * 2010 {Prodevelop}   {Task}
27
 */
28

    
29
package org.gvsig.installer.lib.impl;
30

    
31
import java.io.File;
32
import java.io.InputStream;
33
import java.io.OutputStream;
34
import java.util.List;
35
import java.util.Map;
36
import java.util.Properties;
37

    
38
import org.gvsig.installer.lib.api.PackageInfo;
39
import org.gvsig.installer.lib.api.creation.MakePluginPackageServiceException;
40
import org.gvsig.installer.lib.api.execution.InstallPackageServiceException;
41
import org.gvsig.installer.lib.impl.info.InstallerInfoFileReader;
42
import org.gvsig.installer.lib.impl.info.InstallerInfoFileWriter;
43
import org.gvsig.installer.lib.impl.utils.Compress;
44
import org.gvsig.installer.lib.impl.utils.Decompress;
45
import org.gvsig.installer.lib.spi.InstallPackageProviderServices;
46
import org.gvsig.installer.lib.spi.InstallerInfoFileException;
47
import org.gvsig.installer.lib.spi.InstallerProviderLocator;
48
import org.gvsig.tools.service.spi.AbstractProviderServices;
49
import org.gvsig.tools.task.SimpleTaskStatus;
50

    
51
/**
52
 * @author <a href="mailto:jpiera@gvsig.org">Jorge Piera Llodr&aacute;</a>
53
 */
54
public class DefaultInstallerProviderServices extends AbstractProviderServices
55
                implements InstallPackageProviderServices {
56

    
57
    private List<String> defaultSelectedPacketsIDs = null;
58
    private Properties properties;
59

    
60
        // private static final Logger LOG = LoggerFactory
61
        // .getLogger(DefaultInstallerProviderServices.class);
62

    
63
        public void decompress(InputStream is, File outputDirectory)
64
                        throws InstallPackageServiceException {
65
                Decompress decompress = new Decompress();
66
                decompress.decompressPlugin(is, outputDirectory);
67
        }
68

    
69
        public class ReadPackageException extends InstallPackageServiceException {
70

    
71
                private static final long serialVersionUID = 1989187468965303199L;
72

    
73
                private static final String message = "Exception reading a compressed file";
74

    
75
                private static final String KEY = "Exception_reading_a_compressed_file";
76

    
77
                public ReadPackageException(InstallerInfoFileException e) {
78
                        super(message, e, KEY, serialVersionUID);
79
                }
80

    
81
        }
82

    
83
        public PackageInfo readCompressedPackageInfo(InputStream is)
84
                        throws InstallPackageServiceException {
85
                Decompress decompress = new Decompress();
86
                try {
87
                        return decompress.readInstallerInfo(is);
88
                } catch (InstallerInfoFileException e) {
89
                        throw new ReadPackageException(e);
90
                }
91
        }
92

    
93
        public void compressPackageSet(File folder, String fileName, OutputStream os)
94
                        throws MakePluginPackageServiceException {
95
                Compress compress = new Compress();
96
                compress.compressPluginAsPackageSet(folder, fileName, os);
97
        }
98

    
99
        public void compressPackage(File folder, OutputStream os)
100
                        throws MakePluginPackageServiceException {
101
                Compress compress = new Compress();
102
                compress.compressPluginAsPackage(folder, os);
103
        }
104

    
105
        public void compressPackageIndex(File folder, OutputStream os)
106
                        throws MakePluginPackageServiceException {
107
                Compress compress = new Compress();
108
                compress.compressPluginAsPackageIndex(folder, os);
109
        }
110

    
111
        public void readPackageInfo(File directory, PackageInfo installerInfo)
112
                        throws InstallerInfoFileException {
113
                File installInfoFile = new File(directory + File.separator
114
                                + getPackageInfoFileName());
115
                if (installInfoFile.exists()) {
116
                        InstallerInfoFileReader reader = new InstallerInfoFileReader();
117
                        reader.read(installerInfo, installInfoFile.getAbsolutePath());
118
                }
119

    
120
                if (installerInfo.getCode() == null) {
121
                        installerInfo.setCode(directory.getName());
122
                }
123
                if (installerInfo.getName() == null) {
124
                        installerInfo.setName(directory.getName());
125
                }
126
        }
127

    
128
        private String getPackageInfoFileName() {
129
                return InstallerProviderLocator.getProviderManager()
130
                                .getPackageInfoFileName();
131
        }
132

    
133
        public void writePackageInfo(File directory, PackageInfo packageInfo)
134
                        throws InstallerInfoFileException {
135
                writePackageInfoFile(directory, getPackageInfoFileName(), packageInfo);
136
        }
137

    
138
        public void writePackageInfoForIndex(File directory, PackageInfo packageInfo)
139
                        throws InstallerInfoFileException {
140
                writePackageInfoFile(directory, getPackageInfoFileName() + ".index",
141
                                packageInfo);
142
        }
143

    
144
        private void writePackageInfoFile(File directory, String fileName,
145
                        PackageInfo installerInfo) throws InstallerInfoFileException {
146
                if (!directory.exists()) {
147
                        // throw new
148
                        // InstallerInfoFileException("The directory doesn't exist");
149
                        directory.mkdir();
150
                }
151
                InstallerInfoFileWriter installerInfoFileWriter = new InstallerInfoFileWriter();
152
                installerInfoFileWriter.write(installerInfo, directory + File.separator
153
                                + fileName);
154
        }
155

    
156
        public InputStream searchPackage(InputStream is, String zipEntry)
157
                        throws InstallPackageServiceException {
158
                Decompress decompress = new Decompress();
159
                return decompress.searchPlugin(is, zipEntry);
160
        }
161

    
162
    @Override
163
        public void readPackageSetInfo(InputStream is,
164
                        List<PackageInfo> installerInfos,
165
                        Map<PackageInfo, String> zipEntriesMap, SimpleTaskStatus taskStatus)
166
                        throws InstallPackageServiceException {
167
                Decompress decompress = new Decompress(taskStatus);
168
                decompress.readPackageSetInstallInfos(is, installerInfos, zipEntriesMap);
169

    
170
                defaultSelectedPacketsIDs = decompress.getDefaultSelectedPackages();
171
                properties = decompress.getProperties();
172
        }
173

    
174
    @Override
175
        public void readPackageInfo(InputStream is,
176
                        List<PackageInfo> installerInfos,
177
                        Map<PackageInfo, String> zipEntriesMap, String name, SimpleTaskStatus taskStatus)
178
                        throws InstallPackageServiceException {
179

    
180
                Decompress decompress = new Decompress(taskStatus);
181
                decompress.readPackageInstallInfo(is, installerInfos, zipEntriesMap,
182
                                name);
183
        }
184

    
185
    @Override
186
    public List<String> getDefaultSelectedPackagesIDs() {
187
            return defaultSelectedPacketsIDs;
188
    }
189

    
190
    @Override
191
    public Properties getProperties() {
192
            return properties;
193
    }
194
}