/** * Same as {@link #asByteBuffer(String, Node)} but allows an xpath to be * passed in explicitly for reuse. */ public static ByteBuffer asByteBuffer(String expression, Node node, XPath xpath) throws XPathExpressionException { String base64EncodedString = evaluateAsString(expression, node, xpath); if (isEmptyString(base64EncodedString)) return null; if (!isEmpty(node)) { byte[] decodedBytes = Base64.decode(base64EncodedString); return ByteBuffer.wrap(decodedBytes); } return null; }
if (isEmpty(node)) return null;
/** * Same as {@link #asByteBuffer(String, Node)} but allows an xpath to be * passed in explicitly for reuse. */ public static ByteBuffer asByteBuffer(String expression, Node node, XPath xpath) throws XPathExpressionException { String base64EncodedString = evaluateAsString(expression, node, xpath); if (isEmptyString(base64EncodedString)) return null; if (!isEmpty(node)) { byte[] decodedBytes = Base64.decode(base64EncodedString); return ByteBuffer.wrap(decodedBytes); } return null; }
if (isEmpty(node)) return null;
/** * Evaluates the specified xpath expression, base64 decodes the data and * returns the result as a ByteBuffer. * * @param expression The Xpath expression to evaluate. * @param node The node on which to evaluate the expression. * @return A ByteBuffer of base64 decoded data from the result of evaluating * the specified Xpath expression. * @throws XPathExpressionException If there are any problems evaluating the * Xpath expression. */ public static ByteBuffer asByteBuffer(String expression, Node node) throws XPathExpressionException { String base64EncodedString = evaluateAsString(expression, node); if (isEmptyString(base64EncodedString)) return null; if (!isEmpty(node)) { byte[] decodedBytes = Base64.decode(base64EncodedString); return ByteBuffer.wrap(decodedBytes); } return null; }
/** * Evaluates the specified expression on the specified node and returns the * result as a String. * * @param expression The Xpath expression to evaluate. * @param node The node on which to evaluate the expression. * @return The result of evaluating the specified expression, or null if the * evaluation didn't return any result. * @throws XPathExpressionException If there are any problems evaluating the * Xpath expression. */ private static String evaluateAsString(String expression, Node node) throws XPathExpressionException { if (isEmpty(node)) return null; if (!".".equals(expression)) { /* * If the expression being evaluated doesn't select a node, we want * to return null to distinguish between cases where a node isn't * present (which should be represented as null) and when a node is * present, but empty (which should be represented as the empty * string). We skip this test if the expression is "." since we've * already checked that the node exists. */ if (asNode(expression, node) == null) return null; } String s = xpath().evaluate(expression, node); return s.trim(); }
/** * Same as {@link #asByteBuffer(String, Node)} but allows an xpath to be * passed in explicitly for reuse. */ public static ByteBuffer asByteBuffer(String expression, Node node, XPath xpath) throws XPathExpressionException { String base64EncodedString = evaluateAsString(expression, node, xpath); if (isEmptyString(base64EncodedString)) return null; if (!isEmpty(node)) { byte[] decodedBytes = Base64.decode(base64EncodedString); return ByteBuffer.wrap(decodedBytes); } return null; }
@Test public void testIsEmpty() throws Exception { Document document = XpathUtils.documentFrom(DOCUMENT); Node emptyNode = XpathUtils.asNode("Foo/Fake", document); Node realNode = XpathUtils.asNode("Foo/Count", document); assertTrue(XpathUtils.isEmpty(emptyNode)); assertFalse(XpathUtils.isEmpty(realNode)); }
/** * Evaluates the specified xpath expression, base64 decodes the data and * returns the result as a ByteBuffer. * * @param expression The Xpath expression to evaluate. * @param node The node on which to evaluate the expression. * @return A ByteBuffer of base64 decoded data from the result of evaluating * the specified Xpath expression. * @throws XPathExpressionException If there are any problems evaluating the * Xpath expression. */ public static ByteBuffer asByteBuffer(String expression, Node node) throws XPathExpressionException { String base64EncodedString = evaluateAsString(expression, node); if (isEmptyString(base64EncodedString)) return null; if (!isEmpty(node)) { byte[] decodedBytes = Base64.decode(base64EncodedString); return ByteBuffer.wrap(decodedBytes); } return null; }
if (isEmpty(node)) return null;
/** * Evaluates the specified xpath expression, base64 decodes the data and * returns the result as a ByteBuffer. * * @param expression The Xpath expression to evaluate. * @param node The node on which to evaluate the expression. * @return A ByteBuffer of base64 decoded data from the result of evaluating * the specified Xpath expression. * @throws XPathExpressionException If there are any problems evaluating the * Xpath expression. */ public static ByteBuffer asByteBuffer(String expression, Node node) throws XPathExpressionException { String base64EncodedString = evaluateAsString(expression, node); if (isEmptyString(base64EncodedString)) return null; if (!isEmpty(node)) { byte[] decodedBytes = Base64.decode(base64EncodedString); return ByteBuffer.wrap(decodedBytes); } return null; }
/** * Evaluates the specified expression on the specified node and returns the * result as a String. * * @param expression The Xpath expression to evaluate. * @param node The node on which to evaluate the expression. * @return The result of evaluating the specified expression, or null if the * evaluation didn't return any result. * @throws XPathExpressionException If there are any problems evaluating the * Xpath expression. */ private static String evaluateAsString(String expression, Node node) throws XPathExpressionException { if (isEmpty(node)) return null; if (!".".equals(expression)) { /* * If the expression being evaluated doesn't select a node, we want * to return null to distinguish between cases where a node isn't * present (which should be represented as null) and when a node is * present, but empty (which should be represented as the empty * string). We skip this test if the expression is "." since we've * already checked that the node exists. */ if (asNode(expression, node) == null) return null; } String s = xpath().evaluate(expression, node); return s.trim(); }
/** * Evaluates the specified expression on the specified node and returns the * result as a String. * * @param expression The Xpath expression to evaluate. * @param node The node on which to evaluate the expression. * @return The result of evaluating the specified expression, or null if the * evaluation didn't return any result. * @throws XPathExpressionException If there are any problems evaluating the * Xpath expression. */ private static String evaluateAsString(String expression, Node node) throws XPathExpressionException { if (isEmpty(node)) return null; if (!".".equals(expression)) { /* * If the expression being evaluated doesn't select a node, we want * to return null to distinguish between cases where a node isn't * present (which should be represented as null) and when a node is * present, but empty (which should be represented as the empty * string). We skip this test if the expression is "." since we've * already checked that the node exists. */ if (asNode(expression, node) == null) return null; } String s = xpath().evaluate(expression, node); return s.trim(); }