code: public static List<CmsCategoryTreeEntry> buildCategoryTree(CmsObject cms, List<CmsCategory> categories) {
  
          List<CmsCategoryTreeEntry> result = new ArrayList<CmsCategoryTreeEntry>();
          for (CmsCategory category : categories) {
              CmsCategoryTreeEntry current = new CmsCategoryTreeEntry(category);
              current.setSitePath(cms.getRequestContext().removeSiteRoot(category.getRootPath()));
              String parentPath = CmsResource.getParentFolder(current.getPath());
              CmsCategoryTreeEntry parent = null;
              parent = findCategory(result, parentPath);
              if (parent != null) {
                  parent.addChild(current);
              } else {
                  result.add(current);
              }
          }
          return result;
      }
docs: Builds the tree structure for the given categories.<p>
  
  @param cms the current cms context
  @param categories the categories
  
  @return the tree root element