Statistics
| Revision:

svn-gvsig-desktop / 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 @ 32585

History | View | Annotate | Download (4.04 KB)

1 32400 jpiera
/* gvSIG. Geographic Information System of the Valencian Government
2
*
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
23
/*
24
* AUTHORS (In addition to CIT):
25
* 2010 {Prodevelop}   {Task}
26
*/
27
28
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 32498 jpiera
import org.gvsig.installer.lib.spi.InstallerInfoFileException;
44 32400 jpiera
import org.gvsig.installer.lib.spi.InstallerProviderServices;
45
import org.gvsig.tools.service.spi.AbstractProviderServices;
46
47
/**
48
 * @author <a href="mailto:jpiera@gvsig.org">Jorge Piera Llodr&aacute;</a>
49
 */
50
public class DefaultInstallerProviderServices extends AbstractProviderServices implements InstallerProviderServices{
51 32585 jpiera
        private static final String INSTALL_INFO_FILE = "package.info";
52 32498 jpiera
53 32562 jpiera
        public void decompress(InputStream is, File outputDirectory) throws InstallPackageServiceException {
54 32400 jpiera
                Decompress decompress = new Decompress();
55
                decompress.decompressPlugin(is, outputDirectory);
56
        }
57
58 32562 jpiera
        public PackageInfo readCompressedInstallInfo(InputStream is) throws InstallPackageServiceException {
59 32400 jpiera
                Decompress decompress = new Decompress();
60
                try {
61
                        return decompress.readInstallerInfo(is);
62
                } catch (InstallerInfoFileException e) {
63 32562 jpiera
                        throw new InstallPackageServiceException("Exception reading a compressed file", e);
64 32400 jpiera
                }
65
        }
66
67 32498 jpiera
        public void compress(File directory, String fileName, OutputStream os)
68 32562 jpiera
                        throws MakePluginPackageServiceException {
69 32498 jpiera
                Compress compress = new Compress();
70
                compress.compressPlugin(directory, fileName, os);
71
72
        }
73
74 32562 jpiera
        public void readInstallInfo(File directory, PackageInfo installerInfo) throws InstallerInfoFileException {
75 32498 jpiera
                File installInfoFile = new File (directory + File.separator + INSTALL_INFO_FILE);
76
                if (installInfoFile.exists()){
77
                        InstallerInfoFileReader reader = new InstallerInfoFileReader();
78
                        reader.read(installerInfo, installInfoFile.getAbsolutePath());
79
                }else{
80
                        installerInfo.setCode(directory.getName());
81
                        installerInfo.setName(directory.getName());
82
                }
83
        }
84
85 32562 jpiera
        public void writeInstallInfo(File directory, PackageInfo installerInfo) throws InstallerInfoFileException {
86 32498 jpiera
                if (!directory.exists()){
87
                        throw new InstallerInfoFileException("The directory doesn't exist");
88
                }
89
                InstallerInfoFileWriter installerInfoFileWriter = new InstallerInfoFileWriter();
90 32516 jpiera
                installerInfoFileWriter.write(installerInfo, directory + File.separator + INSTALL_INFO_FILE);
91 32498 jpiera
        }
92
93 32562 jpiera
        public InputStream searchPlugin(InputStream is, String zipEntry) throws InstallPackageServiceException {
94 32498 jpiera
                Decompress decompress = new Decompress();
95
                return decompress.searchPlugin(is, zipEntry);
96
        }
97
98 32500 jpiera
        public void readInstallInfo(InputStream is,
99 32562 jpiera
                        List<PackageInfo> installerInfos,
100
                        Map<PackageInfo, String> zipEntriesMap)
101
                        throws InstallPackageServiceException {
102 32500 jpiera
                Decompress decompress = new Decompress();
103
                decompress.readInstallInfo(is, installerInfos, zipEntriesMap);
104
        }
105
106 32400 jpiera
}