public static XmlElement fromString(String s) throws DocumentedException { try { return new XmlElement(XmlUtil.readXmlToElement(s)); } catch (IOException | SAXException e) { throw DocumentedException.wrap(e); } }
public static XmlElement fromDomElementWithExpected(Element element, String expectedName) throws DocumentedException { XmlElement xmlElement = XmlElement.fromDomElement(element); xmlElement.checkName(expectedName); return xmlElement; }
@Override public String toString() { return "NetconfDocumentedException{" + "message=" + getMessage() + ", errorType=" + this.errorType + ", errorTag=" + this.errorTag + ", errorSeverity=" + this.errorSeverity + ", errorInfo=" + this.errorInfo + '}'; } }
public XmlElement getOnlyChildElementWithSameNamespace() throws DocumentedException { XmlElement childElement = getOnlyChildElement(); childElement.checkNamespace(getNamespace()); return childElement; }
private static void checkXml(XmlElement xml) throws DocumentedException { xml.checkName(XmlNetconfConstants.GET); xml.checkNamespace(XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0); // Filter option: ignore for now, TODO only load modules specified by the filter }
public XmlElement getOnlyChildElement(String childName) throws DocumentedException { List<XmlElement> nameElements = getChildElements(childName); if (nameElements.size() != 1){ throw new DocumentedException("One element " + childName + " expected in " + toString(), DocumentedException.ErrorType.application, DocumentedException.ErrorTag.invalid_value, DocumentedException.ErrorSeverity.error); } return nameElements.get(0); }
private XmlElement getElement(final XmlElement operationElement, String elementName) throws DocumentedException { final Optional<XmlElement> childNode = operationElement.getOnlyChildElementOptionally(elementName); if (!childNode.isPresent()) { throw new DocumentedException(elementName + " element is missing", ErrorType.protocol, ErrorTag.missing_element, ErrorSeverity.error); } return childNode.get(); }
public static XmlElement fromDomElementWithExpected(Element element, String expectedName, String expectedNamespace) throws DocumentedException { XmlElement xmlElement = XmlElement.fromDomElementWithExpected(element, expectedName); xmlElement.checkNamespace(expectedNamespace); return xmlElement; }
public static String toString(final XmlElement xmlElement) { return toString(xmlElement.getDomElement(), false); }
public void checkNamespace(String expectedNamespace) throws UnexpectedNamespaceException, MissingNameSpaceException { if (!getNamespace().equals(expectedNamespace)) { throw new UnexpectedNamespaceException(String.format("Unexpected namespace %s should be %s", getNamespace(), expectedNamespace), DocumentedException.ErrorType.application, DocumentedException.ErrorTag.operation_failed, DocumentedException.ErrorSeverity.error); } }
public void checkName(String expectedName) throws UnexpectedElementException { if (!getName().equals(expectedName)){ throw new UnexpectedElementException(String.format("Expected %s xml element but was %s", expectedName, getName()), DocumentedException.ErrorType.application, DocumentedException.ErrorTag.operation_failed, DocumentedException.ErrorSeverity.error); } }
public void checkNamespaceAttribute(String expectedNamespace) throws UnexpectedNamespaceException, MissingNameSpaceException { if (!getNamespaceAttribute().equals(expectedNamespace)) { throw new UnexpectedNamespaceException(String.format("Unexpected namespace %s should be %s", getNamespaceAttribute(), expectedNamespace), DocumentedException.ErrorType.application, DocumentedException.ErrorTag.operation_failed, DocumentedException.ErrorSeverity.error); } }
public List<XmlElement> getChildElementsWithinNamespace(final String namespace) { return getChildElementsInternal(new ElementFilteringStrategy() { @Override public boolean accept(Element e) { try { return XmlElement.fromDomElement(e).getNamespace().equals(namespace); } catch (MissingNameSpaceException e1) { return false; } } }); }
public static ErrorType from( String text ) { try { return valueOf( text ); } catch( Exception e ) { return application; } } }
public static ErrorSeverity from( String text ) { try { return valueOf( text ); } catch( Exception e ) { return error; } } }
public String getTagValue() { return name(); }
private static void validateInputRpc(final XmlElement xml, String operationName) throws DocumentedException{ xml.checkName(operationName); xml.checkNamespace(XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0); }
public List<XmlElement> getChildElements() { return getChildElementsInternal(new ElementFilteringStrategy() { @Override public boolean accept(Element e) { return true; } }); }
private static void fromXml(XmlElement xml) throws DocumentedException { xml.checkName(DISCARD); xml.checkNamespace(XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0); }
private static void checkXml(XmlElement xml) throws DocumentedException { xml.checkName(XmlNetconfConstants.COMMIT); xml.checkNamespace(XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0); }