1
2
3
4
5
6
7
8
9
10
11
12
13
14 package uk.nhs.interoperability.util;
15
16 import java.io.IOException;
17 import java.util.Map.Entry;
18 import java.util.Properties;
19 import java.util.Set;
20
21
22
23
24
25
26
27
28 public class ITKApplicationProperties {
29
30
31 private static Properties props = new Properties();
32 static {
33 try {
34 props.load(ITKApplicationProperties.class.getResourceAsStream("/application.properties"));
35 } catch (IOException ex){
36 ex.printStackTrace();
37 }
38 }
39
40
41
42
43
44
45
46 public static String getProperty(String propertyName){
47 return props.getProperty(propertyName);
48 }
49
50
51
52
53
54
55
56 public static Properties getPropertiesMatching(String prefix) {
57 return getPropertiesMatching(props, prefix);
58 }
59
60
61
62
63
64
65
66
67 public static Properties getPropertiesMatching(Properties props, String prefix) {
68 Properties matchingProperties = new Properties();
69 Set<Entry<Object, Object>> entries = props.entrySet();
70 for (Entry<Object, Object> entry: entries) {
71 if (entry.getKey() instanceof String && ((String)entry.getKey()).startsWith(prefix)) {
72 matchingProperties.setProperty((String)entry.getKey(), (String)entry.getValue());
73 }
74 }
75 return matchingProperties;
76 }
77
78 }