|
@@ -1,29 +1,37 @@
|
|
|
import { IXmlElement } from "./Xml";
|
|
|
+import { Promise } from "es6-promise";
|
|
|
import JSZip = require("jszip");
|
|
|
|
|
|
-export function extractSheetFromMxl(data: string, onFullfilled: any, onRejected: any): void {
|
|
|
+export function extractSheetFromMxl(data: string): Promise<any> {
|
|
|
"use strict";
|
|
|
+ // _zip_ must be of type 'any' for now, since typings for JSZip are not up-to-date
|
|
|
let zip: any = new JSZip();
|
|
|
- zip.loadAsync(data).then(
|
|
|
+ // asynchronously load zip file and process it - with Promises
|
|
|
+ return zip.loadAsync(data).then(
|
|
|
(_: any) => {
|
|
|
return zip.file("META-INF/container.xml").async("string");
|
|
|
},
|
|
|
- onRejected
|
|
|
+ (err: any) => {
|
|
|
+ throw err;
|
|
|
+ }
|
|
|
).then(
|
|
|
(content: string) => {
|
|
|
let parser: DOMParser = new DOMParser();
|
|
|
let doc: Document = parser.parseFromString(content, "text/xml");
|
|
|
- // doc.Root.Element("rootfiles").Element("rootfile").Attribute("full-path").Value;
|
|
|
let rootFile: string = doc.getElementsByTagName("rootfile")[0].getAttribute("full-path");
|
|
|
return zip.file(rootFile).async("string");
|
|
|
},
|
|
|
- onRejected
|
|
|
+ (err: any) => {
|
|
|
+ throw err;
|
|
|
+ }
|
|
|
).then(
|
|
|
(content: string) => {
|
|
|
let parser: DOMParser = new DOMParser();
|
|
|
let doc: Document = parser.parseFromString(content, "text/xml");
|
|
|
- onFullfilled(new IXmlElement(doc.documentElement));
|
|
|
+ return Promise.resolve(new IXmlElement(doc.documentElement));
|
|
|
},
|
|
|
- onRejected
|
|
|
+ (err: any) => {
|
|
|
+ throw err;
|
|
|
+ }
|
|
|
);
|
|
|
}
|