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 @ 32498

History | View | Annotate | Download (3.76 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

    
34
import org.gvsig.installer.lib.api.InstallerInfo;
35
import org.gvsig.installer.lib.api.creation.InstallerCreationServiceException;
36
import org.gvsig.installer.lib.api.execution.InstallerExecutionServiceException;
37
import org.gvsig.installer.lib.impl.creation.Compress;
38
import org.gvsig.installer.lib.impl.execution.Decompress;
39
import org.gvsig.installer.lib.impl.info.InstallerInfoFileReader;
40
import org.gvsig.installer.lib.impl.info.InstallerInfoFileWriter;
41
import org.gvsig.installer.lib.spi.InstallerInfoFileException;
42
import org.gvsig.installer.lib.spi.InstallerProviderServices;
43
import org.gvsig.tools.service.spi.AbstractProviderServices;
44

    
45
/**
46
 * @author <a href="mailto:jpiera@gvsig.org">Jorge Piera Llodr&aacute;</a>
47
 */
48
public class DefaultInstallerProviderServices extends AbstractProviderServices implements InstallerProviderServices{
49
        private static final String INSTALL_INFO_FILE = "install.info";
50
        
51
        public void decompress(InputStream is, File outputDirectory) throws InstallerExecutionServiceException {
52
                Decompress decompress = new Decompress();
53
                decompress.decompressPlugin(is, outputDirectory);                
54
        }
55

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

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

    
72
        public void readInstallInfo(File directory, InstallerInfo installerInfo) throws InstallerInfoFileException {
73
                File installInfoFile = new File (directory + File.separator + INSTALL_INFO_FILE);
74
                if (installInfoFile.exists()){
75
                        InstallerInfoFileReader reader = new InstallerInfoFileReader();
76
                        reader.read(installerInfo, installInfoFile.getAbsolutePath());
77
                }else{
78
                        installerInfo.setCode(directory.getName());
79
                        installerInfo.setName(directory.getName());
80
                }
81
        }
82

    
83
        public void writeInstallInfo(File directory, InstallerInfo installerInfo) throws InstallerInfoFileException {
84
                if (!directory.exists()){
85
                        throw new InstallerInfoFileException("The directory doesn't exist");
86
                }
87
                InstallerInfoFileWriter installerInfoFileWriter = new InstallerInfoFileWriter();
88
                installerInfoFileWriter.write(installerInfo, directory);// + File.separator + INSTALL_INFO_FILE);                
89
        }
90

    
91
        public InputStream searchPlugin(InputStream is, String zipEntry) throws InstallerExecutionServiceException {
92
                Decompress decompress = new Decompress();
93
                return decompress.searchPlugin(is, zipEntry);        
94
        }
95

    
96
}
97