/** Sets the xpath expression to use to sort selected nodes. */ public void setSort(XPath sortXPath) throws XPathException { if (xpCmp == null) xpCmp = new XPathComparator(); xpCmp.setXpath(sortXPath); }
/** * Set whether to sort ascending or descending. */ public void setDescending(boolean descending) { if (xpCmp == null) xpCmp = new XPathComparator(); xpCmp.setDescending(descending); } }
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 void doTag(XMLOutput output) throws JellyTagException { if (select != null) { List nodes = null; try { nodes = select.selectNodes( getXPathContext() ); } catch (XPathException e) { throw new JellyTagException(e); } // sort the list if xpCmp is set. if (xpCmp != null && (xpCmp.getXpath() != null)) { Collections.sort(nodes, xpCmp); } Iterator iter = nodes.iterator(); while (iter.hasNext()) { iterationValue = iter.next(); if (var != null) { context.setVariable(var, iterationValue); } invokeBody(output); } } }
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 (XPathException e) { throw new XPathSortException("error sorting nodes", e); } }
List list = (List) value; if (xpCmp != null && (xpCmp.getXpath() != null)) { Collections.sort(list, xpCmp);
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); } }
/** Sets the xpath expression to use to sort selected nodes. */ public void setSort(XPath sortXPath) throws XPathException { if (xpCmp == null) xpCmp = new XPathComparator(); xpCmp.setXpath(sortXPath); }
/** * Set whether to sort ascending or descending. */ public void setDescending(boolean descending) { if (xpCmp == null) xpCmp = new XPathComparator(); xpCmp.setDescending(descending); } }
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); } }
/** Sets the xpath expression to use to sort selected nodes. * Ignored if single is true. */ public void setSort(XPath sortXPath) throws XPathException { if (xpCmp == null) xpCmp = new XPathComparator(); xpCmp.setXpath(sortXPath); }
/** * Set whether to sort ascending or descending. */ public void setDescending(boolean descending) { if (xpCmp == null) xpCmp = new XPathComparator(); xpCmp.setDescending(descending); }