Statistics
| Revision:

root / branches / v2_0_0_prep / extensions / org.gvsig.installer / org.gvsig.installer.lib / org.gvsig.installer.lib.impl / src / main / java / org / gvsig / installer / lib / impl / DefaultInstallerProviderServices.java @ 38600

History | View | Annotate | Download (6.14 KB)

1 32400 jpiera
/* gvSIG. Geographic Information System of the Valencian Government
2 33729 cordinyana
 *
3
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
4
 * of the Valencian Government (CIT)
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 2
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
 */
22 32400 jpiera
23
/*
24 33729 cordinyana
 * AUTHORS (In addition to CIT):
25
 * 2010 {Prodevelop}   {Task}
26
 */
27
28 32400 jpiera
package org.gvsig.installer.lib.impl;
29
30
import java.io.File;
31
import java.io.InputStream;
32 32498 jpiera
import java.io.OutputStream;
33 32500 jpiera
import java.util.List;
34
import java.util.Map;
35 32400 jpiera
36 32562 jpiera
import org.gvsig.installer.lib.api.PackageInfo;
37
import org.gvsig.installer.lib.api.creation.MakePluginPackageServiceException;
38
import org.gvsig.installer.lib.api.execution.InstallPackageServiceException;
39 32498 jpiera
import org.gvsig.installer.lib.impl.info.InstallerInfoFileReader;
40
import org.gvsig.installer.lib.impl.info.InstallerInfoFileWriter;
41 32500 jpiera
import org.gvsig.installer.lib.impl.utils.Compress;
42
import org.gvsig.installer.lib.impl.utils.Decompress;
43 32627 jpiera
import org.gvsig.installer.lib.spi.InstallPackageProviderServices;
44 32498 jpiera
import org.gvsig.installer.lib.spi.InstallerInfoFileException;
45 34444 cordinyana
import org.gvsig.installer.lib.spi.InstallerProviderLocator;
46 32400 jpiera
import org.gvsig.tools.service.spi.AbstractProviderServices;
47
48
/**
49
 * @author <a href="mailto:jpiera@gvsig.org">Jorge Piera Llodr&aacute;</a>
50
 */
