WEB-34093 JSON Schema: improve the status for not yet downloaded schemas

+ fix rewriting urls when file extension is already provided
This commit is contained in:
Anton Lobov
2018-07-27 12:49:15 +02:00
parent 959594afb0
commit acfedcab64
2 changed files with 24 additions and 17 deletions
@@ -40,7 +40,8 @@ public class JsonFileResolver {
return JsonSchemaCatalogManager.DEFAULT_CATALOG_HTTPS;
}
if (StringUtil.startsWithIgnoreCase(urlString, JsonSchemaRemoteContentProvider.STORE_URL_PREFIX_HTTP)) {
return StringUtil.replace(urlString, "http://json.schemastore.org/", "https://schemastore.azurewebsites.net/schemas/json/") + ".json";
String newUrl = StringUtil.replace(urlString, "http://json.schemastore.org/", "https://schemastore.azurewebsites.net/schemas/json/");
return newUrl.endsWith(".json") ? newUrl : newUrl + ".json";
}
return urlString;
}
@@ -126,23 +126,10 @@ class JsonSchemaStatusWidget extends EditorBasedStatusBarPopup {
//noinspection EnumSwitchStatementWhichMissesCases
switch (info.getState()) {
case DOWNLOADING_NOT_STARTED:
addDownloadingUpdateListener(info);
return getNoSchemaState();
case DOWNLOADING_IN_PROGRESS:
info.addDownloadingListener(new FileDownloadingAdapter() {
@Override
public void fileDownloaded(VirtualFile localFile) {
update();
}
@Override
public void errorOccurred(@NotNull String errorMessage) {
update();
}
@Override
public void downloadingCancelled() {
update();
}
});
addDownloadingUpdateListener(info);
return new MyWidgetState("Download is scheduled or in progress", "Downloading JSON schema", false);
case ERROR_OCCURRED:
return getDownloadErrorState(info.getErrorMessage());
@@ -171,6 +158,25 @@ class JsonSchemaStatusWidget extends EditorBasedStatusBarPopup {
true);
}
private void addDownloadingUpdateListener(@NotNull RemoteFileInfo info) {
info.addDownloadingListener(new FileDownloadingAdapter() {
@Override
public void fileDownloaded(VirtualFile localFile) {
update();
}
@Override
public void errorOccurred(@NotNull String errorMessage) {
update();
}
@Override
public void downloadingCancelled() {
update();
}
});
}
private boolean isValidSchemaFile(VirtualFile schemaFile) {
if (schemaFile == null || !myService.isApplicableToFile(schemaFile) || !myService.isSchemaFile(schemaFile)) return false;
FileType type = schemaFile.getFileType();