code: public List<CmsCategory> readCategoriesForRepositories(
          CmsObject cms,
          String parentCategoryPath,
          boolean includeSubCats,
          List<String> repositories,
          boolean includeRepositories)
      throws CmsException {
  
          String catPath = parentCategoryPath;
          if (catPath == null) {
              catPath = "";
          }
  
          Collection<CmsCategory> cats = includeRepositories ? new ArrayList<CmsCategory>() : new HashSet<CmsCategory>();
  
          // traverse in reverse order, to ensure the set will contain most global categories
          Iterator<String> it = repositories.iterator();
          while (it.hasNext()) {
              String repository = it.next();
              try {
                  if (includeRepositories) {
                      CmsCategory repo = getCategory(cms, cms.readResource(repository));
                      cats.add(repo);
                  }
                  cats.addAll(
                      internalReadSubCategories(cms, internalCategoryRootPath(repository, catPath), includeSubCats));
              } catch (CmsVfsResourceNotFoundException e) {
                  // it may be that the given category is not defined in this repository
                  // just ignore
              }
          }
          List<CmsCategory> ret = new ArrayList<CmsCategory>(cats);
          if (!includeRepositories) {
              Collections.sort(ret);
          }
          return ret;
      }
docs: Returns all categories given some search parameters.<p>
  
  @param cms the current cms context
  @param parentCategoryPath the path of the parent category to get the categories for
  @param includeSubCats if to include all categories, or first level child categories only
  @param repositories a list of site paths
  @param includeRepositories flag, indicating if the repositories itself should be returned as category.
  @return a list of {@link CmsCategory} objects
  @throws CmsException  if something goes wrong