Hi

Thanks Alex. I played a littel bit with an comparator. The result is the same, but I'm not so familiar with this.

public class CaseInsensitiveComparator
  implements java.util.Comparator {
    public int compare(Object o1, Object o2) {
      String s1 = o1.toString().toUpperCase().trim();
      String s2 = o2.toString().toUpperCase().trim();
      return s1.compareTo(s2);
    }
}

private void sortMyChildren(Collection myChildren, JspWriter out) throws IOException, RepositoryException {
        
  //Array for the sorted children
  ArrayList childrenArrayList = new ArrayList();
  childrenArrayList.add("dd");
  childrenArrayList.add("cc");
  childrenArrayList.add("aa");
  childrenArrayList.add("bb");

  //
  //Iterate through children an get the nodeData
for (Iterator myChildrenIterator = myChildren.iterator(); myChildrenIterator.hasNext();) {
                
    //
    //go throug the paragraph
    Content para = (Content)myChildrenIterator.next();
    //
    //Get the nodeData
    Iterator paraNodes = para.getChildren().iterator();
    Content nodes = (Content)paraNodes.next();

    String node4sort = nodes.getNodeData("region").getString();

    //Fill the ArrayList
    childrenArrayList.add(node4sort);
  }

  //
  //now sort the array
  Collections.sort(childrenArrayList, new CaseInsensitiveComparator());
  int size = childrenArrayList.size();
  for (int i=0; i<size; i++) {
    out.println(childrenArrayList.get(i) + "<br />");
  }
}



The Strings "aa","bb","cc" and "dd" are sorted, but the strings I get from Node (node4sort) are in the original order.

When I test the comparator with the code below it works perfect
        
Object[] data = {"Aubergine","banana","aubergine","Banana"};
List list = Arrays.asList(data);
Collections.sort(list, new CaseInsensitiveComparator());
out.println(list);

Browsing the internet everywhere is written that the collections.sort() function fits perfect for strings like "myString" (case-sensitive).

So I'm asking me, if getNodeData("someNode").getString() doesn't return a "normal" string, even when there are NodeDatas like "Umbrien","Toscana" etc.

Hmmm. Somewhere is the solution
Christoph

----------------------------------------------------------------
for list details see
http://www.magnolia.info/en/magnolia/developer.html
----------------------------------------------------------------

Reply via email to