/**
* {@linkplain ResourceStorage Resource storage} for local,
* that is, client-side/browser-side, resources.
*/
export class LocalFiles extends ResourceStorage {
/**
* Constructs a client-side/browser-side resource storage for use
* by specified XML Editor.
*/
constructor(xmlEditor) {
super(xmlEditor);
}
/**
* <strong>Operation not supported:</strong>
* simply returns a new {@link LocalFile} having specified URI,
* <code>null</code> data and <code>null</code> file handle.
*/
loadResource(uri) {
if (!uri.startsWith("file:/")) {
return Promise.resolve(null);
} else {
return Promise.resolve(new LocalFile(uri, null, null));
}
}
/**
* <strong>Operation not supported:</strong>
* simply returns a new {@link LocalFile} having specified URI,
* specified data and corresponding file handle (if any).
*/
storeResource(data, uri) {
if (!uri.startsWith("file:/")) {
return Promise.resolve(null);
} else {
return Promise.resolve(new LocalFile(uri, data, data.handle));
}
}
openResource(options) {
return LocalFileDialog.showDialog(this._xmlEditor, options)
.then((choice) => {
if (choice === null) {
// Canceled by user.
return null;
} else {
return new LocalFile(choice.uri, choice.file,
choice.file.handle);
}
});
}
}