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 * Load poperty file from a url. Example: <code>file://c:/temp/example.properties</code>.
12 *
13 * @author Linke
14 *
15 */
16 public class UrlPropertiesLoader implements PropertiesLoader {
17
18 private URL url = null;
19
20 public UrlPropertiesLoader(URL pvUrl) {
21 url = pvUrl;
22 }
23
24 public UrlPropertiesLoader(String pvUrl) {
25 try {
26 url = new URL(pvUrl);
27 } catch (MalformedURLException e) {
28 throw new PropertiesLoadException("Error by create URL with file: " + pvUrl, e);
29 }
30 }
31
32 public Properties load() {
33 Properties lvProperties = new Properties();
34 try {
35 InputStream lvInputStream = url.openStream();
36 lvProperties.load(lvInputStream);
37 } catch (Exception e) {
38 throw new PropertiesLoadException("Error in load-method:", e);
39 }
40 return lvProperties;
41 }
42
43 }