use of org.opendaylight.netconf.api.xml.XmlElement in project netconf by opendaylight.
the class NetconfMessageUtil method extractCapabilitiesFromHello.
public static Collection<String> extractCapabilitiesFromHello(final Document doc) {
XmlElement responseElement = XmlElement.fromDomDocument(doc);
// Extract child element <capabilities> from <hello> with or without(fallback) the same namespace
Optional<XmlElement> capabilitiesElement = responseElement.getOnlyChildElementWithSameNamespaceOptionally(XmlNetconfConstants.CAPABILITIES);
if (capabilitiesElement.isEmpty()) {
capabilitiesElement = responseElement.getOnlyChildElementOptionally(XmlNetconfConstants.CAPABILITIES);
}
List<XmlElement> caps = capabilitiesElement.get().getChildElements(XmlNetconfConstants.CAPABILITY);
return Collections2.transform(caps, input -> {
// Trim possible leading/tailing whitespace
try {
return input.getTextContent().trim();
} catch (DocumentedException e) {
LOG.trace("Error fetching input text content", e);
return null;
}
});
}
use of org.opendaylight.netconf.api.xml.XmlElement in project netconf by opendaylight.
the class SubtreeFilter method applyRpcSubtreeFilter.
public static Document applyRpcSubtreeFilter(final Document requestDocument, final Document rpcReply) throws DocumentedException {
OperationNameAndNamespace operationNameAndNamespace = new OperationNameAndNamespace(requestDocument);
if (XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0.equals(operationNameAndNamespace.getNamespace()) && XmlNetconfConstants.GET.equals(operationNameAndNamespace.getOperationName()) || XmlNetconfConstants.GET_CONFIG.equals(operationNameAndNamespace.getOperationName())) {
// process subtree filtering here, in case registered netconf operations do
// not implement filtering.
Optional<XmlElement> maybeFilter = operationNameAndNamespace.getOperationElement().getOnlyChildElementOptionally(XmlNetconfConstants.FILTER, XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0);
if (maybeFilter.isEmpty()) {
return rpcReply;
}
XmlElement filter = maybeFilter.get();
if (isSupported(filter)) {
// do
return filtered(maybeFilter.get(), rpcReply);
}
}
// return identical document
return rpcReply;
}
use of org.opendaylight.netconf.api.xml.XmlElement in project netconf by opendaylight.
the class SubtreeFilter method extractNotificationContent.
private static Document extractNotificationContent(final Document notification) throws DocumentedException {
XmlElement root = XmlElement.fromDomElement(notification.getDocumentElement());
XmlElement content = root.getOnlyChildElement();
notification.removeChild(root.getDomElement());
notification.appendChild(content.getDomElement());
return notification;
}
use of org.opendaylight.netconf.api.xml.XmlElement in project netconf by opendaylight.
the class SubtreeFilter method filteredNotification.
private static Document filteredNotification(final XmlElement filter, final 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;
}
return null;
}
use of org.opendaylight.netconf.api.xml.XmlElement in project netconf by opendaylight.
the class AbstractNetconfOperation method handle.
@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, XmlNetconfConstants.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;
}
Aggregations