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.Arrays;
19  
20  import org.apache.commons.lang.StringUtils;
21  import org.dom4j.Node;
22  import org.rundeck.api.domain.RundeckNode;
23  
24  /**
25   * Parser for a single {@link RundeckNode}
26   *
27   * @author Vincent Behar
28   */
29  public class NodeParser extends BaseXpathParser<RundeckNode> {
30  
31  
32      public NodeParser(final String xpath) {
33          super(xpath);
34      }
35  
36      public NodeParser() {
37  
38      }
39  
40      @Override
41      public RundeckNode parse(Node rundeckNodeNode) {
42  
43          RundeckNode rundeckNode = new RundeckNode();
44  
45          rundeckNode.setName(StringUtils.trimToNull(rundeckNodeNode.valueOf("@name")));
46          rundeckNode.setType(StringUtils.trimToNull(rundeckNodeNode.valueOf("@type")));
47          rundeckNode.setDescription(StringUtils.trimToNull(rundeckNodeNode.valueOf("@description")));
48          rundeckNode.setHostname(StringUtils.trimToNull(rundeckNodeNode.valueOf("@hostname")));
49          rundeckNode.setOsArch(StringUtils.trimToNull(rundeckNodeNode.valueOf("@osArch")));
50          rundeckNode.setOsFamily(StringUtils.trimToNull(rundeckNodeNode.valueOf("@osFamily")));
51          rundeckNode.setOsName(StringUtils.trimToNull(rundeckNodeNode.valueOf("@osName")));
52          rundeckNode.setOsVersion(StringUtils.trimToNull(rundeckNodeNode.valueOf("@osVersion")));
53          rundeckNode.setUsername(StringUtils.trimToNull(rundeckNodeNode.valueOf("@username")));
54          rundeckNode.setEditUrl(StringUtils.trimToNull(rundeckNodeNode.valueOf("@editUrl")));
55          rundeckNode.setRemoteUrl(StringUtils.trimToNull(rundeckNodeNode.valueOf("@remoteUrl")));
56  
57          String tags = StringUtils.trimToEmpty(rundeckNodeNode.valueOf("@tags"));
58          rundeckNode.setTags(Arrays.asList(StringUtils.split(tags, ",")));
59  
60          return rundeckNode;
61      }
62  
63  }