View Javadoc

1   /*
2    * Copyright 2011 Vincent Behar
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
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   * Parser for a single {@link RundeckHistory}
25   * 
26   * @author Vincent Behar
27   */
28  public class HistoryParser extends BaseXpathParser<RundeckHistory> {
29  
30  
31      public HistoryParser(final String xpath) {
32          super(xpath);
33      }
34  
35      @Override
36      public RundeckHistory parse(Node eventsNode) {
37  
38          RundeckHistory history = new RundeckHistory();
39  
40          history.setCount(Integer.valueOf(eventsNode.valueOf("@count")));
41          history.setTotal(Integer.valueOf(eventsNode.valueOf("@total")));
42          history.setMax(Integer.valueOf(eventsNode.valueOf("@max")));
43          history.setOffset(Integer.valueOf(eventsNode.valueOf("@offset")));
44  
45          @SuppressWarnings("unchecked")
46          List<Node> eventNodes = eventsNode.selectNodes("event");
47          EventParser eventParser = new EventParser();
48  
49          for (Node eventNode : eventNodes) {
50              RundeckEvent event = eventParser.parseXmlNode(eventNode);
51              history.addEvent(event);
52          }
53  
54          return history;
55      }
56  
57  }