code: public static Resource getResource(Object adaptable) {
      if (adaptable instanceof Resource) {
        return (Resource)adaptable;
      }
      else if (adaptable instanceof SlingHttpServletRequest) {
        SlingHttpServletRequest request = (SlingHttpServletRequest)adaptable;
        return request.getResource();
      }
      return null;
    }
docs: Tries to get the resource associated with the adaptable.
  @param adaptable Adaptable
  @return Resource or null