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
/* 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
import java.io.OutputStream;
33
import java.util.List;
34
import java.util.Map;
35

    
36
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
import org.gvsig.installer.lib.impl.info.InstallerInfoFileReader;
40
import org.gvsig.installer.lib.impl.info.InstallerInfoFileWriter;
41
import org.gvsig.installer.lib.impl.utils.Compress;
42
import org.gvsig.installer.lib.impl.utils.Decompress;
43
import org.gvsig.installer.lib.spi.InstallerInfoFileException;
44
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
        private static final String INSTALL_INFO_FILE = "package.info";
52
        
53
        public void decompress(InputStream is, File outputDirectory) throws InstallPackageServiceException {
54
                Decompress decompress = new Decompress();
55
                decompress.decompressPlugin(is, outputDirectory);                
56
        }
57

    
58
        public PackageInfo readCompressedInstallInfo(InputStream is) throws InstallPackageServiceException {
59
                Decompress decompress = new Decompress();
60
                try {
61
                        return decompress.readInstallerInfo(is);
62
                } catch (InstallerInfoFileException e) {
63
                        throw new InstallPackageServiceException("Exception reading a compressed file", e);
64
                }
65
        }
66

    
67
        public void compress(File directory, String fileName, OutputStream os)
68
                        throws MakePluginPackageServiceException {
69
                Compress compress = new Compress();
70
                compress.compressPlugin(directory, fileName, os);        
71
                
72
        }
73

    
74
        public void readInstallInfo(File directory, PackageInfo installerInfo) throws InstallerInfoFileException {
75
                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
        public void writeInstallInfo(File directory, PackageInfo installerInfo) throws InstallerInfoFileException {
86
                if (!directory.exists()){
87
                        throw new InstallerInfoFileException("The directory doesn't exist");
88
                }
89
                InstallerInfoFileWriter installerInfoFileWriter = new InstallerInfoFileWriter();
90
                installerInfoFileWriter.write(installerInfo, directory + File.separator + INSTALL_INFO_FILE);                
91
        }
92

    
93
        public InputStream searchPlugin(InputStream is, String zipEntry) throws InstallPackageServiceException {
94
                Decompress decompress = new Decompress();
95
                return decompress.searchPlugin(is, zipEntry);        
96
        }
97

    
98
        public void readInstallInfo(InputStream is,
99
                        List<PackageInfo> installerInfos,
100
                        Map<PackageInfo, String> zipEntriesMap)
101
                        throws InstallPackageServiceException {
102
                Decompress decompress = new Decompress();                        
103
                decompress.readInstallInfo(is, installerInfos, zipEntriesMap);                        
104
        }
105

    
106
}
107