Statistics
| Revision:

svn-gvsig-desktop / tags / v2_0_0_Build_2021 / extensions / org.gvsig.installer / org.gvsig.installer.lib / org.gvsig.installer.lib.impl / src / main / java / org / gvsig / installer / lib / impl / info / InstallerInfoFileReader.java @ 34107

History | View | Annotate | Download (6.28 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.FileInputStream;
32
import java.io.FileNotFoundException;
33
import java.io.IOException;
34
import java.io.InputStream;
35
import java.net.MalformedURLException;
36
import java.net.URL;
37
import java.util.Properties;
38

    
39
import org.gvsig.installer.lib.api.PackageInfo;
40
import org.gvsig.installer.lib.spi.InstallerInfoFileException;
41

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

    
47
    /**
48
     * Reads and parses the install.info file and creates one object that
49
     * contains
50
     * the information.
51
     * 
52
     * @param fileName
53
     *            The file name that contains the install.info information.
54
     * @return
55
     *         An object with the information about the installation
56
     * @throws InstallerInfoFileException
57
     */
58
    public void read(PackageInfo installerInfoResource, String fileName)
59
        throws InstallerInfoFileException {
60
        read(installerInfoResource, new File(fileName));
61
    }
62

    
63
    /**
64
     * Reads and parses the install.info file and creates one object that
65
     * contains
66
     * the information.
67
     * 
68
     * @param file
69
     *            The file that contains the install.info information.
70
     * @return
71
     *         An object with the information about the installation
72
     * @throws InstallerInfoFileException
73
     */
74
    public void read(PackageInfo installerInfoResource, File file)
75
        throws InstallerInfoFileException {
76
        if (!file.exists()) {
77
            throw new InstallerInfoFileException("install_infofile_not_found");
78
        }
79
        try {
80
            read(installerInfoResource, new FileInputStream(file));
81
        } catch (FileNotFoundException e) {
82
            throw new InstallerInfoFileException("install_infofile_not_found",
83
                e);
84
        }
85
    }
86

    
87
    /**
88
     * Reads and parses the install.info file and creates one object that
89
     * contains
90
     * the information.
91
     * 
92
     * @param is
93
     *            The input stream that contains the install.info information.
94
     * @return
95
     *         An object with the information about the installation
96
     * @throws InstallerInfoFileException
97
     */
98
    public void read(PackageInfo installerInfoResource, InputStream is)
99
        throws InstallerInfoFileException {
100
        Properties properties = new Properties();
101
        try {
102
            properties.load(is);
103
            is.close();
104
        } catch (IOException e) {
105
            throw new InstallerInfoFileException(
106
                "install_infofile_reading_error", e);
107
        }
108
        // Checks if the file contains the minumum attributes
109
        if (!properties.containsKey(InstallerInfoTags.CODE)) {
110
            throw new NotPropertyFoundException(InstallerInfoTags.CODE);
111
        }
112

    
113
        if (!properties.containsKey(InstallerInfoTags.NAME)) {
114
            throw new NotPropertyFoundException(InstallerInfoTags.NAME);
115
        }
116

    
117
        installerInfoResource.setCode(properties
118
            .getProperty(InstallerInfoTags.CODE));
119
        installerInfoResource.setName(properties
120
            .getProperty(InstallerInfoTags.NAME));
121
        installerInfoResource.setDescription(properties
122
            .getProperty(InstallerInfoTags.DESCRIPTION));
123
        installerInfoResource.setVersion(properties
124
            .getProperty(InstallerInfoTags.VERSION));
125
        installerInfoResource.setType(properties
126
            .getProperty(InstallerInfoTags.TYPE));
127
        String build = properties.getProperty(InstallerInfoTags.BUILD);
128
        try {
129
            installerInfoResource.setBuild(Integer.parseInt(build));
130
        } catch (Exception e) {
131
            installerInfoResource.setBuild(0);
132
        }
133
        installerInfoResource.setState(properties
134
            .getProperty(InstallerInfoTags.STATE));
135
        try {
136
            installerInfoResource.setOfficial(Boolean.parseBoolean(properties
137
                .getProperty(InstallerInfoTags.OFFICIAL)));
138
        } catch (Exception e) {
139
            installerInfoResource.setOfficial(false);
140
        }
141

    
142
        String os = properties.getProperty(InstallerInfoTags.OS);
143
        if (os != null) {
144
            installerInfoResource.setOperatingSystem(os);
145
        }
146

    
147
        String arch = properties.getProperty(InstallerInfoTags.ARCHITECTURE);
148
        if (arch != null) {
149
            installerInfoResource.setArchitecture(arch);
150
        }
151

    
152
        String jvm = properties.getProperty(InstallerInfoTags.JVM);
153
        if (jvm != null) {
154
            installerInfoResource.setJavaVM(jvm);
155
        }
156

    
157
        installerInfoResource.setGvSIGVersion(properties
158
            .getProperty(InstallerInfoTags.GVSIG_VERSION));
159

    
160
        String urlStr = properties.getProperty(InstallerInfoTags.DOWNLOAD_URL);
161
        if (urlStr != null) {
162
            URL downloadURL;
163
            try {
164
                downloadURL = new URL(urlStr);
165
            } catch (MalformedURLException e) {
166
                throw new InstallerInfoFileException(
167
                    "Error getting the value of the download url property as URL: "
168
                        + urlStr, e);
169
            }
170
            installerInfoResource.setDownloadURL(downloadURL);
171
        }
172

    
173
        String modelVersion =
174
            properties.getProperty(InstallerInfoTags.MODEL_VERSION);
175
        if (modelVersion != null) {
176
            installerInfoResource.setModelVersion(modelVersion);
177
        }
178
    }
179

    
180
}