51 33729 cordinyana
public class DefaultInstallerProviderServices extends AbstractProviderServices
52 34158 cordinyana
                implements InstallPackageProviderServices {
53 32400 jpiera
54 37599 nfrancisco
        private List<String> defaultSelectedPacketsIDs = null;
55 33982 cordinyana
56 37599 nfrancisco
        // private static final Logger LOG = LoggerFactory
57
        // .getLogger(DefaultInstallerProviderServices.class);
58
59 34158 cordinyana
        public void decompress(InputStream is, File outputDirectory)
60
                        throws InstallPackageServiceException {
61
                Decompress decompress = new Decompress();
62
                decompress.decompressPlugin(is, outputDirectory);
63
        }
64 32498 jpiera
65 37599 nfrancisco
        public class ReadPackageException extends InstallPackageServiceException {
66 35946 nfrancisco
67 37599 nfrancisco
                private static final long serialVersionUID = 1989187468965303199L;
68 35946 nfrancisco
69 37599 nfrancisco
                private static final String message = "Exception reading a compressed file";
70 35946 nfrancisco
71 37599 nfrancisco
                private static final String KEY = "Exception_reading_a_compressed_file";
72 35946 nfrancisco
73 37599 nfrancisco
                public ReadPackageException(InstallerInfoFileException e) {
74
                        super(message, e, KEY, serialVersionUID);
75
                }
76 35946 nfrancisco
77 37599 nfrancisco
        }
78
79 34158 cordinyana
        public PackageInfo readCompressedPackageInfo(InputStream is)
80
                        throws InstallPackageServiceException {
81
                Decompress decompress = new Decompress();
82
                try {
83
                        return decompress.readInstallerInfo(is);
84
                } catch (InstallerInfoFileException e) {
85 35946 nfrancisco
                        throw new ReadPackageException(e);
86 34158 cordinyana
                }
87
        }
88 32498 jpiera
89 34158 cordinyana
        public void compressPackageSet(File folder, String fileName, OutputStream os)
90
                        throws MakePluginPackageServiceException {
91
                Compress compress = new Compress();
92
                compress.compressPluginAsPackageSet(folder, fileName, os);
93
        }
94 32498 jpiera
95 34158 cordinyana
        public void compressPackage(File folder, OutputStream os)
96
                        throws MakePluginPackageServiceException {
97
                Compress compress = new Compress();
98
                compress.compressPluginAsPackage(folder, os);
99
        }
100 32498 jpiera
101 37599 nfrancisco
        public void compressPackageIndex(File folder, OutputStream os)
102
                        throws MakePluginPackageServiceException {
103
                Compress compress = new Compress();
104
                compress.compressPluginAsPackageIndex(folder, os);
105
        }
106 34444 cordinyana
107 34158 cordinyana
        public void readPackageInfo(File directory, PackageInfo installerInfo)
108
                        throws InstallerInfoFileException {
109
                File installInfoFile = new File(directory + File.separator
110 37599 nfrancisco
                                + getPackageInfoFileName());
111 34158 cordinyana
                if (installInfoFile.exists()) {
112
                        InstallerInfoFileReader reader = new InstallerInfoFileReader();
113
                        reader.read(installerInfo, installInfoFile.getAbsolutePath());
114
                }
115 32500 jpiera
116 34158 cordinyana
                if (installerInfo.getCode() == null) {
117
                        installerInfo.setCode(directory.getName());
118
                }
119
                if (installerInfo.getName() == null) {
120
                        installerInfo.setName(directory.getName());
121
                }
122
        }
123 33729 cordinyana
124 37599 nfrancisco
        private String getPackageInfoFileName() {
125
                return InstallerProviderLocator.getProviderManager()
126
                                .getPackageInfoFileName();
127
        }
128 34444 cordinyana
129 37599 nfrancisco
        public void writePackageInfo(File directory, PackageInfo packageInfo)
130 34158 cordinyana
                        throws InstallerInfoFileException {
131 37599 nfrancisco
                writePackageInfoFile(directory, getPackageInfoFileName(), packageInfo);
132 34158 cordinyana
        }
133 33729 cordinyana
134 37599 nfrancisco
        public void writePackageInfoForIndex(File directory, PackageInfo packageInfo)
135
                        throws InstallerInfoFileException {
136
                writePackageInfoFile(directory, getPackageInfoFileName() + ".index",
137
                                packageInfo);
138
        }
139 34444 cordinyana
140 37599 nfrancisco
        private void writePackageInfoFile(File directory, String fileName,
141
                        PackageInfo installerInfo) throws InstallerInfoFileException {
142
                if (!directory.exists()) {
143 37822 nfrancisco
                        // throw new
144
                        // InstallerInfoFileException("The directory doesn't exist");
145
                        directory.mkdir();
146 37599 nfrancisco
                }
147
                InstallerInfoFileWriter installerInfoFileWriter = new InstallerInfoFileWriter();
148
                installerInfoFileWriter.write(installerInfo, directory + File.separator
149
                                + fileName);
150
        }
151 34444 cordinyana
152 37599 nfrancisco
        public InputStream searchPackage(InputStream is, String zipEntry)
153 34158 cordinyana
                        throws InstallPackageServiceException {
154
                Decompress decompress = new Decompress();
155
                return decompress.searchPlugin(is, zipEntry);
156
        }
157 34020 cordinyana
158 34158 cordinyana
        public void readPackageSetInfo(InputStream is,
159
                        List<PackageInfo> installerInfos,
160
                        Map<PackageInfo, String> zipEntriesMap)
161
                        throws InstallPackageServiceException {
162
                Decompress decompress = new Decompress();
163
                decompress
164
                                .readPackageSetInstallInfos(is, installerInfos, zipEntriesMap);
165 37599 nfrancisco
166 35189 nfrancisco
                defaultSelectedPacketsIDs = decompress.getDefaultSelectedPackages();
167 34158 cordinyana
        }
168 34020 cordinyana
169 34158 cordinyana
        public void readPackageInfo(InputStream is,
170
                        List<PackageInfo> installerInfos,
171
                        Map<PackageInfo, String> zipEntriesMap, String name)
172
                        throws InstallPackageServiceException {
173 33729 cordinyana
174 34158 cordinyana
                Decompress decompress = new Decompress();
175
                decompress.readPackageInstallInfo(is, installerInfos, zipEntriesMap,
176
                                name);
177 37599 nfrancisco
        }
178 34003 cordinyana
179 37599 nfrancisco
        public List<String> getDefaultSelectedPackagesIDs() {
180
                return defaultSelectedPacketsIDs;
181
        }
182 32400 jpiera
}