public int compare(Node n1, Node n2) { try { // apply the xpaths. not using stringValueOf since I don't // want all of the child nodes appended to the strings Object val1 = xpath.evaluate(n1); Object val2 = xpath.evaluate(n2); // return if null if (val1 == null || val2 == null) { return val1 == null ? (val2 == null ? 1 : -1) : 1; } Comparable c1 = getComparableValue(val1); Comparable c2 = getComparableValue(val2); // compare descending or ascending if (!descending) { return c1.compareTo(c2); } else { return c2.compareTo(c1); } } catch (JaxenException e) { throw new XPathSortException("error sorting nodes", e); } }
public int compare(Node n1, Node n2) { try { // apply the xpaths. not using stringValueOf since I don't // want all of the child nodes appended to the strings Object val1 = xpath.evaluate(n1); Object val2 = xpath.evaluate(n2); // return if null if (val1 == null || val2 == null) { return val1 == null ? (val2 == null ? 1 : -1) : 1; } Comparable c1 = getComparableValue(val1); Comparable c2 = getComparableValue(val2); // compare descending or ascending if (!descending) { return c1.compareTo(c2); } else { return c2.compareTo(c1); } } catch (JaxenException e) { throw new XPathSortException("error sorting nodes", e); } }
public int compare(Node n1, Node n2) { try { // apply the xpaths. not using stringValueOf since I don't // want all of the child nodes appended to the strings Object val1 = xpath.evaluate(n1); Object val2 = xpath.evaluate(n2); // return if null if (val1 == null || val2 == null) { return val1 == null ? (val2 == null ? 1 : -1) : 1; } Comparable c1 = getComparableValue(val1); Comparable c2 = getComparableValue(val2); // compare descending or ascending if (!descending) { return c1.compareTo(c2); } else { return c2.compareTo(c1); } } catch (JaxenException e) { throw new XPathSortException("error sorting nodes", e); } }
Object object = xpath.evaluate(contextNode); Object value; if (object instanceof List)
public NodeList selectNodeList(Node contextNode, String expression) throws JRException { try { XPath xpath = getXPath(expression); Object object = xpath.evaluate(contextNode); List nodes; if (object instanceof List) { nodes = (List) object; } else { nodes = new ArrayList(); nodes.add(object); } return new NodeListWrapper(nodes); } catch (JaxenException e) { throw new JRException("XPath selection failed. Expression: " + expression, e); } }
public Object evaluate(String path, Base base, Map<String, String> namespaces, Map<QName, Function> functions, Map<QName, Object> variables) throws XPathException { try { base = getElementWrapped(base); XPath xpath = getXPath(path, namespaces, functions, variables); return xpath.evaluate(base); } catch (JaxenException e) { throw new XPathException(e); } }