1 package org.rundeck.api.parser;
2
3 import org.apache.commons.lang.StringUtils;
4 import org.dom4j.Node;
5 import org.rundeck.api.domain.WorkflowStepContextState;
6 import org.rundeck.api.domain.WorkflowStepState;
7
8 import java.util.HashMap;
9
10
11
12
13 public class WorkflowStepStateParser extends BaseXpathParser<WorkflowStepState> {
14 @Override
15 public WorkflowStepState parse(final Node targetNode) {
16 final WorkflowStepState state = new WorkflowStepState();
17
18 BaseStateParser.parseBaseState(targetNode, state);
19 state.setStepContextId(StringUtils.trimToNull(targetNode.valueOf("@stepctx")));
20 state.setStepNum(Integer.valueOf(targetNode.valueOf("@id")));
21 state.setNodeStep(Boolean.valueOf(StringUtils.trimToNull(targetNode.valueOf("nodeStep"))));
22 if (Boolean.valueOf(StringUtils.trimToNull(targetNode.valueOf("hasSubworkflow")))) {
23
24 state.setSubWorkflow(new WorkflowStateParser("workflow").parseXmlNode(targetNode));
25 }
26 if (Boolean.valueOf(StringUtils.trimToNull(targetNode.valueOf("nodeStep")))) {
27
28 final HashMap<String, WorkflowStepContextState> nodeStates = new HashMap<String, WorkflowStepContextState>();
29 for (final Object o : targetNode.selectNodes("nodeStates/nodeState")) {
30 final Node nodeStateNode = (Node) o;
31 final String nodeName = StringUtils.trimToNull(nodeStateNode.valueOf("@name"));
32 if (null != nodeName) {
33 nodeStates.put(nodeName, new WorkflowStepContextStateParser(state).parseXmlNode(nodeStateNode));
34 }
35 }
36 state.setNodeStates(nodeStates);
37 }
38 return state;
39 }
40 }