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