1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.eclipse.jetty.deploy;
20
21 import java.io.FileNotFoundException;
22 import java.io.IOException;
23 import java.net.MalformedURLException;
24 import java.util.HashMap;
25 import java.util.Map;
26 import java.util.Properties;
27
28 import org.eclipse.jetty.util.annotation.ManagedAttribute;
29 import org.eclipse.jetty.util.annotation.ManagedObject;
30 import org.eclipse.jetty.util.annotation.ManagedOperation;
31 import org.eclipse.jetty.util.annotation.Name;
32 import org.eclipse.jetty.util.resource.Resource;
33
34
35
36
37
38
39 @ManagedObject("Configure deployed webapps via properties")
40 public class PropertiesConfigurationManager implements ConfigurationManager
41 {
42 private String _properties;
43 private final Map<String,String> _map = new HashMap<String,String>();
44
45 public PropertiesConfigurationManager(String properties)
46 {
47 }
48
49 public PropertiesConfigurationManager()
50 {
51 }
52
53 @ManagedAttribute("A file or URL of properties")
54 public void setFile(String resource) throws MalformedURLException, IOException
55 {
56 _properties=resource;
57 _map.clear();
58 loadProperties(_properties);
59 }
60
61 public String getFile()
62 {
63 return _properties;
64 }
65
66 @ManagedOperation("Set a property")
67 public void put(@Name("name")String name, @Name("value")String value)
68 {
69 _map.put(name,value);
70 }
71
72
73
74
75 @Override
76 public Map<String, String> getProperties()
77 {
78 return new HashMap<>(_map);
79 }
80
81 private void loadProperties(String resource) throws FileNotFoundException, IOException
82 {
83 Resource file=Resource.newResource(resource);
84 if (file!=null && file.exists())
85 {
86 Properties properties = new Properties();
87 properties.load(file.getInputStream());
88 for (Map.Entry<Object, Object> entry : properties.entrySet())
89 _map.put(entry.getKey().toString(),String.valueOf(entry.getValue()));
90 }
91 }
92 }