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 / InstallerInfoFileReader.java @ 32333
History | View | Annotate | Download (4.34 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.util.Properties; |
36 |
|
37 |
import org.gvsig.installer.lib.api.InstallerInfo; |
38 |
|
39 |
|
40 |
/**
|
41 |
* @author <a href="mailto:jpiera@gvsig.org">Jorge Piera Llodrá</a>
|
42 |
*/
|
43 |
public class InstallerInfoFileReader { |
44 |
|
45 |
public InstallerInfoFileReader()
|
46 |
{ |
47 |
|
48 |
} |
49 |
|
50 |
/**
|
51 |
* Reads and parses the install.info file and creates one object that contains
|
52 |
* the information.
|
53 |
* @param fileName
|
54 |
* The file name that contains the install.info information.
|
55 |
* @return
|
56 |
* An object with the information about the installation
|
57 |
* @throws InstallerInfoFileException
|
58 |
*/
|
59 |
public void read(InstallerInfo installerInfoResource, String fileName) throws InstallerInfoFileException{ |
60 |
read(installerInfoResource, new File(fileName)); |
61 |
} |
62 |
|
63 |
/**
|
64 |
* Reads and parses the install.info file and creates one object that contains
|
65 |
* the information.
|
66 |
* @param file
|
67 |
* The file that contains the install.info information.
|
68 |
* @return
|
69 |
* An object with the information about the installation
|
70 |
* @throws InstallerInfoFileException
|
71 |
*/
|
72 |
public void read(InstallerInfo installerInfoResource, File file) throws InstallerInfoFileException{ |
73 |
if (!file.exists()){
|
74 |
throw new InstallerInfoFileException("install_infofile_not_found"); |
75 |
} |
76 |
try {
|
77 |
read(installerInfoResource, new FileInputStream(file)); |
78 |
} catch (FileNotFoundException e) { |
79 |
throw new InstallerInfoFileException("install_infofile_not_found", e); |
80 |
} |
81 |
} |
82 |
|
83 |
/**
|
84 |
* Reads and parses the install.info file and creates one object that contains
|
85 |
* the information.
|
86 |
* @param is
|
87 |
* The input stream that contains the install.info information.
|
88 |
* @return
|
89 |
* An object with the information about the installation
|
90 |
* @throws InstallerInfoFileException
|
91 |
*/
|
92 |
public void read(InstallerInfo installerInfoResource, InputStream is) throws InstallerInfoFileException{ |
93 |
Properties properties = new Properties(); |
94 |
try {
|
95 |
properties.load(is); |
96 |
is.close(); |
97 |
} catch (IOException e) { |
98 |
throw new InstallerInfoFileException("install_infofile_reading_error", e); |
99 |
} |
100 |
//Checks if the file contains the minumum attributes
|
101 |
if (!properties.containsKey(InstallerInfoTags.CODE)){
|
102 |
throw new NotPropertyFoundException(InstallerInfoTags.CODE); |
103 |
} |
104 |
|
105 |
if (!properties.containsKey(InstallerInfoTags.NAME)){
|
106 |
throw new NotPropertyFoundException(InstallerInfoTags.NAME); |
107 |
} |
108 |
|
109 |
installerInfoResource.setCode(properties.getProperty(InstallerInfoTags.CODE)); |
110 |
installerInfoResource.setName(properties.getProperty(InstallerInfoTags.NAME)); |
111 |
installerInfoResource.setDescription(properties.getProperty(InstallerInfoTags.DESCRIPCTION)); |
112 |
installerInfoResource.setVersion(properties.getProperty(InstallerInfoTags.VERSION)); |
113 |
installerInfoResource.setType(properties.getProperty(InstallerInfoTags.TYPE)); |
114 |
String build = properties.getProperty(InstallerInfoTags.BUILD);
|
115 |
try{
|
116 |
installerInfoResource.setBuild(Integer.parseInt(properties.getProperty(InstallerInfoTags.BUILD)));
|
117 |
}catch(Exception e){ |
118 |
installerInfoResource.setBuild(0);
|
119 |
} |
120 |
installerInfoResource.setState(properties.getProperty(InstallerInfoTags.STATE)); |
121 |
try{
|
122 |
installerInfoResource.setOfficial(Boolean.parseBoolean(properties.getProperty(InstallerInfoTags.OFFCICIAL)));
|
123 |
}catch(Exception e){ |
124 |
installerInfoResource.setOfficial(false);
|
125 |
} |
126 |
} |
127 |
|
128 |
} |
129 |
|