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.ArrayList;
19 import java.util.List;
20 import org.dom4j.Node;
21 import org.rundeck.api.domain.RundeckProject;
22
23 /**
24 * Parser for a {@link List} of {@link RundeckProject}
25 *
26 * @author Vincent Behar
27 */
28 public class ProjectsParser implements XmlNodeParser<List<RundeckProject>> {
29
30 private final String xpath;
31
32 /**
33 * @param xpath of the projects elements
34 */
35 public ProjectsParser(String xpath) {
36 super();
37 this.xpath = xpath;
38 }
39
40 @Override
41 public List<RundeckProject> parseXmlNode(Node node) {
42 List<RundeckProject> projects = new ArrayList<RundeckProject>();
43
44 @SuppressWarnings("unchecked")
45 List<Node> projectNodes = node.selectNodes(xpath);
46
47 for (Node projectNode : projectNodes) {
48 RundeckProject project = new ProjectParser().parseXmlNode(projectNode);
49 projects.add(project);
50 }
51
52 return projects;
53 }
54
55 }