-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a19d2ea
commit fbed54e
Showing
3 changed files
with
72 additions
and
5 deletions.
There are no files selected for viewing
41 changes: 41 additions & 0 deletions
41
.../main/java/edu/stanford/bmir/protege/web/client/download/FetchAndOpenInBrowserWindow.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package edu.stanford.bmir.protege.web.client.download; | ||
|
||
import javax.annotation.Nonnull; | ||
|
||
/** | ||
* Matthew Horridge | ||
* Stanford Center for Biomedical Informatics Research | ||
* 2024-06-14 | ||
*/ | ||
public class FetchAndOpenInBrowserWindow { | ||
|
||
/** | ||
* GET the specified path and open the result as a blob in a new window | ||
* @param path The path | ||
* @param token The access token to use. This will be set in the authorization header. | ||
*/ | ||
public static native void fetchUrlAndOpenInWindow(@Nonnull String path, | ||
@Nonnull String token, | ||
@Nonnull FetchAndOpenInBrowserWindowErrorHandler errorHandler)/*-{ | ||
var xhr = new XMLHttpRequest(); | ||
xhr.open('GET', path); | ||
xhr.onreadystatechange = handler; | ||
xhr.responseType = 'blob'; | ||
xhr.setRequestHeader('Authorization', 'Bearer ' + token); | ||
xhr.send(); | ||
function handler() { | ||
if (this.readyState === this.DONE) { | ||
if (this.status === 200) { | ||
// this.response is a Blob, because we set responseType above | ||
var data_url = URL.createObjectURL(this.response); | ||
$wnd.open(data_url, '_blank'); | ||
} else { | ||
console.error('Error'); | ||
errorHandler.@edu.stanford.bmir.protege.web.client.download.FetchAndOpenInBrowserWindowErrorHandler::handleError(*)(); | ||
} | ||
} | ||
} | ||
}-*/; | ||
} |
11 changes: 11 additions & 0 deletions
11
...du/stanford/bmir/protege/web/client/download/FetchAndOpenInBrowserWindowErrorHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package edu.stanford.bmir.protege.web.client.download; | ||
|
||
/** | ||
* Matthew Horridge | ||
* Stanford Center for Biomedical Informatics Research | ||
* 2024-06-14 | ||
*/ | ||
public interface FetchAndOpenInBrowserWindowErrorHandler { | ||
|
||
void handleError(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters