MCPcopy Index your code
hub / github.com/Juniper/netconf-java / findNodes

Method findNodes

src/main/java/net/juniper/netconf/XML.java:457–538  ·  view source on GitHub ↗

Get all the nodes at a given hierarchy, as list of org.w3c.dom.Node objects. @param list The String based list of elements which determine the hierarchy. For example, for the below XML: <rpc-reply> <environment-information> <environment-

(List<String> list)

Source from the content-addressed store, hash-verified

455 * @return The list containing Nodes as org.w3c.dom.Node objects.
456 */
457 public List<Node> findNodes(List<String> list) {
458 Element nextElement = ownerDoc.getDocumentElement();
459 boolean nextElementFound;
460 List<Node> finalList = new ArrayList<>();
461 for (int k=0; k<list.size(); k++) {
462 nextElementFound = false;
463 String nextElementName = list.get(k);
464 if (!nextElementName.contains("~")) {
465 NodeList nextElementList =
466 nextElement != null
467 ? nextElement.getElementsByTagName(nextElementName)
468 : null;
469 if (nextElementList == null || nextElementList.getLength() == 0) {
470 logger.fine("Element '" + nextElementName + "' not found in findNodes()");
471 return null;
472 }
473 /* If the next to next(n2n) element is a filter based on
474 * text value,
475 * then do the required filtering.
476 * For example,
477 * ....
478 * <physical-interface>
479 * <name>ge-1/0/0</name>
480 * <logical-interface>
481 * ....
482 * In this case, the list passed to findValue function
483 * should contain (..,"physical-interface","name~ge-1/0/0",
484 * "logical-interface",..)
485 * This will fetch me the required element.
486 */
487 String n2nString = null;
488 if (k<list.size()-1)
489 n2nString = list.get(k+1);
490 if (n2nString != null && n2nString.contains("~")) {
491 /* Since the n2n element is a filter based on text value
492 * ( decided by '~')
493 * we now traverse the entire NodeList to find the
494 * correct nextElement
495 * based on the text value of the filter.
496 */
497 String n2nText = n2nString.substring(n2nString.
498 indexOf("~") + 1);
499 String n2nElementName = n2nString.substring(0,
500 n2nString.indexOf("~"));
501 for (int i=0; i<nextElementList.getLength(); i++) {
502 nextElement = (Element)nextElementList.item(i);
503 Element n2nElement = (Element)nextElement.
504 getElementsByTagName(n2nElementName).item(0);
505 String text = n2nElement.getFirstChild().
506 getNodeValue();
507 text = trim(text);
508 if (text.equals(n2nText)) {
509 nextElementFound = true;
510 break;
511 }
512 }
513 if (!nextElementFound)
514 return null;

Calls 3

trimMethod · 0.95
indexOfMethod · 0.80
equalsMethod · 0.45