private @Nullable String fetchOneFile(final ProgressIndicator indicator,
                                        final String resourceUrl,
                                        final Project project,
                                        String extResourcesPath,
                                        @Nullable String refname) throws IOException {
    SwingUtilities.invokeLater(
      () -> indicator.setText(XmlBundle.message("xml.intention.fetch.progress.fetching", resourceUrl))
    );

    FetchResult result = fetchData(project, resourceUrl, indicator);
    if (result == null) return null;

    if(!resultIsValid(project, indicator, resourceUrl, result)) {
      return null;
    }

    String resPath = extResourcesPath + File.separatorChar;

    if (refname != null) { // resource is known under ref.name so need to save it
      resPath += refname;
      int refNameSlashIndex = resPath.lastIndexOf('/');
      if (refNameSlashIndex != -1) {
        checkExists(resPath.substring(0, refNameSlashIndex));
      }
    }
    else {
      int slashIndex = resourceUrl.lastIndexOf('/');
      resPath += Integer.toHexString(resourceUrl.hashCode()) + "_" + resourceUrl.substring(slashIndex + 1);
    }

    int lastDoPosInResourceUrl = resourceUrl.lastIndexOf('.');
    if (lastDoPosInResourceUrl == -1 ||
        FileTypeManager.getInstance().getFileTypeByExtension(resourceUrl.substring(lastDoPosInResourceUrl + 1)) == FileTypes.UNKNOWN) {
      // remote url does not contain file with extension
      final String extension =
        result.contentType != null &&
        result.contentType.contains(HTML_MIME) ? HtmlFileType.INSTANCE.getDefaultExtension() : XmlFileType.INSTANCE.getDefaultExtension();
      resPath += "." + extension;
    }

    File res = new File(resPath);

    FileUtil.writeToFile(res, result.bytes);
    return resPath;
  }
private @Nullable String fetchOneFile(final ProgressIndicator indicator,
                                        final String resourceUrl,
                                        final Project project,
                                        String extResourcesPath,
                                        @Nullable String refname)