public static Document createDocumentCopy(final Document original) { final Document copiedDocument = newDocument(); final Node copiedRoot = copiedDocument.importNode(original.getDocumentElement(), true); copiedDocument.appendChild(copiedRoot); return copiedDocument; } }
public static NetconfStartExiMessage create(final EXIOptions exiOptions, final String messageId) { final Document doc = XmlUtil.newDocument(); final Element rpcElement = doc.createElementNS(XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0, XmlNetconfConstants.RPC_KEY); rpcElement.setAttributeNS(XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0, XmlNetconfConstants.MESSAGE_ID, messageId); // TODO draft http://tools.ietf.org/html/draft-varga-netconf-exi-capability-02#section-3.5.1 has no namespace for start-exi element in xml final Element startExiElement = doc.createElementNS(XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_EXI_1_0, START_EXI); addAlignment(exiOptions, doc, startExiElement); addFidelity(exiOptions, doc, startExiElement); rpcElement.appendChild(startExiElement); doc.appendChild(rpcElement); return new NetconfStartExiMessage(doc); }
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; }
@Override public Document handle(final Document requestMessage, final NetconfOperationChainedExecution subsequentOperation) throws DocumentedException { final XmlElement requestElement = getRequestElementWithCheck(requestMessage); final Document document = XmlUtil.newDocument(); final XmlElement operationElement = requestElement.getOnlyChildElement(); final Map<String, Attr> attributes = requestElement.getAttributes(); final Element response = handle(document, operationElement, subsequentOperation); final Element rpcReply = XmlUtil.createElement(document, XmlMappingConstants.RPC_REPLY_KEY, Optional.of(XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0)); if(XmlElement.fromDomElement(response).hasNamespace()) { rpcReply.appendChild(response); } else { final NodeList list = response.getChildNodes(); if (list.getLength() == 0) { rpcReply.appendChild(response); } else { while (list.getLength() != 0) { rpcReply.appendChild(list.item(0)); } } } for (Attr attribute : attributes.values()) { rpcReply.setAttributeNode((Attr) document.importNode(attribute, true)); } document.appendChild(rpcReply); return document; }
@Override public Document handle(final Document requestMessage, final NetconfOperationChainedExecution subsequentOperation) throws DocumentedException { XmlElement requestElement = getRequestElementWithCheck(requestMessage); Document document = XmlUtil.newDocument(); XmlElement operationElement = requestElement.getOnlyChildElement(); Map<String, Attr> attributes = requestElement.getAttributes(); Element response = handle(document, operationElement, subsequentOperation); Element rpcReply = XmlUtil.createElement(document, XmlMappingConstants.RPC_REPLY_KEY, Optional.of(XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0)); if(XmlElement.fromDomElement(response).hasNamespace()) { rpcReply.appendChild(response); } else { Element responseNS = XmlUtil.createElement(document, response.getNodeName(), Optional.of(XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0)); NodeList list = response.getChildNodes(); while(list.getLength()!=0) { responseNS.appendChild(list.item(0)); } rpcReply.appendChild(responseNS); } for (Attr attribute : attributes.values()) { rpcReply.setAttributeNode((Attr) document.importNode(attribute, true)); } document.appendChild(rpcReply); return document; }
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 AnyXmlNode encapsulate(final DOMNotification body) { // FIXME: Introduce something like YangModeledAnyXmlNode in Yangtools final Document doc = XmlUtil.newDocument(); final Optional<String> namespace = Optional.of(PAYLOAD_ARG.getNodeType().getNamespace().toString()); final Element element = XmlUtil.createElement(doc, "payload", namespace); final DOMResult result = new DOMResult(element); final SchemaContext context = mount.getSchemaContext(); final SchemaPath schemaPath = body.getType(); try { NetconfUtil.writeNormalizedNode(body.getBody(), result, schemaPath, context); return Builders.anyXmlBuilder().withNodeIdentifier(PAYLOAD_ARG).withValue(new DOMSource(element)).build(); } catch (IOException | XMLStreamException e) { LOG.error("Unable to encapsulate notification.", e); throw Throwables.propagate(e); } }
ValidationException, ConflictingVersionException { Document document = XmlUtil.newDocument(); Element dataElement = XmlUtil.createElement(document, XmlMappingConstants.DATA_KEY, Optional.<String>absent()); Element modulesElement = XmlUtil.createElement(document, XmlMappingConstants.MODULES_KEY,