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 | 40560 | jjdelcerro | /**
|
---|---|---|---|
2 | * gvSIG. Desktop Geographic Information System.
|
||
3 | 40435 | jjdelcerro | *
|
4 | 40560 | jjdelcerro | * Copyright (C) 2007-2013 gvSIG Association.
|
5 | *
|
||
6 | 40435 | jjdelcerro | * This program is free software; you can redistribute it and/or
|
7 | * modify it under the terms of the GNU General Public License
|
||
8 | 40560 | jjdelcerro | * as published by the Free Software Foundation; either version 3
|
9 | 40435 | jjdelcerro | * of the License, or (at your option) any later version.
|
10 | 40560 | jjdelcerro | *
|
11 | 40435 | jjdelcerro | * 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 | 40560 | jjdelcerro | *
|
16 | 40435 | jjdelcerro | * 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 | 40560 | jjdelcerro | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
19 | 40435 | jjdelcerro | * MA 02110-1301, USA.
|
20 | 40560 | jjdelcerro | *
|
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 | 40435 | jjdelcerro | */
|
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 | 43126 | jjdelcerro | import java.util.Properties; |
37 | 40435 | jjdelcerro | |
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 | 43126 | jjdelcerro | import org.gvsig.tools.task.SimpleTaskStatus; |
50 | 40435 | jjdelcerro | |
51 | /**
|
||
52 | * @author <a href="mailto:jpiera@gvsig.org">Jorge Piera Llodrá</a>
|
||
53 | */
|
||
54 | public class DefaultInstallerProviderServices extends AbstractProviderServices |
||
55 | implements InstallPackageProviderServices {
|
||
56 | |||
57 | 43126 | jjdelcerro | private List<String> defaultSelectedPacketsIDs = null; |
58 | private Properties properties; |
||
59 | 40435 | jjdelcerro | |
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 | 43126 | jjdelcerro | @Override
|
163 | 40435 | jjdelcerro | public void readPackageSetInfo(InputStream is, |
164 | List<PackageInfo> installerInfos,
|
||
165 | 43126 | jjdelcerro | Map<PackageInfo, String> zipEntriesMap, SimpleTaskStatus taskStatus) |
166 | 40435 | jjdelcerro | throws InstallPackageServiceException {
|
167 | 43126 | jjdelcerro | Decompress decompress = new Decompress(taskStatus);
|
168 | decompress.readPackageSetInstallInfos(is, installerInfos, zipEntriesMap); |
||
169 | 40435 | jjdelcerro | |
170 | defaultSelectedPacketsIDs = decompress.getDefaultSelectedPackages(); |
||
171 | 43126 | jjdelcerro | properties = decompress.getProperties(); |
172 | 40435 | jjdelcerro | } |
173 | |||
174 | 43126 | jjdelcerro | @Override
|
175 | 40435 | jjdelcerro | public void readPackageInfo(InputStream is, |
176 | List<PackageInfo> installerInfos,
|
||
177 | 43126 | jjdelcerro | Map<PackageInfo, String> zipEntriesMap, String name, SimpleTaskStatus taskStatus) |
178 | 40435 | jjdelcerro | throws InstallPackageServiceException {
|
179 | |||
180 | 43126 | jjdelcerro | Decompress decompress = new Decompress(taskStatus);
|
181 | 40435 | jjdelcerro | decompress.readPackageInstallInfo(is, installerInfos, zipEntriesMap, |
182 | name); |
||
183 | } |
||
184 | |||
185 | 43126 | jjdelcerro | @Override
|
186 | public List<String> getDefaultSelectedPackagesIDs() { |
||
187 | return defaultSelectedPacketsIDs;
|
||
188 | } |
||
189 | |||
190 | @Override
|
||
191 | public Properties getProperties() { |
||
192 | return properties;
|
||
193 | } |
||
194 | 40435 | jjdelcerro | } |