1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.rundeck.api.parser;
17
18 import java.util.List;
19 import org.dom4j.Node;
20 import org.rundeck.api.domain.RundeckEvent;
21 import org.rundeck.api.domain.RundeckHistory;
22
23
24
25
26
27
28 public class HistoryParser implements XmlNodeParser<RundeckHistory> {
29
30 private String xpath;
31
32 public HistoryParser() {
33 super();
34 }
35
36
37
38
39 public HistoryParser(String xpath) {
40 super();
41 this.xpath = xpath;
42 }
43
44 @Override
45 public RundeckHistory parseXmlNode(Node node) {
46 Node eventsNode = xpath != null ? node.selectSingleNode(xpath) : node;
47
48 RundeckHistory history = new RundeckHistory();
49
50 history.setCount(Integer.valueOf(eventsNode.valueOf("@count")));
51 history.setTotal(Integer.valueOf(eventsNode.valueOf("@total")));
52 history.setMax(Integer.valueOf(eventsNode.valueOf("@max")));
53 history.setOffset(Integer.valueOf(eventsNode.valueOf("@offset")));
54
55 @SuppressWarnings("unchecked")
56 List<Node> eventNodes = eventsNode.selectNodes("event");
57 EventParser eventParser = new EventParser();
58
59 for (Node eventNode : eventNodes) {
60 RundeckEvent event = eventParser.parseXmlNode(eventNode);
61 history.addEvent(event);
62 }
63
64 return history;
65 }
66
67 }