Uploaded image for project: 'Suggestion Box'
  1. Suggestion Box
  2. SUGGEST-159

NodeUtil should include a function for redordering nodes alphabetically

    XMLWordPrintable

    Details

    • Type: Improvement
    • Status: Accepted
    • Priority: Neutral
    • Resolution: Unresolved
    • Labels:
      None

      Description

      Here is an example of a snippet I use frequently:

      public static void sort(Node node) {
              boolean outOfOrder = true;
              NodeIterator iterator = null;
              Node previous = null;
              Node current = null;
              
              try {
                  while (outOfOrder) {
                      outOfOrder = false;
                      iterator = node.getNodes();
      
                      if (iterator.hasNext()) 
                          previous = iterator.nextNode();
      
                      while (iterator.hasNext()) {
                          current = iterator.nextNode();
      
                          if (current.getName().compareToIgnoreCase(previous.getName()) < 0) {
                              node.orderBefore(current.getName(), previous.getName());
                              outOfOrder = true; 
                          }
      
                          previous = current;
                      }
                  }
              } catch (RepositoryException e) {
                  log.error(e.getMessage(), e);
              }
       }
      

      I think it would be helpful to have some trace for start sort and end sort because large sets could takes a couple of minutes to sort.

        Attachments

          Activity

            People

            Assignee:
            Unassigned Unassigned
            Reporter:
            rgange Richard Gange
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Dates

              Created:
              Updated:
              Date of First Response: