List of usage examples for org.dom4j Node getStringValue
String getStringValue();
From source file:com.dtolabs.client.services.RundeckAPICentralDispatcher.java
License:Apache License
private IStoredJobLoadResult parseAPIJobResult(final Node node1, final boolean successful, final boolean skippedJob, final String message) { final Node uuidNode = node1.selectSingleNode("uuid"); final Node idNode = node1.selectSingleNode("id"); final String id = null != uuidNode ? uuidNode.getStringValue() : null != idNode ? idNode.getStringValue() : null; final String name = node1.selectSingleNode("name").getStringValue(); final String url = null != id ? createJobURL(id) : null; final String group = null != node1.selectSingleNode("group") ? node1.selectSingleNode("group").getStringValue() : null;// w ww. j a va 2 s . c o m final String description = null != node1.selectSingleNode("description") ? node1.selectSingleNode("description").getStringValue() : null; final String project = null != node1.selectSingleNode("project") ? node1.selectSingleNode("project").getStringValue() : null; logger.debug("\t" + name + " [" + id + "] <" + url + "> (" + project + ")"); return StoredJobLoadResultImpl.createLoadResult(id, name, url, group, description, project, successful, skippedJob, message); }
From source file:com.dtolabs.client.services.RundeckCentralDispatcher.java
License:Apache License
/** * Submit a request to the server which expects a list of queued item results in the response, and return a single QueuedItemResult parsed from the response. * * @param tempxml xml temp file (or null) * @param otherparams parameters for the request * * @param requestPath//from w ww . ja v a2 s. c o m * @return a single QueuedItemResult * * @throws CentralDispatcherException if an error occurs */ private QueuedItemResult submitQueueRequest(final File tempxml, final HashMap<String, String> otherparams, final String requestPath) throws CentralDispatcherException { final HashMap<String, String> params = new HashMap<String, String>(); params.put("xmlreq", "true"); if (null != otherparams) { params.putAll(otherparams); } final WebserviceResponse response; try { response = serverService.makeRundeckRequest(requestPath, params, tempxml, null); } catch (MalformedURLException e) { throw new CentralDispatcherServerRequestException("Failed to make request", e); } validateResponse(response); //////////////////// //parse result list of execution responses. this implementation handles multiple responses, but only //returns a single QueuedItem (the first one found). //TODO: update to return multiple QueuedItems when multiple job queue requests are supported /////////////////// final Document resultDoc = response.getResultDoc(); final int succeeded; final int failed; Node node = resultDoc.selectSingleNode("/result/succeeded/@count"); if (null != node) { succeeded = Integer.parseInt(node.getStringValue()); } else { succeeded = -1; } node = resultDoc.selectSingleNode("/result/failed/@count"); if (null != node) { failed = Integer.parseInt(node.getStringValue()); } else { failed = -1; } final String succeededId; if (succeeded > 0) { logger.info("Succeeded queueing " + succeeded + " Job" + (succeeded > 1 ? "s" : "") + ":"); final List nodes = resultDoc.selectNodes("/result/succeeded/execution"); final Node node1 = (Node) nodes.iterator().next(); final String index = node1.selectSingleNode("@index").getStringValue(); final String id = node1.selectSingleNode("id").getStringValue(); succeededId = id; final String name = node1.selectSingleNode("name").getStringValue(); String url = node1.selectSingleNode("url").getStringValue(); url = makeAbsoluteURL(url); logger.info("\t" + index + ": " + name + " [" + id + "] <" + url + ">"); return QueuedItemResultImpl.successful("Succeeded queueing " + name, succeededId, url, name); } if (failed > 0) { final String s1 = "Failed to queue " + failed + " Job" + (failed > 1 ? "s" : "") + ":"; logger.error(s1); final List nodes = resultDoc.selectNodes("/result/failed/execution"); final Node node1 = (Node) nodes.iterator().next(); final String index = node1.selectSingleNode("@index").getStringValue(); final String id = null != node1.selectSingleNode("id") ? node1.selectSingleNode("id").getStringValue() : null; String url = null != node1.selectSingleNode("url") ? node1.selectSingleNode("url").getStringValue() : null; url = makeAbsoluteURL(url); final String error = null != node1.selectSingleNode("error") ? node1.selectSingleNode("error").getStringValue() : null; final String message = null != node1.selectSingleNode("message") ? node1.selectSingleNode("message").getStringValue() : null; final String errmsg = error + (null != id ? " [" + id + "] <" + url + ">" : "") + (null != message ? " : " + message : ""); final String s2 = index + ": " + errmsg; logger.error(s2); return QueuedItemResultImpl.failed(errmsg); } return QueuedItemResultImpl.failed("Server response contained no success information."); }
From source file:com.dtolabs.client.services.RundeckCentralDispatcher.java
License:Apache License
public Collection<IStoredJob> listStoredJobs(final IStoredJobsQuery iStoredJobsQuery, final OutputStream output, final JobDefinitionFileFormat fformat) throws CentralDispatcherException { final HashMap<String, String> params = new HashMap<String, String>(); final String nameMatch = iStoredJobsQuery.getNameMatch(); String groupMatch = iStoredJobsQuery.getGroupMatch(); final String projectFilter = iStoredJobsQuery.getProjectFilter(); final String idlistFilter = iStoredJobsQuery.getIdlist(); if (null != output && null != fformat) { params.put("format", fformat.getName()); } else {//from ww w . ja va 2 s . c o m params.put("format", JobDefinitionFileFormat.xml.getName()); } if (null != nameMatch) { params.put("jobFilter", nameMatch); } if (null != groupMatch) { final Matcher matcher = Pattern.compile("^/*(.+?)/*$").matcher(groupMatch); if (matcher.matches()) { //strip leading and trailing slashes groupMatch = matcher.group(1); } params.put("groupPath", groupMatch); } if (null != projectFilter) { params.put("projFilter", projectFilter); } if (null != idlistFilter) { params.put("idlist", idlistFilter); } //2. send request via ServerService final WebserviceResponse response; try { response = serverService.makeRundeckRequest(RUNDECK_LIST_STORED_JOBS_PATH, params, null, null); } catch (MalformedURLException e) { throw new CentralDispatcherServerRequestException("Failed to make request", e); } //if xml, do local validation and listing if (null == fformat || fformat == JobDefinitionFileFormat.xml) { validateJobsResponse(response); //////////////////// //parse result list of queued items, return the collection of QueuedItems /////////////////// final Document resultDoc = response.getResultDoc(); final Node node = resultDoc.selectSingleNode("/joblist"); final ArrayList<IStoredJob> list = new ArrayList<IStoredJob>(); if (null == node) { return list; } final List items = node.selectNodes("job"); if (null != items && items.size() > 0) { for (final Object o : items) { final Node node1 = (Node) o; final String id = node1.selectSingleNode("id").getStringValue(); final String name = node1.selectSingleNode("name").getStringValue(); final String url = createJobURL(id); final Node gnode = node1.selectSingleNode("group"); final String group = null != gnode ? gnode.getStringValue() : null; final String description = node1.selectSingleNode("description").getStringValue(); list.add(StoredJobImpl.create(id, name, url, group, description, projectFilter)); } } if (null != output) { //write output doc to the outputstream final OutputFormat format = OutputFormat.createPrettyPrint(); try { final XMLWriter writer = new XMLWriter(output, format); writer.write(resultDoc); writer.flush(); } catch (IOException e) { throw new CentralDispatcherServerRequestException(e); } } return list; } else if (fformat == JobDefinitionFileFormat.yaml) { //do rought yaml parse final Collection<Map> mapCollection = validateJobsResponseYAML(response); final ArrayList<IStoredJob> list = new ArrayList<IStoredJob>(); if (null == mapCollection || mapCollection.size() < 1) { return list; } for (final Map map : mapCollection) { final String id = map.get("id").toString(); final String name = (String) map.get("name"); final String group = map.containsKey("group") ? (String) map.get("group") : null; final String desc = map.containsKey("description") ? (String) map.get("description") : ""; final String url = createJobURL(id); list.add(StoredJobImpl.create(id, name, url, group, desc, projectFilter)); } if (null != output) { //write output doc to the outputstream try { final Writer writer = new OutputStreamWriter(output); writer.write(response.getResults()); writer.flush(); } catch (IOException e) { throw new CentralDispatcherServerRequestException(e); } } return list; } return null; }
From source file:com.dtolabs.client.services.RundeckCentralDispatcher.java
License:Apache License
public Collection<IStoredJobLoadResult> loadJobs(final ILoadJobsRequest iLoadJobsRequest, final File input, final JobDefinitionFileFormat format) throws CentralDispatcherException {// w w w . j a va 2s . c om final HashMap params = new HashMap(); params.put("dupeOption", iLoadJobsRequest.getDuplicateOption().toString()); params.put("xmlreq", "true"); if (null != format) { params.put("fileformat", format.getName()); } /* * Send the request bean and the file as a multipart request. */ //2. send request via ServerService final WebserviceResponse response; try { response = serverService.makeRundeckRequest(RUNDECK_JOBS_UPLOAD, params, input, null); } catch (MalformedURLException e) { throw new CentralDispatcherServerRequestException("Failed to make request", e); } validateResponse(response); //////////////////// //parse result list of queued items, return the collection of QueuedItems /////////////////// final Document result = response.getResultDoc(); final int succeeded; final int failed; final int skipped; Node node = result.selectSingleNode("/result/succeeded/@count"); if (null != node) { succeeded = Integer.parseInt(node.getStringValue()); } else { succeeded = -1; } node = result.selectSingleNode("/result/failed/@count"); if (null != node) { failed = Integer.parseInt(node.getStringValue()); } else { failed = -1; } node = result.selectSingleNode("/result/skipped/@count"); if (null != node) { skipped = Integer.parseInt(node.getStringValue()); } else { skipped = -1; } ArrayList<IStoredJobLoadResult> resultList = new ArrayList<IStoredJobLoadResult>(); if (succeeded > 0) { logger.debug("Succeeded creating/updating " + succeeded + " Jobs:"); final List nodes = result.selectNodes("/result/succeeded/job"); for (final Object node2 : nodes) { final Node node1 = (Node) node2; final IStoredJobLoadResult storedJobLoadResult = parseStoredJobResult(node1, true, false, "Succeeded"); resultList.add(storedJobLoadResult); } } if (failed > 0) { logger.debug("Failed to add " + failed + " Jobs:"); final List nodes = result.selectNodes("/result/failed/job"); for (final Object node2 : nodes) { final Node node1 = (Node) node2; final String error = null != node1.selectSingleNode("error") ? node1.selectSingleNode("error").getStringValue() : "Failed"; final IStoredJobLoadResult storedJobLoadResult = parseStoredJobResult(node1, false, false, error); resultList.add(storedJobLoadResult); } } if (skipped > 0) { logger.debug("Skipped " + skipped + " Jobs:"); final List nodes = result.selectNodes("/result/skipped/job"); for (final Object node2 : nodes) { final Node node1 = (Node) node2; final String error = null != node1.selectSingleNode("error") ? node1.selectSingleNode("error").getStringValue() : "Skipped"; final IStoredJobLoadResult storedJobLoadResult = parseStoredJobResult(node1, true, true, error); resultList.add(storedJobLoadResult); } } return resultList; }
From source file:com.dtolabs.client.services.RundeckCentralDispatcher.java
License:Apache License
private IStoredJobLoadResult parseStoredJobResult(final Node node1, final boolean successful, final boolean skippedJob, final String message) { final String index = node1.selectSingleNode("@index").getStringValue(); final Node idNode = node1.selectSingleNode("id"); final String id = null != idNode ? idNode.getStringValue() : null; final String name = node1.selectSingleNode("name").getStringValue(); final Node urlNode = node1.selectSingleNode("url"); final String url = null != urlNode ? makeAbsoluteURL(urlNode.getStringValue()) : null; final String group = null != node1.selectSingleNode("group") ? node1.selectSingleNode("group").getStringValue() : null;//from ww w. ja v a2 s .c om final String description = null != node1.selectSingleNode("description") ? node1.selectSingleNode("description").getStringValue() : null; logger.debug("\t" + index + ": " + name + " [" + id + "] <" + url + ">"); int ndx = -1; try { ndx = Integer.parseInt(index); } catch (NumberFormatException e) { } return StoredJobLoadResultImpl.createLoadResult(id, name, url, group, description, successful, skippedJob, message); }
From source file:com.dtolabs.shared.resources.ResourceXMLParser.java
License:Apache License
/** * Parse a simple resource/entity node for the type/name attributes, returning a new or existing Entity * * @param set entity set/*from w w w .j a v a2s .c o m*/ * @param n entity DOM node * * @return new or existing Entity * * @throws ResourceXMLParserException if the ndoe is missing the required attributes */ private Entity parseResourceRef(final EntitySet set, final Node n) throws ResourceXMLParserException { final Node node2 = n.selectSingleNode("@" + COMMON_NAME); if (null == node2) { throw new ResourceXMLParserException("@" + COMMON_NAME + " required: " + reportNodeErrorLocation(n)); } final String rname = node2.getStringValue(); return set.getOrCreateEntity(rname); }
From source file:com.feilong.framework.bind.parse.base.StandardXpathExpressionXmlParse.java
License:Apache License
@Override protected Map<String, String> getVarNameAndValueMap(String xml) { if (Validator.isNullOrEmpty(xml)) { throw new IllegalArgumentException("xml can't be null/empty!"); }/*from w ww .j av a 2 s . co m*/ Document document = Dom4jUtil.string2Document(xml); @SuppressWarnings("unchecked") List<Node> selectNodes = document.selectNodes(xpathExpression); Map<String, String> varNameAndValueMap = new TreeMap<String, String>(); for (Node node : selectNodes) { String varName = node.getName(); String stringValue = node.getStringValue(); varNameAndValueMap.put(varName, stringValue); } if (log.isDebugEnabled()) { log.debug("varNameAndValueMap:{}", JsonUtil.format(varNameAndValueMap)); } return varNameAndValueMap; }
From source file:com.feilong.framework.netpay.advance.adaptor.doku.util.DokuQueryResultParse.java
License:Apache License
/** * ? wddxPacketXML ,? var name .//w w w.j av a 2 s . co m * * @param xml * the wddx packet xml * @return the var name and value map */ @Override protected Map<String, String> getVarNameAndValueMap(String xml) { Document document = Dom4jUtil.string2Document(xml); @SuppressWarnings("unchecked") List<Node> selectNodes = document.selectNodes(XPATH_EXPRESSION_VAR); Map<String, String> varNameAndValueMap = new HashMap<String, String>(); for (Node node : selectNodes) { String varName = node.getName(); String stringValue = node.getStringValue(); varNameAndValueMap.put(varName, stringValue); } if (log.isDebugEnabled()) { log.debug("varNameAndValueMap:{}", JsonUtil.format(varNameAndValueMap)); } return varNameAndValueMap; }
From source file:com.feilong.framework.netpay.advance.adaptor.sprintasia.creditcard.util.CreditCardQueryResultPaser.java
License:Apache License
/** * ? wddxPacketXML ,? var name .//www.j ava 2s . c o m * * @param wddxPacketXML * the wddx packet xml * @return the var name and value map */ @Override protected Map<String, String> getVarNameAndValueMap(String wddxPacketXML) { Document document = Dom4jUtil.string2Document(wddxPacketXML); @SuppressWarnings("unchecked") List<Node> selectNodes = document.selectNodes(XPATH_EXPRESSION_VAR); Map<String, String> varNameAndValueMap = new HashMap<String, String>(); for (Node node : selectNodes) { String varName = Dom4jUtil.getAttributeValue(node, "name"); String stringValue = node.getStringValue(); varNameAndValueMap.put(varName, stringValue); } if (log.isInfoEnabled()) { log.info("varNameAndValueMap:{}", JsonUtil.format(varNameAndValueMap)); } return varNameAndValueMap; }
From source file:com.globalsight.everest.edit.offline.ttx.TTXParser.java
License:Apache License
/** * Parse main contents//from ww w. jav a2s. c om * * @param p_element */ private void domNodehandler(Node p_node, boolean isSource) { // public static final short ANY_NODE 0 // public static final short ATTRIBUTE_NODE 2 // public static final short CDATA_SECTION_NODE 4 // public static final short COMMENT_NODE 8 // public static final short DOCUMENT_NODE 9 // public static final short DOCUMENT_TYPE_NODE 10 // public static final short ELEMENT_NODE 1 // public static final short ENTITY_REFERENCE_NODE 5 // public static final short MAX_NODE_TYPE 14 // public static final short NAMESPACE_NODE 13 // public static final short PROCESSING_INSTRUCTION_NODE 7 // public static final short TEXT_NODE 3 // public static final short UNKNOWN_NODE 14 if (p_node == null) { return; } switch (p_node.getNodeType()) { case Node.ELEMENT_NODE: elementNodeProcessor(p_node, isSource); break; case Node.TEXT_NODE: String nodeValue = p_node.getStringValue(); if (nodeValue.startsWith("#")) { nodeValue = nodeValue.replaceFirst("#", OfflineConstants.PONUD_SIGN); } if (isParsingTTXForGS) { boolean isInTargetTuv = isInTargetTuv(p_node); if (nodeValue != null && isInTargetTuv) { results.append(nodeValue); } else if (nodeValue != null && isLockedSegment(p_node)) { results.append(AmbassadorDwUpConstants.SEGMENT_MATCH_TYPE_KEY).append(" ") .append("DO NOT TRANSLATE OR MODIFY (Locked).").append(TTXConstants.NEW_LINE); results.append(nodeValue); } } else { results.append(nodeValue); } break; default: return; } }