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 / info / InstallerInfoFileWriter.java @ 32498

History | View | Annotate | Download (3.42 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.info;
29

    
30
import java.io.File;
31
import java.io.FileNotFoundException;
32
import java.io.FileOutputStream;
33
import java.io.IOException;
34
import java.io.OutputStream;
35
import java.util.Properties;
36

    
37
import org.gvsig.installer.lib.api.InstallerInfo;
38
import org.gvsig.installer.lib.spi.InstallerInfoFileException;
39

    
40
/**
41
 * @author <a href="mailto:jpiera@gvsig.org">Jorge Piera Llodr&aacute;</a>
42
 */
43
public class InstallerInfoFileWriter {
44

    
45
        /**
46
         * Writes the install.info file 
47
         * @param fileName
48
         * The file name to write the installation information
49
         * @param installInfo
50
         * The installation information
51
         * @throws InstallerInfoFileException
52
         */
53
        public void write(InstallerInfo installInfo, String fileName) throws InstallerInfoFileException{
54
                write(installInfo, new File(fileName));
55
        }
56

    
57
        /**
58
         * Writes the install.info file 
59
         * @param file
60
         * The file to write the installation information
61
         * @param installInfo
62
         * The installation information
63
         * @throws InstallerInfoFileException
64
         */
65
        public void write(InstallerInfo installInfo, File file) throws InstallerInfoFileException{
66
                try {
67
                        write(installInfo, new FileOutputStream(file));
68
                } catch (FileNotFoundException e) {
69
                        throw new InstallerInfoFileException("install_infofile_not_found", e);
70
                }
71
        }
72
        
73
        /**
74
         * Writes the install.info file 
75
         * @param os
76
         * The file to write the installation information
77
         * @param installInfo
78
         * The installation information
79
         * @throws InstallerInfoFileException
80
         */
81
        public void write(InstallerInfo installInfo, OutputStream os) throws InstallerInfoFileException{
82
                try {                        
83
                        //Fill the properties
84
                        Properties properties = new Properties();        
85
                        properties.setProperty(InstallerInfoTags.CODE, installInfo.getCode());
86
                        properties.setProperty(InstallerInfoTags.NAME, installInfo.getName());
87
                        properties.setProperty(InstallerInfoTags.DESCRIPCTION, installInfo.getDescription());
88
                        properties.setProperty(InstallerInfoTags.VERSION, installInfo.getVersion());
89
                        properties.setProperty(InstallerInfoTags.BUILD, new Integer(installInfo.getBuild()).toString());
90
                        properties.setProperty(InstallerInfoTags.STATE, installInfo.getState());
91
                        properties.setProperty(InstallerInfoTags.OFFCICIAL, new Boolean(installInfo.isOfficial()).toString());                
92
                        properties.setProperty(InstallerInfoTags.TYPE, installInfo.getType());
93
                        properties.store(os, "");
94
                        os.close();
95
                } catch (IOException e) {
96
                        throw new InstallerInfoFileException("install_infofile_writing_error", e);
97
                }
98

    
99

    
100
        }
101
}
102