code: private boolean linksToOtherDomain(Adaptable adaptable, Page currentPage, Resource targetResource) {
      if (currentPage == null || targetResource == null) {
        return false;
      }
  
      UrlHandlerConfig urlHandlerConfig = AdaptTo.notNull(adaptable, UrlHandlerConfig.class);
      Resource currentResource = AdaptTo.notNull(currentPage, Resource.class);
      ResourceResolver resourceResolver = currentResource.getResourceResolver();
      String currentSiteRoot = getRootPath(currentPage.getPath(), urlHandlerConfig.getSiteRootLevel(currentResource), resourceResolver);
      String pathSiteRoot = getRootPath(targetResource.getPath(), urlHandlerConfig.getSiteRootLevel(targetResource), resourceResolver);
      boolean notInCurrentSite = !StringUtils.equals(currentSiteRoot, pathSiteRoot);
  
      if (notInCurrentSite) {
        UrlConfig targetUrlConfig = new UrlConfig(targetResource);
        return targetUrlConfig.isValid();
      }
      else {
        return false;
      }
    }
docs: Checks if the target resource is located outsite the current site, and if for this other
  resource context a valid url configuration with a specific hostname exists.
  @param adaptable Adaptable
  @param currentPage Current page (may be null)
  @param targetResource Target resource (may be null)
  @return true if the target resources is located in another site/context with separate url configuration