1
2
3
4
5
6
7
8
9
10
11
12
13
14 package org.eclipse.jetty.deploy;
15
16 import java.io.FileNotFoundException;
17 import java.io.IOException;
18 import java.net.MalformedURLException;
19 import java.util.HashMap;
20 import java.util.Map;
21 import java.util.Properties;
22
23 import org.eclipse.jetty.util.resource.Resource;
24
25
26
27
28
29
30 public class FileConfigurationManager implements ConfigurationManager
31 {
32 private Resource _file;
33 private Map<String,String> _map = new HashMap<String,String>();
34
35 public FileConfigurationManager()
36 {
37 }
38
39 public void setFile(String filename) throws MalformedURLException, IOException
40 {
41 _file = Resource.newResource(filename);
42 }
43
44
45
46
47 public Map<String, String> getProperties()
48 {
49 try
50 {
51 loadProperties();
52 return _map;
53 }
54 catch (Exception e)
55 {
56 throw new RuntimeException(e);
57 }
58 }
59
60 private void loadProperties() throws FileNotFoundException, IOException
61 {
62 if (_map.isEmpty() && _file!=null)
63 {
64 Properties properties = new Properties();
65 properties.load(_file.getInputStream());
66 for (Map.Entry<Object, Object> entry : properties.entrySet())
67 _map.put(entry.getKey().toString(),String.valueOf(entry.getValue()));
68 }
69 }
70 }