gvsig-tools / org.gvsig.tools / library / trunk / org.gvsig.tools / org.gvsig.tools.lib / src / main / java / org / gvsig / tools / packageutils / impl / PackageInfoFileReader.java @ 807
History | View | Annotate | Download (4.46 KB)
1 |
/**
|
---|---|
2 |
* gvSIG. Desktop Geographic Information System.
|
3 |
*
|
4 |
* Copyright (C) 2007-2013 gvSIG Association.
|
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 |
* For any additional information, do not hesitate to contact us
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com.
|
23 |
*/
|
24 |
/*
|
25 |
* AUTHORS (In addition to CIT):
|
26 |
* 2010 {Prodevelop} {Task}
|
27 |
*/
|
28 |
|
29 |
package org.gvsig.tools.packageutils.impl; |
30 |
|
31 |
import java.io.File; |
32 |
import java.io.FileInputStream; |
33 |
import java.io.FileNotFoundException; |
34 |
import java.io.IOException; |
35 |
import java.io.InputStream; |
36 |
import java.net.MalformedURLException; |
37 |
import java.net.URL; |
38 |
import java.util.Properties; |
39 |
|
40 |
import org.gvsig.tools.packageutils.PackageInfo; |
41 |
import org.slf4j.Logger; |
42 |
import org.slf4j.LoggerFactory; |
43 |
|
44 |
public class PackageInfoFileReader { |
45 |
|
46 |
private static final Logger logger = LoggerFactory |
47 |
.getLogger(PackageInfoFileReader.class); |
48 |
|
49 |
public void read(PackageInfo packageInfo, String fileName) throws IOException, FileNotFoundException { |
50 |
this.read(packageInfo, new File(fileName)); |
51 |
} |
52 |
|
53 |
public void read(PackageInfo packageInfo, File file) throws IOException, FileNotFoundException { |
54 |
this.read(packageInfo, new FileInputStream(file)); |
55 |
} |
56 |
|
57 |
public void read(PackageInfo packageInfo, InputStream is) throws IOException { |
58 |
Properties properties = new Properties(); |
59 |
properties.load(is); |
60 |
is.close(); |
61 |
read(packageInfo, properties); |
62 |
} |
63 |
|
64 |
public void read(PackageInfo packageInfo, Properties properties ) { |
65 |
|
66 |
packageInfo.setCode(properties.getProperty(PackageInfoTags.CODE)); |
67 |
|
68 |
String codealias1 = properties.getProperty(PackageInfoTags.CODEALIAS);
|
69 |
if( codealias1 != null ) { |
70 |
String[] s = codealias1.split(","); |
71 |
for( int i=0; i<s.length; i++) { |
72 |
s[i] = s[i].trim(); |
73 |
if(! "".equals(s[i]) ) { // isEmpty |
74 |
packageInfo.getAllCodes().add(s[i]); |
75 |
} |
76 |
} |
77 |
} |
78 |
|
79 |
packageInfo.setName(properties.getProperty(PackageInfoTags.NAME)); |
80 |
|
81 |
String pkgName = packageInfo.getName();
|
82 |
|
83 |
packageInfo.setDescription(properties.getProperty(PackageInfoTags.DESCRIPTION)); |
84 |
packageInfo.getVersion().parse(properties.getProperty(PackageInfoTags.VERSION)); |
85 |
packageInfo.setType(properties.getProperty(PackageInfoTags.TYPE)); |
86 |
packageInfo.setState(properties.getProperty(PackageInfoTags.STATE)); |
87 |
packageInfo.setOfficial(Boolean.valueOf(properties.getProperty(PackageInfoTags.OFFICIAL)).booleanValue());
|
88 |
packageInfo.setOperatingSystem(properties.getProperty(PackageInfoTags.OS)); |
89 |
packageInfo.setArchitecture(properties.getProperty(PackageInfoTags.ARCHITECTURE)); |
90 |
packageInfo.setJavaVM(properties.getProperty(PackageInfoTags.JVM)); |
91 |
String value = properties.getProperty(PackageInfoTags.APPLICATION_VERSION);
|
92 |
if( value == null ) { |
93 |
value = properties.getProperty(PackageInfoTags.GVSIG_VERSION); |
94 |
} |
95 |
packageInfo.getApplicationVersion().parse(value); |
96 |
packageInfo.setDownloadURL(properties.getProperty(PackageInfoTags.DOWNLOAD_URL)); |
97 |
packageInfo.setModelVersion(properties.getProperty(PackageInfoTags.MODEL_VERSION)); |
98 |
packageInfo.setOwner(properties.getProperty(PackageInfoTags.OWNER)); |
99 |
packageInfo.setDependencies(properties.getProperty(PackageInfoTags.DEPENDENCIES)); |
100 |
packageInfo.setSourcesURL(getUrl(properties, PackageInfoTags.SOURCES_URL, pkgName)); |
101 |
packageInfo.setWebURL(getUrl(properties, PackageInfoTags.WEB_URL, pkgName)); |
102 |
packageInfo.setOwnerURL(getUrl(properties, PackageInfoTags.OWNER_URL, pkgName)); |
103 |
packageInfo.addCategoriesAsString(properties.getProperty(PackageInfoTags.CATEGORIES)); |
104 |
} |
105 |
|
106 |
private URL getUrl(Properties properties, String name, String pkgName) { |
107 |
String s = properties.getProperty(name);
|
108 |
if (s != null && s.length()==0 ) { |
109 |
URL url;
|
110 |
try {
|
111 |
url = new URL(s); |
112 |
} catch (MalformedURLException e) { |
113 |
logger.info("Malformed url for '"+name+"' in package '"+pkgName+"', url='"+s+"'."); |
114 |
return null; |
115 |
} |
116 |
return url;
|
117 |
} else {
|
118 |
return null; |
119 |
} |
120 |
} |
121 |
|
122 |
|
123 |
} |