@Test public void expressionEvaluatorWithoutAutoTextExtraction_givenExpression_shoulReturnCorrectValue() { String expression = "./author"; ExpressionEvaluatorFactory<XdmItem> evaluatorFactory = xpathResolver.getExpressionEvaluatorFactory(); EvaluateExpression evaluateExpression = evaluatorFactory.apply(nodes.get(0)); assertThat(evaluateExpression.apply(expression).get(), is("Giada De Laurentiis")); boolean autoExtractNodeText = false; xpathResolver = new XPathResolver(autoExtractNodeText); nodeIterator = xpathResolver.bindSource(LSOURCE, sourceResolver).get(); evaluatorFactory = xpathResolver.getExpressionEvaluatorFactory(); nodes = Lists.newArrayList(nodeIterator); evaluateExpression = evaluatorFactory.apply(nodes.get(0)); assertThat(evaluateExpression.apply(expression).get(), is("<author>Giada De Laurentiis</author>")); }
@Override public ExpressionEvaluatorFactory<XdmItem> getExpressionEvaluatorFactory() { return entry -> expression -> { try { XPathSelector selector = xpath.compile(expression).load(); selector.setContextItem(entry); XdmValue value = selector.evaluate(); if (value.size() > 1) { List<String> results = new ArrayList<>(); value.forEach(i -> { String sValue = getItemStringValue(i, value); if (sValue != null) { results.add(sValue); } } ); return Optional.of(results); } else if (value.size() == 0) { return Optional.empty(); } XdmItem item = value.itemAt(0); return Optional.ofNullable(getItemStringValue(item, value)); } catch (SaxonApiException e) { throw new RuntimeException(String.format( "Error applying XPath expression [%s] to entry [%s]", entry, expression), e); } }; }
XPathResolver implements LogicalSourceResolver<XdmItem> { @Override public ExpressionEvaluatorFactory<XdmItem> getExpressionEvaluatorFactory() { return entry -> expression -> { try { XPathSelector selector = xpath.compile(expression).load(); selector.setContextItem(entry); XdmValue value = selector.evaluate(); if (value.size() > 1) { List<String> results = new ArrayList<>(); value.forEach(i -> { String sValue = getItemStringValue(i, value); if (sValue != null) { results.add(sValue); } } ); return Optional.of(results); } else if (value.size() == 0) { return Optional.empty(); } XdmItem item = value.itemAt(0); return Optional.ofNullable(getItemStringValue(item, value)); } catch (SaxonApiException e) { throw new RuntimeException(String.format( "Error applying XPath expression [%s] to entry [%s]", entry, expression), e); } }; } }
XPathResolver implements LogicalSourceResolver<XdmItem> { @Override public ExpressionEvaluatorFactory<XdmItem> getExpressionEvaluatorFactory() { return entry -> expression -> { try { XPathSelector selector = xpath.compile(expression).load(); selector.setContextItem(entry); XdmValue value = selector.evaluate(); if (value.size() > 1) { List<String> results = new ArrayList<>(); value.forEach(i -> { String sValue = getItemStringValue(i, value); if (sValue != null) { results.add(sValue); } } ); return Optional.of(results); } else if (value.size() == 0) { return Optional.empty(); } XdmItem item = value.itemAt(0); return Optional.ofNullable(getItemStringValue(item, value)); } catch (SaxonApiException e) { throw new RuntimeException(String.format( "Error applying XPath expression [%s] to entry [%s]", entry, expression), e); } }; } XPathResolver();  XPathResolver(boolean autoNodeTextExtraction); }
XPathResolver implements LogicalSourceResolver<XdmItem> { @Override public ExpressionEvaluatorFactory<XdmItem> getExpressionEvaluatorFactory() { return entry -> expression -> { try { XPathSelector selector = xpath.compile(expression).load(); selector.setContextItem(entry); XdmValue value = selector.evaluate(); if (value.size() > 1) { List<String> results = new ArrayList<>(); value.forEach(i -> { String sValue = getItemStringValue(i, value); if (sValue != null) { results.add(sValue); } } ); return Optional.of(results); } else if (value.size() == 0) { return Optional.empty(); } XdmItem item = value.itemAt(0); return Optional.ofNullable(getItemStringValue(item, value)); } catch (SaxonApiException e) { throw new RuntimeException(String.format( "Error applying XPath expression [%s] to entry [%s]", entry, expression), e); } }; } XPathResolver();  XPathResolver(boolean autoNodeTextExtraction); boolean autoExtractsNodeText(); @Override SourceIterator<XdmItem> getSourceIterator(); @Override ExpressionEvaluatorFactory<XdmItem> getExpressionEvaluatorFactory(); }
XPathResolver implements LogicalSourceResolver<XdmItem> { @Override public ExpressionEvaluatorFactory<XdmItem> getExpressionEvaluatorFactory() { return entry -> expression -> { try { XPathSelector selector = xpath.compile(expression).load(); selector.setContextItem(entry); XdmValue value = selector.evaluate(); if (value.size() > 1) { List<String> results = new ArrayList<>(); value.forEach(i -> { String sValue = getItemStringValue(i, value); if (sValue != null) { results.add(sValue); } } ); return Optional.of(results); } else if (value.size() == 0) { return Optional.empty(); } XdmItem item = value.itemAt(0); return Optional.ofNullable(getItemStringValue(item, value)); } catch (SaxonApiException e) { throw new RuntimeException(String.format( "Error applying XPath expression [%s] to entry [%s]", entry, expression), e); } }; } XPathResolver();  XPathResolver(boolean autoNodeTextExtraction); boolean autoExtractsNodeText(); @Override SourceIterator<XdmItem> getSourceIterator(); @Override ExpressionEvaluatorFactory<XdmItem> getExpressionEvaluatorFactory();  }