/
ContextConfigurationParser.java
52 lines (40 loc) · 1.86 KB
/
ContextConfigurationParser.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package com.lyncode.xoai.dataprovider.xml.xoaiconfig.parse;
import com.lyncode.xoai.dataprovider.xml.read.XmlReader;
import com.lyncode.xoai.dataprovider.xml.read.XmlReaderException;
import com.lyncode.xoai.dataprovider.xml.xoaiconfig.ContextConfiguration;
public class ContextConfigurationParser extends Parser<ContextConfiguration> {
@Override
public ContextConfiguration parse(XmlReader reader) throws ParseException {
try {
ContextConfiguration configuration = new ContextConfiguration(reader.getAttribute("baseurl"));
String name = reader.getAttribute("name");
if (name != null) configuration.withName(name);
reader.proceedToNextElement();
if (reader.elementNameIs("Transformer")) {
configuration.withTransformer(reader.getAttribute("ref"));
reader.proceedToTheNextStartElement();
}
if (reader.elementNameIs("Filter")) {
configuration.withFilter(reader.getAttribute("red"));
reader.proceedToTheNextStartElement();
}
while (reader.elementNameIs("Set")) {
configuration.withSet(reader.getAttribute("ref"));
reader.proceedToTheNextStartElement();
}
while (reader.elementNameIs("Format")) {
configuration.withFormat(reader.getAttribute("ref"));
reader.proceedToNextElement();
reader.proceedToNextElement();
}
if (reader.isStart() && reader.elementNameIs("Description")) {
configuration.withDescription(reader.getText());
reader.proceedToNextElement();
}
reader.proceedToNextElement();
return configuration;
} catch (XmlReaderException e) {
throw new ParseException(e);
}
}
}