@Override
  public @Nullable XMLInputSource resolveEntity(XMLResourceIdentifier xmlResourceIdentifier) throws XNIException {
    String publicId  = xmlResourceIdentifier.getLiteralSystemId() != null ?
                  xmlResourceIdentifier.getLiteralSystemId():
                  xmlResourceIdentifier.getNamespace();

    if (publicId != null && publicId.startsWith("file:")) {
      Path basePath = new File(URI.create(xmlResourceIdentifier.getBaseSystemId())).getParentFile().toPath();
      try {
        Path publicIdPath = new File(URI.create(publicId)).toPath();
        publicId = basePath.relativize(publicIdPath).toString().replace(File.separatorChar, '/');
      }
      catch (Exception ignore) {
      }
    }
    PsiFile psiFile = resolve(xmlResourceIdentifier.getBaseSystemId(), publicId);
    if (psiFile==null && xmlResourceIdentifier.getLiteralSystemId()!=null && xmlResourceIdentifier.getNamespace()!=null) {
      psiFile = resolve(
        xmlResourceIdentifier.getBaseSystemId(),
        publicId = xmlResourceIdentifier.getNamespace()
      );
    }

    if (psiFile == null) {
      if (publicId != null && publicId.contains(":/")) {
        return reportUnresolvedUrl(xmlResourceIdentifier, publicId, "");
      }
      String expandedSystemId = xmlResourceIdentifier.getExpandedSystemId();
      if (expandedSystemId != null && isHttpUrl(expandedSystemId)) {
        return reportUnresolvedUrl(xmlResourceIdentifier, publicId, "unresolved");
      }
      return null;
    }

    XMLInputSource source = new XMLInputSource(xmlResourceIdentifier);
    if (xmlResourceIdentifier.getLiteralSystemId() == null) {
      VirtualFile virtualFile = psiFile.getVirtualFile();
      if (virtualFile != null) {
        final String url = VfsUtilCore.fixIDEAUrl(virtualFile.getUrl());
        source.setBaseSystemId(url);
        source.setSystemId(url);
      }
    }
    source.setPublicId(publicId);
    source.setBaseSystemId(null);
    source.setCharacterStream(new StringReader(psiFile.getText()));

    return source;
  }
@Override
  public @Nullable XMLInputSource resolveEntity(XMLResourceIdentifier xmlResourceIdentifier)