code: public String getRootPath(Resource resource) {
      int rootLevel = urlHandlerConfig.getSiteRootLevel(resource);
      if (rootLevel > 0) {
        return Path.getAbsoluteParent(resource.getPath(), rootLevel, resource.getResourceResolver());
      }
      return null;
    }
docs: Gets site root level path of a site.
  @param resource Resource within the site
  @return Site root path for the site. The path is not checked for validness.