View Javadoc

1   package org.rundeck.api.parser;
2   
3   import java.util.ArrayList;
4   import java.util.List;
5   import org.dom4j.Node;
6   import org.rundeck.api.domain.RundeckProject;
7   
8   /**
9    * Parser for a {@link List} of {@link RundeckProject}
10   * 
11   * @author Vincent Behar
12   */
13  public class ProjectsParser implements NodeParser<List<RundeckProject>> {
14  
15      private final String xpath;
16  
17      /**
18       * @param xpath of the projects elements
19       */
20      public ProjectsParser(String xpath) {
21          super();
22          this.xpath = xpath;
23      }
24  
25      @Override
26      public List<RundeckProject> parseNode(Node node) {
27          List<RundeckProject> projects = new ArrayList<RundeckProject>();
28  
29          @SuppressWarnings("unchecked")
30          List<Node> projectNodes = node.selectNodes(xpath);
31  
32          for (Node projectNode : projectNodes) {
33              RundeckProject project = new ProjectParser().parseNode(projectNode);
34              projects.add(project);
35          }
36  
37          return projects;
38      }
39  
40  }