public static String toString(final XmlElement xmlElement) { return toString(xmlElement.getDomElement(), false); }
private ModifyAction getDefaultOperation(final XmlElement operationElement) throws DocumentedException { final NodeList elementsByTagName = operationElement.getDomElement().getElementsByTagName(DEFAULT_OPERATION_KEY); if(elementsByTagName.getLength() == 0) { return ModifyAction.MERGE; } else if(elementsByTagName.getLength() > 1) { throw new DocumentedException("Multiple " + DEFAULT_OPERATION_KEY + " elements", ErrorType.rpc, ErrorTag.unknown_attribute, ErrorSeverity.error); } else { return ModifyAction.fromXmlValue(elementsByTagName.item(0).getTextContent()); } }
private static Document extractNotificationContent(Document notification) throws DocumentedException { XmlElement root = XmlElement.fromDomElement(notification.getDocumentElement()); XmlElement content = root.getOnlyChildElement(); notification.removeChild(root.getDomElement()); notification.appendChild(content.getDomElement()); return notification; }
private Element getPlaceholder(final Document innerResult) throws DocumentedException { final XmlElement rootElement = XmlElement.fromDomElementWithExpected( innerResult.getDocumentElement(), XmlMappingConstants.RPC_REPLY_KEY, XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0); return rootElement.getOnlyChildElement(XmlNetconfConstants.DATA_KEY).getDomElement(); }
private static Document filtered(XmlElement filter, Document originalReplyDocument) throws DocumentedException { Document result = XmlUtil.newDocument(); // even if filter is empty, copy /rpc/data Element rpcReply = originalReplyDocument.getDocumentElement(); Node rpcReplyDst = result.importNode(rpcReply, false); result.appendChild(rpcReplyDst); XmlElement dataSrc = XmlElement.fromDomElement(rpcReply).getOnlyChildElement("data", XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0); Element dataDst = (Element) result.importNode(dataSrc.getDomElement(), false); rpcReplyDst.appendChild(dataDst); addSubtree(filter, dataSrc, XmlElement.fromDomElement(dataDst)); return result; }
private Datastore extractTargetParameter(final XmlElement operationElement) throws DocumentedException { final NodeList elementsByTagName = operationElement.getDomElement().getElementsByTagName(TARGET_KEY); // Direct lookup instead of using XmlElement class due to performance if (elementsByTagName.getLength() == 0) { throw new DocumentedException("Missing target element", ErrorType.rpc, ErrorTag.missing_attribute, ErrorSeverity.error); } else if (elementsByTagName.getLength() > 1) { throw new DocumentedException("Multiple target elements", ErrorType.rpc, ErrorTag.unknown_attribute, ErrorSeverity.error); } else { final XmlElement targetChildNode = XmlElement.fromDomElement((Element) elementsByTagName.item(0)).getOnlyChildElement(); return Datastore.valueOf(targetChildNode.getName()); } }
/** * Parses xml element rpc input into normalized node or null if rpc does not take any input * @param oElement rpc xml element * @param input input container schema node, or null if rpc does not take any input * @return parsed rpc into normalized node, or null if input schema is null */ @Nullable private NormalizedNode<?, ?> rpcToNNode(final XmlElement oElement, @Nullable final ContainerSchemaNode input) { return input == null ? null : DomToNormalizedNodeParserFactory .getInstance(DomUtils.defaultValueCodecProvider(), schemaContext.getCurrentContext()) .getContainerNodeParser() .parse(Collections.singletonList(oElement.getDomElement()), input); }
private static Document filteredNotification(XmlElement filter, Document originalNotification) throws DocumentedException { Document result = XmlUtil.newDocument(); XmlElement dataSrc = XmlElement.fromDomDocument(originalNotification); Element dataDst = (Element) result.importNode(dataSrc.getDomElement(), false); for (XmlElement filterChild : filter.getChildElements()) { addSubtree2(filterChild, dataSrc.getOnlyChildElement(), XmlElement.fromDomElement(dataDst)); } if(dataDst.getFirstChild() != null) { result.appendChild(dataDst.getFirstChild()); return result; } else { return null; } }
private static MatchingResult addSubtree2(XmlElement filter, XmlElement src, XmlElement dstParent) throws DocumentedException { Document document = dstParent.getDomElement().getOwnerDocument(); MatchingResult matches = matches(src, filter); if (matches != MatchingResult.NO_MATCH && matches != MatchingResult.CONTENT_MISMATCH) { Element copied = (Element) document.importNode(src.getDomElement(), filterHasChildren == false); boolean shouldAppend = filterHasChildren == false; if (filterHasChildren) { // this implies TAG_MATCH copied = (Element) document.importNode(src.getDomElement(), true); dstParent.getDomElement().appendChild(copied);
private NormalizedNode parseIntoNormalizedNode(final DataSchemaNode schemaNode, final XmlElement element, final DomToNormalizedNodeParserFactory.BuildingStrategyProvider editOperationStrategyProvider) { if (schemaNode instanceof ContainerSchemaNode) { return DomToNormalizedNodeParserFactory .getInstance(DomUtils.defaultValueCodecProvider(), schemaContext.getCurrentContext(), editOperationStrategyProvider) .getContainerNodeParser() .parse(Collections.singletonList(element.getDomElement()), (ContainerSchemaNode) schemaNode); } else if (schemaNode instanceof ListSchemaNode) { return DomToNormalizedNodeParserFactory .getInstance(DomUtils.defaultValueCodecProvider(), schemaContext.getCurrentContext(), editOperationStrategyProvider) .getMapNodeParser() .parse(Collections.singletonList(element.getDomElement()), (ListSchemaNode) schemaNode); } else { //this should never happen since edit-config on any other node type should not be possible nor makes sense LOG.debug("DataNode from module is not ContainerSchemaNode nor ListSchemaNode, aborting.."); } throw new UnsupportedOperationException("implement exception if parse fails"); }