1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package ch.elca.el4j.services.xmlmerge.config;
18
19 import java.io.ByteArrayInputStream;
20 import java.io.IOException;
21 import java.util.Enumeration;
22 import java.util.Iterator;
23 import java.util.LinkedHashSet;
24 import java.util.Map;
25 import java.util.Properties;
26 import java.util.Set;
27
28 import ch.elca.el4j.services.xmlmerge.ConfigurationException;
29
30
31
32
33
34
35
36
37
38
39 public class PropertyXPathConfigurer extends AbstractXPathConfigurer {
40
41
42
43
44 public static final String DEFAULT_ACTION_KEY = "action.default";
45
46
47
48
49 public static final String DEFAULT_MAPPER_KEY = "mapper.default";
50
51
52
53
54 public static final String DEFAULT_MATCHER_KEY = "matcher.default";
55
56
57
58
59 public static final String PATH_PREFIX = "xpath.";
60
61
62
63
64 public static final String MAPPER_PREFIX = "mapper.";
65
66
67
68
69 public static final String MATCHER_PREFIX = "matcher.";
70
71
72
73
74 public static final String ACTION_PREFIX = "action.";
75
76
77
78
79 Properties m_props;
80
81
82
83
84 Set m_paths = new LinkedHashSet();
85
86
87
88
89
90
91
92
93
94
95
96 public PropertyXPathConfigurer(String propString)
97 throws ConfigurationException {
98 m_props = new Properties();
99 try {
100 m_props.load(new ByteArrayInputStream(propString.getBytes()));
101 } catch (IOException ioe) {
102
103 throw new ConfigurationException(ioe);
104 }
105 }
106
107
108
109
110
111
112
113
114 public PropertyXPathConfigurer(Map map) {
115 m_props = new Properties();
116 m_props.putAll(map);
117 }
118
119
120
121
122
123
124
125
126 public PropertyXPathConfigurer(Properties properties) {
127 m_props = properties;
128 }
129
130
131
132
133 protected void readConfiguration() throws ConfigurationException {
134 String token;
135
136 token = m_props.getProperty(DEFAULT_ACTION_KEY);
137 if (token != null) {
138 setDefaultAction(token);
139 }
140
141 token = m_props.getProperty(DEFAULT_MAPPER_KEY);
142 if (token != null) {
143 setDefaultMapper(token);
144 }
145
146 token = m_props.getProperty(DEFAULT_MATCHER_KEY);
147 if (token != null) {
148 setDefaultMatcher(token);
149 }
150
151 Enumeration keys = m_props.keys();
152
153 while (keys.hasMoreElements()) {
154 String key = (String) keys.nextElement();
155
156 if (key.startsWith(PATH_PREFIX)) {
157 m_paths.add(key.substring(PATH_PREFIX.length()));
158 }
159 }
160
161 Iterator it = m_paths.iterator();
162 while (it.hasNext()) {
163 String path = (String) it.next();
164
165 token = m_props.getProperty(ACTION_PREFIX + path);
166 if (token != null) {
167 addAction(m_props.getProperty(PATH_PREFIX + path), token);
168 }
169 token = m_props.getProperty(MAPPER_PREFIX + path);
170 if (token != null) {
171 addMapper(m_props.getProperty(PATH_PREFIX + path), token);
172 }
173 token = m_props.getProperty(MATCHER_PREFIX + path);
174 if (token != null) {
175 addMatcher(m_props.getProperty(PATH_PREFIX + path), token);
176 }
177 }
178
179 }
180
181 }