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

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

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

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

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

    
98

    
99
        }
100
}
101