|
1 |
| package net.sf.crispy.properties; |
|
2 |
| |
|
3 |
| import java.io.InputStream; |
|
4 |
| import java.net.MalformedURLException; |
|
5 |
| import java.net.URL; |
|
6 |
| import java.util.Properties; |
|
7 |
| |
|
8 |
| import net.sf.crispy.PropertiesLoader; |
|
9 |
| |
|
10 |
| |
|
11 |
| |
|
12 |
| |
|
13 |
| |
|
14 |
| |
|
15 |
| |
|
16 |
| public class UrlPropertiesLoader implements PropertiesLoader { |
|
17 |
| |
|
18 |
| private URL url = null; |
|
19 |
| |
|
20 |
2
| public UrlPropertiesLoader(URL pvUrl) {
|
|
21 |
2
| url = pvUrl;
|
|
22 |
| } |
|
23 |
| |
|
24 |
2
| public UrlPropertiesLoader(String pvUrl) {
|
|
25 |
2
| try {
|
|
26 |
2
| url = new URL(pvUrl);
|
|
27 |
| } catch (MalformedURLException e) { |
|
28 |
1
| throw new PropertiesLoadException("Error by create URL with file: " + pvUrl, e);
|
|
29 |
| } |
|
30 |
| } |
|
31 |
| |
|
32 |
4
| public Properties load() {
|
|
33 |
4
| Properties lvProperties = new Properties();
|
|
34 |
4
| try {
|
|
35 |
4
| InputStream lvInputStream = url.openStream();
|
|
36 |
3
| lvProperties.load(lvInputStream);
|
|
37 |
| } catch (Exception e) { |
|
38 |
1
| throw new PropertiesLoadException("Error in load-method:", e);
|
|
39 |
| } |
|
40 |
3
| return lvProperties;
|
|
41 |
| } |
|
42 |
| |
|
43 |
| } |