code: private static List<Resource> getAncestors(Resource currentResource, Resource rootResource) {
      List<Resource> results = new ArrayList<Resource>();
  
      if (currentResource == null || rootResource == null || StringUtils.equals(currentResource.getPath(), rootResource.getPath())) {
        return results;
      }
  
      Resource parent = currentResource.getParent();
      while (parent != null) {
        results.add(0, parent);
        if (parent.getPath().equals(rootResource.getPath())) {
          break;
        }
        parent = parent.getParent();
      }
      return results;
    }
docs: Returns the ancestors of the current resource (inclusive) up to the root.
  The result is ordered with the root as the first item.