| 81 |
81 |
/*** the jobs / tests ***/
|
| 82 |
82 |
|
| 83 |
83 |
function ParseXMLJob() {
|
| 84 |
|
// this.inputpattern = { date: "", filename: "", data: "", error: "" };
|
| 85 |
|
// this.outputpattern = { dom: null, errors: { parseXmlErrors: [] } };
|
| 86 |
84 |
this.inputpattern = { file: { entries: [] } };
|
| 87 |
85 |
this.outputpattern = {
|
| 88 |
86 |
file: { entries: [] },
|
| ... | ... | |
| 423 |
421 |
icon.style.marginRight = icon.style.marginBottom = "10px";
|
| 424 |
422 |
addParagraph(div, "mimetype: " + data.mimetype);
|
| 425 |
423 |
addParagraph(div, "version: " + data.version);
|
|
424 |
addParagraph(div, "document representation: " +
|
|
425 |
((data.file.dom) ? "single XML document" :"package"));
|
| 426 |
426 |
addErrors(div, data, false);
|
| 427 |
427 |
}
|
| 428 |
428 |
function dorender(data) {
|
| ... | ... | |
| 516 |
516 |
}
|
| 517 |
517 |
};
|
| 518 |
518 |
}
|
| 519 |
|
|
| 520 |
|
function ODFFile(file, path) {
|
| 521 |
|
var odffile = this,
|
| 522 |
|
zipentries,
|
| 523 |
|
files = {},
|
| 524 |
|
data,
|
| 525 |
|
dom;
|
| 526 |
|
function loadZipEntries(position, callback) {
|
| 527 |
|
if (position >= zipentries.length) {
|
| 528 |
|
if (callback) {
|
| 529 |
|
callback(odffile);
|
| 530 |
|
}
|
| 531 |
|
return;
|
| 532 |
|
}
|
| 533 |
|
var e = zipentries[position];
|
| 534 |
|
files[e.filename] = e;
|
| 535 |
|
e.load(function (error, data) {
|
| 536 |
|
e.error = error;
|
| 537 |
|
e.data = data;
|
| 538 |
|
loadZipEntries(position + 1, callback);
|
| 539 |
|
});
|
| 540 |
|
}
|
| 541 |
|
function loadZip(callback) {
|
| 542 |
|
var zip = new core.Zip(path, function (err, zip) {
|
| 543 |
|
if (err) {
|
| 544 |
|
error = err;
|
| 545 |
|
} else {
|
| 546 |
|
zipentries = zip.getEntries();
|
| 547 |
|
loadZipEntries(0, callback);
|
| 548 |
|
}
|
| 549 |
|
});
|
| 550 |
|
}
|
| 551 |
|
function loadXml(callback) {
|
| 552 |
|
}
|
| 553 |
|
function init() {
|
| 554 |
|
runtime.read(path, 0, file.size, function (err, data) {
|
| 555 |
|
if (err) {
|
| 556 |
|
error = err;
|
| 557 |
|
return;
|
| 558 |
|
}
|
| 559 |
|
// is this file a zip file?
|
| 560 |
|
if (data[0] === 80) {
|
| 561 |
|
loadZip();
|
| 562 |
|
} else {
|
| 563 |
|
loadXml();
|
| 564 |
|
}
|
| 565 |
|
});
|
| 566 |
|
}
|
| 567 |
|
init();
|
| 568 |
|
}
|
| 569 |
|
function FileDiagnose(element, file, path) {
|
| 570 |
|
var doc = element.ownerDocument,
|
| 571 |
|
icon = doc.createElement("img"),
|
| 572 |
|
base64 = new core.Base64(),
|
| 573 |
|
zipentries,
|
| 574 |
|
files = {},
|
| 575 |
|
data,
|
| 576 |
|
error;
|
| 577 |
|
ODFFile(file, path);
|
| 578 |
|
function analyze(error, data) {
|
| 579 |
|
if (error) {
|
| 580 |
|
addParagraph(error);
|
| 581 |
|
return;
|
| 582 |
|
}
|
| 583 |
|
var mimetype = data.slice(30, 77);
|
| 584 |
|
addParagraph(mimetype);
|
| 585 |
|
}
|
| 586 |
|
function addParagraph(text) {
|
| 587 |
|
var p = doc.createElement("p");
|
| 588 |
|
p.appendChild(doc.createTextNode(text));
|
| 589 |
|
element.appendChild(p);
|
| 590 |
|
}
|
| 591 |
|
function addSpan(parent, nodename, text) {
|
| 592 |
|
var e = doc.createElement(nodename);
|
| 593 |
|
e.appendChild(doc.createTextNode(text));
|
| 594 |
|
parent.appendChild(e);
|
| 595 |
|
}
|
| 596 |
|
function addText(parent, text) {
|
| 597 |
|
parent.appendChild(doc.createTextNode(text));
|
| 598 |
|
}
|
| 599 |
|
function init() {
|
| 600 |
|
icon.style.width = "128px";
|
| 601 |
|
icon.style.float = "left";
|
| 602 |
|
icon.style.mozBoxShadow = icon.style.webkitBoxShadow = icon.style.boxShadow = "3px 3px 4px #000";
|
| 603 |
|
icon.style.marginRight = icon.style.marginBottom = "10px";
|
| 604 |
|
var iconsrc = "", p;
|
| 605 |
|
if (file.type === "application/vnd.oasis.opendocument.text") {
|
| 606 |
|
iconsrc = "application-vnd.oasis.opendocument.text.png";
|
| 607 |
|
} else if (file.type === "application/vnd.oasis.opendocument.spreadsheet") {
|
| 608 |
|
iconsrc = "application-vnd.oasis.opendocument.spreadsheet.png";
|
| 609 |
|
} else if (file.type === "application/vnd.oasis.opendocument.presentation") {
|
| 610 |
|
iconsrc = "application-vnd.oasis.opendocument.presentation.png";
|
| 611 |
|
}
|
| 612 |
|
icon.setAttribute("src", iconsrc);
|
| 613 |
|
element.appendChild(icon);
|
| 614 |
|
|
| 615 |
|
p = doc.createElement("p");
|
| 616 |
|
element.appendChild(p);
|
| 617 |
|
addText(p, "name: ");
|
| 618 |
|
addSpan(p, "strong", file.name);
|
| 619 |
|
addText(p, " type: ");
|
| 620 |
|
addSpan(p, "strong", file.type);
|
| 621 |
|
addText(p, " size: ");
|
| 622 |
|
addSpan(p, "strong", file.size);
|
| 623 |
|
addText(p, " bytes");
|
| 624 |
|
}
|
| 625 |
|
this.setData = function (error_, data_) {
|
| 626 |
|
data = data_;
|
| 627 |
|
error = error_;
|
| 628 |
|
analyze(error, data);
|
| 629 |
|
if (error) {
|
| 630 |
|
addParagraph("Error: " + error + " " + string(data.length));
|
| 631 |
|
}
|
| 632 |
|
};
|
| 633 |
|
function addThumbnail() {
|
| 634 |
|
var src;
|
| 635 |
|
zipentry = files["Thumbnails/thumbnail.png"];
|
| 636 |
|
if (zipentry) {
|
| 637 |
|
zipentry.load(function (error, data) {
|
| 638 |
|
if (!src) {
|
| 639 |
|
src = "data:image/png;base64," +
|
| 640 |
|
base64.convertUTF8ArrayToBase64(data);
|
| 641 |
|
icon.setAttribute("src", src);
|
| 642 |
|
}
|
| 643 |
|
});
|
| 644 |
|
}
|
| 645 |
|
}
|
| 646 |
|
function loadZipEntries(position) {
|
| 647 |
|
if (position >= zipentries.length) {
|
| 648 |
|
return;
|
| 649 |
|
}
|
| 650 |
|
var e = zipentries[position];
|
| 651 |
|
files[e.filename] = e;
|
| 652 |
|
e.load(function (error, data) {
|
| 653 |
|
e.error = error;
|
| 654 |
|
e.data = data;
|
| 655 |
|
loadZipEntries(position + 1);
|
| 656 |
|
});
|
| 657 |
|
}
|
| 658 |
|
function analyzeZip() {
|
| 659 |
|
var zip = new core.Zip(path, function (err, zip) {
|
| 660 |
|
var i, thumbnail;
|
| 661 |
|
if (err) {
|
| 662 |
|
addParagraph("Error: " + err);
|
| 663 |
|
} else {
|
| 664 |
|
zipentries = zip.getEntries();
|
| 665 |
|
loadZipEntries(0);
|
| 666 |
|
for (i = 0; i < zipentries.length; ++i) {
|
| 667 |
|
addParagraph(zipentries[i].filename);
|
| 668 |
|
}
|
| 669 |
|
addThumbnail();
|
| 670 |
|
}
|
| 671 |
|
});
|
| 672 |
|
}
|
| 673 |
|
init();
|
| 674 |
|
analyzeZip();
|
| 675 |
|
}
|
| 676 |
519 |
function LoadingFile(file) {
|
| 677 |
520 |
var data,
|
| 678 |
521 |
error,
|
| ... | ... | |
| 731 |
574 |
// cancel event and hover styling
|
| 732 |
575 |
dragHandler(evt);
|
| 733 |
576 |
|
| 734 |
|
function diagnoseFile(div, file) {
|
| 735 |
|
var diagnose, loadingfile, path;
|
|
577 |
function diagnoseFile(file) {
|
|
578 |
var loadingfile, path;
|
| 736 |
579 |
path = file.name;
|
| 737 |
580 |
loadingfile = new LoadingFile(file);
|
| 738 |
581 |
openedFiles[path] = loadingfile;
|
| 739 |
|
diagnose = new FileDiagnose(div, file, path);
|
| 740 |
582 |
loadingfile.load(function (error, data) {
|
| 741 |
|
diagnose.setData(error, data);
|
| 742 |
583 |
jobrunnerdata.push({file:{
|
| 743 |
584 |
path: path,
|
| 744 |
585 |
data: data
|
| ... | ... | |
| 752 |
593 |
for (i = 0; i < files.length; ++i) {
|
| 753 |
594 |
div = doc.createElement("div");
|
| 754 |
595 |
diagnoses.appendChild(div);
|
| 755 |
|
diagnoseFile(div, files[i]);
|
|
596 |
diagnoseFile(files[i]);
|
| 756 |
597 |
}
|
| 757 |
598 |
}
|
| 758 |
599 |
|