code: protected UrlConfig getUrlConfigForTarget(Adaptable adaptable, Resource targetResource) {
      UrlConfig config = null;
      if (targetResource != null) {
        config = new UrlConfig(targetResource);
      }
      if (config == null || !config.isValid()) {
        config = new UrlConfig(adaptable);
      }
      return config;
    }
docs: Get URL configuration for target resource. If this is invalid or not available, get it from adaptable.
  @param adaptable Adaptable (request or resource)
  @param targetResource Target resource (may be null)
  @return Url config (never null)