List of usage examples for org.dom4j Node valueOf
String valueOf(String xpathExpression);
valueOf
evaluates an XPath expression and returns the textual representation of the results the XPath string-value of this node.
From source file:org.rundeck.api.parser.BulkDeleteParser.java
License:Apache License
@Override public RundeckJobDeleteBulk parse(Node subnode) { final ArrayList<RundeckJobDelete> deletes = new ArrayList<RundeckJobDelete>(); final List results = subnode.selectNodes("(succeeded|failed)/deleteJobResult"); final DeleteParser parser = new DeleteParser(); if (null != results && results.size() > 0) { for (final Object o : results) { deletes.add(parser.parseXmlNode((Node) o)); }/* w w w. j a va 2 s. c o m*/ } final String requestcount = StringUtils.trimToNull(subnode.valueOf("@requestCount")); final String allsuccessString = StringUtils.trimToNull(subnode.valueOf("@allsuccessful")); int count = 0; boolean allsuccess = false; if (null != requestcount) { try { count = Integer.parseInt(requestcount); } catch (NumberFormatException e) { } } if (null != allsuccessString) { allsuccess = Boolean.parseBoolean(allsuccessString); } return new RundeckJobDeleteBulk(deletes, count, allsuccess); }
From source file:org.rundeck.api.parser.DeleteParser.java
License:Apache License
@Override public RundeckJobDelete parse(Node resultNode) { final RundeckJobDelete delete = new RundeckJobDelete(); delete.setError(StringUtils.trimToNull(resultNode.valueOf("error"))); delete.setErrorCode(StringUtils.trimToNull(resultNode.valueOf("@errorCode"))); delete.setId(StringUtils.trimToNull(resultNode.valueOf("@id"))); delete.setMessage(StringUtils.trimToNull(resultNode.valueOf("message"))); delete.setSuccessful(null == delete.getError() && null == delete.getErrorCode()); return delete; }
From source file:org.rundeck.api.parser.EventParser.java
License:Apache License
@Override public RundeckEvent parse(Node eventNode) { RundeckEvent event = new RundeckEvent(); event.setTitle(StringUtils.trimToNull(eventNode.valueOf("title"))); try {/* w ww.ja v a 2s . co m*/ event.setStatus(EventStatus.valueOf(StringUtils.upperCase(eventNode.valueOf("status")))); } catch (IllegalArgumentException e) { event.setStatus(null); } event.setSummary(StringUtils.trimToNull(eventNode.valueOf("summary"))); NodeSummary nodeSummary = new NodeSummary(); nodeSummary.setSucceeded(Integer.valueOf(eventNode.valueOf("node-summary/@succeeded"))); nodeSummary.setFailed(Integer.valueOf(eventNode.valueOf("node-summary/@failed"))); nodeSummary.setTotal(Integer.valueOf(eventNode.valueOf("node-summary/@total"))); event.setNodeSummary(nodeSummary); event.setUser(StringUtils.trimToNull(eventNode.valueOf("user"))); event.setProject(StringUtils.trimToNull(eventNode.valueOf("project"))); String startedAt = StringUtils.trimToNull(eventNode.valueOf("@starttime")); if (startedAt != null) { event.setStartedAt(new Date(Long.valueOf(startedAt))); } String endedAt = StringUtils.trimToNull(eventNode.valueOf("@endtime")); if (endedAt != null) { event.setEndedAt(new Date(Long.valueOf(endedAt))); } event.setAbortedBy(StringUtils.trimToNull(eventNode.valueOf("abortedby"))); try { event.setExecutionId(Long.valueOf(eventNode.valueOf("execution/@id"))); } catch (NumberFormatException e) { event.setExecutionId(null); } event.setJobId(StringUtils.trimToNull(eventNode.valueOf("job/@id"))); return event; }
From source file:org.rundeck.api.parser.ExecutionParser.java
License:Apache License
@Override public RundeckExecution parse(Node execNode) { RundeckExecution execution = new RundeckExecution(); execution.setId(Long.valueOf(execNode.valueOf("@id"))); execution.setUrl(StringUtils.trimToNull(execNode.valueOf("@href"))); try {/*from w w w .j ava2 s.c o m*/ execution.setStatus(ExecutionStatus .valueOf(StringUtils.replace(StringUtils.upperCase(execNode.valueOf("@status")), "-", "_"))); } catch (IllegalArgumentException e) { execution.setStatus(null); } execution.setDescription(StringUtils.trimToNull(execNode.valueOf("description"))); execution.setArgstring(StringUtils.trimToNull(execNode.valueOf("argstring"))); execution.setStartedBy(StringUtils.trimToNull(execNode.valueOf("user"))); execution.setAbortedBy(StringUtils.trimToNull(execNode.valueOf("abortedby"))); execution.setProject(StringUtils.trimToNull(execNode.valueOf("@project"))); String startedAt = StringUtils.trimToNull(execNode.valueOf("date-started/@unixtime")); if (startedAt != null) { execution.setStartedAt(new Date(Long.valueOf(startedAt))); } String endedAt = StringUtils.trimToNull(execNode.valueOf("date-ended/@unixtime")); if (endedAt != null) { execution.setEndedAt(new Date(Long.valueOf(endedAt))); } Node jobNode = execNode.selectSingleNode("job"); if (jobNode != null) { RundeckJob job = new JobParser().parseXmlNode(jobNode); execution.setJob(job); } final Node successfulNodes = execNode.selectSingleNode("successfulNodes"); if (successfulNodes != null) { final List<RundeckNode> rundeckNodes = new ListParser<RundeckNode>(new NodeParser(), "successfulNodes/node").parseXmlNode(execNode); execution.setSuccessfulNodes(new HashSet<RundeckNodeIdentity>(rundeckNodes)); } else { execution.setSuccessfulNodes(Collections.<RundeckNodeIdentity>emptySet()); } final Node failedNodes = execNode.selectSingleNode("failedNodes"); if (failedNodes != null) { final List<RundeckNode> rundeckNodes = new ListParser<RundeckNode>(new NodeParser(), "failedNodes/node") .parseXmlNode(execNode); execution.setFailedNodes(new HashSet<RundeckNodeIdentity>(rundeckNodes)); } else { execution.setFailedNodes(Collections.<RundeckNodeIdentity>emptySet()); } return execution; }
From source file:org.rundeck.api.parser.HistoryParser.java
License:Apache License
@Override public RundeckHistory parse(Node eventsNode) { RundeckHistory history = new RundeckHistory(); history.setCount(Integer.valueOf(eventsNode.valueOf("@count"))); history.setTotal(Integer.valueOf(eventsNode.valueOf("@total"))); history.setMax(Integer.valueOf(eventsNode.valueOf("@max"))); history.setOffset(Integer.valueOf(eventsNode.valueOf("@offset"))); @SuppressWarnings("unchecked") List<Node> eventNodes = eventsNode.selectNodes("event"); EventParser eventParser = new EventParser(); for (Node eventNode : eventNodes) { RundeckEvent event = eventParser.parseXmlNode(eventNode); history.addEvent(event);/*w w w . ja v a 2 s. c o m*/ } return history; }
From source file:org.rundeck.api.parser.JobParser.java
License:Apache License
@Override public RundeckJob parse(Node jobNode) { RundeckJob job = new RundeckJob(); job.setName(StringUtils.trimToNull(jobNode.valueOf("name"))); job.setDescription(StringUtils.trimToNull(jobNode.valueOf("description"))); job.setGroup(StringUtils.trimToNull(jobNode.valueOf("group"))); // ID is either an attribute or an child element... String jobId = null;/* w w w . ja v a 2 s . co m*/ jobId = jobNode.valueOf("id"); if (StringUtils.isBlank(jobId)) { jobId = jobNode.valueOf("@id"); } job.setId(jobId); String averageDuration = StringUtils.trimToNull(jobNode.valueOf("@averageDuration")); if (averageDuration != null) { job.setAverageDuration(Long.valueOf(averageDuration)); } // project is either a nested element of context, or just a child element Node contextNode = jobNode.selectSingleNode("context"); if (contextNode != null) { job.setProject(StringUtils.trimToNull(contextNode.valueOf("project"))); } else { job.setProject(StringUtils.trimToNull(jobNode.valueOf("project"))); } return job; }
From source file:org.rundeck.api.parser.JobsImportResultParser.java
License:Apache License
@Override public RundeckJobsImportResult parse(Node resultNode) { RundeckJobsImportResult result = new RundeckJobsImportResult(); @SuppressWarnings("unchecked") List<Node> succeededJobsNodes = resultNode.selectNodes("succeeded/job"); if (succeededJobsNodes != null) { for (Node succeededJobNode : succeededJobsNodes) { RundeckJob job = new JobParser().parseXmlNode(succeededJobNode); result.addSucceededJob(job); }//from w ww . j a v a 2 s .c o m } @SuppressWarnings("unchecked") List<Node> skippedJobsNodes = resultNode.selectNodes("skipped/job"); if (skippedJobsNodes != null) { for (Node skippedJobNode : skippedJobsNodes) { RundeckJob job = new JobParser().parseXmlNode(skippedJobNode); result.addSkippedJob(job); } } @SuppressWarnings("unchecked") List<Node> failedJobsNodes = resultNode.selectNodes("failed/job"); if (failedJobsNodes != null) { for (Node failedJobNode : failedJobsNodes) { RundeckJob job = new JobParser().parseXmlNode(failedJobNode); result.addFailedJob(job, failedJobNode.valueOf("error")); } } return result; }
From source file:org.rundeck.api.parser.NodeParser.java
License:Apache License
@Override public RundeckNode parse(Node rundeckNodeNode) { RundeckNode rundeckNode = new RundeckNode(); rundeckNode.setName(StringUtils.trimToNull(rundeckNodeNode.valueOf("@name"))); rundeckNode.setType(StringUtils.trimToNull(rundeckNodeNode.valueOf("@type"))); rundeckNode.setDescription(StringUtils.trimToNull(rundeckNodeNode.valueOf("@description"))); rundeckNode.setHostname(StringUtils.trimToNull(rundeckNodeNode.valueOf("@hostname"))); rundeckNode.setOsArch(StringUtils.trimToNull(rundeckNodeNode.valueOf("@osArch"))); rundeckNode.setOsFamily(StringUtils.trimToNull(rundeckNodeNode.valueOf("@osFamily"))); rundeckNode.setOsName(StringUtils.trimToNull(rundeckNodeNode.valueOf("@osName"))); rundeckNode.setOsVersion(StringUtils.trimToNull(rundeckNodeNode.valueOf("@osVersion"))); rundeckNode.setUsername(StringUtils.trimToNull(rundeckNodeNode.valueOf("@username"))); rundeckNode.setEditUrl(StringUtils.trimToNull(rundeckNodeNode.valueOf("@editUrl"))); rundeckNode.setRemoteUrl(StringUtils.trimToNull(rundeckNodeNode.valueOf("@remoteUrl"))); String tags = StringUtils.trimToEmpty(rundeckNodeNode.valueOf("@tags")); rundeckNode.setTags(Arrays.asList(StringUtils.split(tags, ","))); return rundeckNode; }
From source file:org.rundeck.api.parser.ParserHelper.java
License:Apache License
/** * Load an XML {@link Document} from the given {@link InputStream} * //from w ww. j a v a 2 s . com * @param inputStream from an API call to Rundeck * @return an XML {@link Document} * @throws RundeckApiException if we failed to read the response, or if the response is an error */ public static Document loadDocument(InputStream inputStream) throws RundeckApiException { SAXReader reader = new SAXReader(); reader.setEncoding("UTF-8"); Document document; try { document = reader.read(inputStream); } catch (DocumentException e) { throw new RundeckApiException("Failed to read Rundeck response", e); } document.setXMLEncoding("UTF-8"); Node result = document.selectSingleNode("result"); if (result != null) { Boolean failure = Boolean.valueOf(result.valueOf("@error")); if (failure) { throw new RundeckApiException(result.valueOf("error/message")); } } return document; }
From source file:org.rundeck.api.parser.ProjectParser.java
License:Apache License
@Override public RundeckProject parse(Node projectNode) { RundeckProject project = new RundeckProject(); project.setName(StringUtils.trimToNull(projectNode.valueOf("name"))); project.setDescription(StringUtils.trimToNull(projectNode.valueOf("description"))); project.setResourceModelProviderUrl(StringUtils.trimToNull(projectNode.valueOf("resources/providerURL"))); return project; }