code: private List<CmsGalleryTreeEntry> galleryListToTree(List<CmsGalleryFolderBean> galleries) {
  
          List<CmsGalleryTreeEntry> result = new ArrayList<CmsGalleryTreeEntry>();
          Collections.sort(galleries, new CmsComparatorPath(true));
          CmsGalleryTreeEntry previous = null;
          for (CmsGalleryFolderBean folderBean : galleries) {
              CmsGalleryTreeEntry current = new CmsGalleryTreeEntry(folderBean);
              CmsGalleryTreeEntry parent = null;
              if (previous != null) {
                  parent = lookForParent(previous, current.getPath());
              }
              if (parent != null) {
                  parent.addChild(current);
              } else {
                  result.add(current);
              }
              previous = current;
          }
          return result;
      }
docs: Creates a tree structure from the given gallery folder list.<p>
  The tree may have several entries at root level.<p>
  
  @param galleries the gallery folder list
  
  @return the list of tree entries