@Override public String apply(@Nonnull XmlElement input) { // Trim possible leading/tailing whitespace try { return input.getTextContent().trim(); } catch (DocumentedException e) { LOG.trace("Error fetching input text content",e); return null; } } });
private static boolean prefixedContentMatches(final XmlElement filter, final XmlElement src) throws DocumentedException { final Map.Entry<String, String> prefixToNamespaceOfFilter; final Map.Entry<String, String> prefixToNamespaceOfSrc; try { prefixToNamespaceOfFilter = filter.findNamespaceOfTextContent(); prefixToNamespaceOfSrc = src.findNamespaceOfTextContent(); } catch (IllegalArgumentException e) { //if we can't find namespace of prefix - it's not a prefix, so it doesn't match return false; } final String prefix = prefixToNamespaceOfFilter.getKey(); // If this is not a prefixed content, we do not need to continue since content do not match if (prefix.equals(XmlElement.DEFAULT_NAMESPACE_PREFIX)) { return false; } // Namespace mismatch if (!prefixToNamespaceOfFilter.getValue().equals(prefixToNamespaceOfSrc.getValue())) { return false; } final String unprefixedFilterContent = filter.getTextContent().substring(prefixToNamespaceOfFilter.getKey().length() + 1); final String unprefixedSrcContnet = src.getTextContent().substring(prefixToNamespaceOfSrc.getKey().length() + 1); // Finally compare unprefixed content return unprefixedFilterContent.equals(unprefixedSrcContnet); }
/** * Search for element's attributes defining namespaces. Look for the one * namespace that matches prefix of element's text content. E.g. * * <pre> * <type * xmlns:th-java="urn:opendaylight:params:xml:ns:yang:controller:threadpool:impl">th-java:threadfactory-naming</type> * </pre> * * returns {"th-java","urn:.."}. If no prefix is matched, then default * namespace is returned with empty string as key. If no default namespace * is found value will be null. */ public Map.Entry<String/* prefix */, String/* namespace */> findNamespaceOfTextContent() throws DocumentedException { Map<String, String> namespaces = extractNamespaces(); String textContent = getTextContent(); int indexOfColon = textContent.indexOf(':'); String prefix; if (indexOfColon > -1) { prefix = textContent.substring(0, indexOfColon); } else { prefix = DEFAULT_NAMESPACE_PREFIX; } if (!namespaces.containsKey(prefix)) { throw new IllegalArgumentException("Cannot find namespace for " + XmlUtil.toString(element) + ". Prefix from content is " + prefix + ". Found namespaces " + namespaces); } return Maps.immutableEntry(prefix, namespaces.get(prefix)); }
GetSchemaEntry(final XmlElement getSchemaElement) throws DocumentedException { getSchemaElement.checkName(GET_SCHEMA); getSchemaElement.checkNamespace(XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_YANG_IETF_NETCONF_MONITORING); XmlElement identifierElement = null; try { identifierElement = getSchemaElement.getOnlyChildElementWithSameNamespace(IDENTIFIER); } catch (final DocumentedException e) { LOG.trace("Can't get identifier element as only child element with same namespace due to ",e); throw DocumentedException.wrap(e); } identifier = identifierElement.getTextContent(); final Optional<XmlElement> versionElement = getSchemaElement .getOnlyChildElementWithSameNamespaceOptionally(VERSION); if (versionElement.isPresent()) { version = Optional.of(versionElement.get().getTextContent()); } else { version = Optional.absent(); } } }
.getOnlyChildElementWithSameNamespaceOptionally(EditConfigXmlParser.TEST_OPTION_KEY); if (testOptionElementOpt.isPresent()) { String testOptionValue = testOptionElementOpt.get().getTextContent(); testOption = TestOption.getFromXmlName(testOptionValue); } else { .getOnlyChildElementWithSameNamespaceOptionally(EditConfigXmlParser.ERROR_OPTION_KEY); if (errorOptionElement.isPresent()) { String errorOptionParsed = errorOptionElement.get().getTextContent(); if (!errorOptionParsed.equals(EditConfigXmlParser.DEFAULT_ERROR_OPTION)){ throw new UnsupportedOperationException("Only " + EditConfigXmlParser.DEFAULT_ERROR_OPTION .getOnlyChildElementWithSameNamespaceOptionally(EditConfigXmlParser.DEFAULT_OPERATION_KEY); if (defaultContent.isPresent()) { String mergeStrategyString = defaultContent.get().getTextContent(); LOG.trace("Setting merge strategy to {}", mergeStrategyString); editStrategyType = EditStrategyType.valueOf(mergeStrategyString);
.getTextContent(), netconfOperationName, netconfOperationNamespace);