View Javadoc

1   /*
2    * Copyright 2012 DTO Labs, Inc. (http://dtolabs.com)
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   */
17  
18  /*
19  * DeleteParser.java
20  * 
21  * User: Greg Schueler <a href="mailto:greg@dtosolutions.com">greg@dtosolutions.com</a>
22  * Created: 10/1/12 3:52 PM
23  * 
24  */
25  package org.rundeck.api.parser;
26  
27  import org.apache.commons.lang.StringUtils;
28  import org.dom4j.Element;
29  import org.dom4j.Node;
30  import org.rundeck.api.domain.RundeckJobDelete;
31  
32  import java.util.*;
33  
34  
35  /**
36   * DeleteParser is ...
37   *
38   * @author Greg Schueler <a href="mailto:greg@dtosolutions.com">greg@dtosolutions.com</a>
39   */
40  public class DeleteParser implements XmlNodeParser<RundeckJobDelete> {
41      private String xpath;
42  
43      public DeleteParser(String xpath) {
44          this.xpath = xpath;
45      }
46  
47      public DeleteParser() {
48      }
49  
50      @Override
51      public RundeckJobDelete parseXmlNode(Node node) {
52          Node resultNode = xpath != null ? node.selectSingleNode(xpath) : node;
53  
54          final RundeckJobDelete delete = new RundeckJobDelete();
55          delete.setError(StringUtils.trimToNull(resultNode.valueOf("error")));
56          delete.setErrorCode(StringUtils.trimToNull(resultNode.valueOf("@errorCode")));
57          delete.setId(StringUtils.trimToNull(resultNode.valueOf("@id")));
58          delete.setMessage(StringUtils.trimToNull(resultNode.valueOf("message")));
59          delete.setSuccessful(null == delete.getError() && null == delete.getErrorCode());
60  
61          return delete;
62      }
63  }