1 56 57 package org.jdom.contrib.helpers; 58 59 import org.jdom.*; 60 import java.util.*; 61 62 67 public class JDOMHelper { 68 91 public static void sortElements(Element parent, Comparator c) { 92 List children = new ArrayList(parent.getChildren()); 94 Collections.sort(children, c); 95 ListIterator childrenIter = children.listIterator(); 96 97 List content = new ArrayList(parent.getContent()); 99 ListIterator contentIter = content.listIterator(); 100 101 while(contentIter.hasNext()) { 106 Object obj = contentIter.next(); 107 if (obj instanceof Element) 108 contentIter.set(childrenIter.next()); 109 } 110 111 parent.setContent((List)null); 113 parent.setContent(content); 114 } 115 } | Popular Tags |