01: /***
02: * jwma Java WebMail
03: * Copyright (c) 2000-2003 jwma team
04: *
05: * jwma is free software; you can distribute and use this source
06: * under the terms of the BSD-style license received along with
07: * the distribution.
08: ***/package dtw.webmail.util;
09:
10: import java.util.Properties;
11: import java.net.*;
12: import java.io.*;
13:
14: /**
15: * Utility class providing two simple
16: * yet powerful methods for loading properties.
17: *
18: * @author Dieter Wimberger
19: * @version 0.9.7 07/02/2003
20: */
21: public class PropertiesLoader {
22:
23: /**
24: * Returns a <tt>Properties</tt> instance loaded from the
25: * URL given as <tt>String</tt>.
26: *
27: * @param url that refers to the properties file as <tt>String</tt>.
28: *
29: * @return loaded <tt>Properties</tt> instance.
30: *
31: * @throws MalformedURLException if the <tt>String</tt> does not
32: * represent a valid URL.
33: * @throws IOException if the method fails to access the URL.
34: */
35: public static Properties loadProperties(String url)
36: throws MalformedURLException, IOException {
37:
38: return loadProperties(new URL(url));
39: }//loadProperties(String)
40:
41: /**
42: * Returns a <tt>Properties</tt> instance loaded from the
43: * given <tt>URL</tt>.
44: *
45: * @param url that refers to the properties file as <tt>java.net.URL</tt>.
46: *
47: * @return loaded <tt>Properties</tt> instance.
48: *
49: * @throws IOException if the method fails to access the URL.
50: */
51: public static Properties loadProperties(URL url) throws IOException {
52:
53: Properties newprops = new Properties();
54: InputStream in = url.openStream();
55: newprops.load(in);
56: in.close();
57:
58: return newprops;
59: }//loadProperties(URL)
60:
61: }//class PropertiesLoader
|