code: public ResourceHandle findUpwards(String basePath, Pattern namePattern, String childType) {
          ResourceHandle current = this;
          while (current != null && current.isValid()) {
              ResourceHandle base = ResourceHandle.use(current.getChild(basePath));
              if (base.isValid()) {
                  for (ResourceHandle child : base.getChildrenByType(childType)) {
                      if (namePattern.matcher(child.getName()).matches()) {
                          return child;
                      }
                  }
              }
              current = current.getParent();
          }
          return null;
      }
docs: Retrieves a child of this resource or a parent specified by its base path, name pattern and type; for example
  findUpwards("jcr:content", Pattern.compile("^some.*$"), "sling:Folder").