Merge pull request #642 from aurimasv/wpd-regression

Fix snapshots
This commit is contained in:
Dan Stillman 2015-02-21 21:45:59 -05:00
commit 867784b157
2 changed files with 31 additions and 23 deletions

View file

@ -310,8 +310,10 @@ var wpdCommon = {
},
// add a line to the error list (displays a maximum of 15 errors)
addError: function (aError) {
Zotero.debug('ERROR: ' + aError);
addError: function (errorMsg, errorObj) {
if (errorMsg) Zotero.debug(errorMsg);
if (errorObj) Zotero.debug(errorObj);
/*
if (this.errCount < WPD_MAXUIERRORCOUNT) {
if (this.errList.indexOf(aError) > -1) return; // is the same
this.errList = this.errList + aError + "\n";
@ -319,6 +321,7 @@ var wpdCommon = {
this.errList = this.errList + '...';
}
this.errCount++;
*/
},
saveWebPage: function (aDestFile) {
@ -505,7 +508,7 @@ var wpdCommon = {
var aBaseURLObj = this.convertURLToObject(aBaseURL);
return aBaseURLObj.resolve(aRelURL);
} catch (ex) {
this.addError("[wpdCommon.resolveURL]:\n -> aBaseURL: " + aBaseURL + "\n -> aRelURL: " + aRelURL + "\n -> " + ex);
this.addError("[wpdCommon.resolveURL]:\n -> aBaseURL: " + aBaseURL + "\n -> aRelURL: " + aRelURL, ex);
}
return "";
},
@ -516,7 +519,7 @@ var wpdCommon = {
aURLObj.spec = aURL
return aURLObj.asciiHost;
} catch (ex) {
this.addError("[wpdCommon.getHostName]:\n -> aURL: " + aURL + "\n -> " + ex);
this.addError("[wpdCommon.getHostName]:\n -> aURL: " + aURL, ex);
}
return "";
},
@ -527,7 +530,7 @@ var wpdCommon = {
aURLObj.spec = aURL
return aURLObj.asciiSpec;
} catch (ex) {
this.addError("[wpdCommon.getHostName]:\n -> aURL: " + aURL + "\n -> " + ex);
this.addError("[wpdCommon.getHostName]:\n -> aURL: " + aURL, ex);
}
return "";
},
@ -577,7 +580,7 @@ var wpdCommon = {
if (text) output = output.split(/\n/g);
return output;
} catch (ex) {
this.addError("[wpdCommon.readFile]:\n -> str_Filename: " + str_Filename + "\n -> " + ex);
this.addError("[wpdCommon.readFile]:\n -> str_Filename: " + str_Filename, ex);
}
return "";
},
@ -621,7 +624,7 @@ var wpdCommon = {
obj_Transport.close();
return true;
} catch (ex) {
this.addError("[wpdCommon.writeFile]:\n -> str_Filename: " + str_Filename + "\n -> " + ex);
this.addError("[wpdCommon.writeFile]:\n -> str_Filename: " + str_Filename, ex);
}
return false;
},
@ -651,10 +654,13 @@ var wpdCommon = {
if (MODE_SIMULATE) return true;
try {
//new obj_URI object
var obj_URI = Components.classes["@mozilla.org/network/io-service;1"].getService(Components.interfaces.nsIIOService).newURI(aSourceURL, null, null);
var obj_URI = Components.classes["@mozilla.org/network/io-service;1"]
.getService(Components.interfaces.nsIIOService)
.newURI(aSourceURL, null, null);
//new file object
var obj_TargetFile = Components.classes["@mozilla.org/file/local;1"].createInstance(Components.interfaces.nsILocalFile);
var obj_TargetFile = Components.classes["@mozilla.org/file/local;1"]
.createInstance(Components.interfaces.nsILocalFile);
//set file with path
// NOTE: This function has a known bug on the macintosh and other OSes
// which do not represent file locations as paths. If you do use this
@ -662,23 +668,25 @@ var wpdCommon = {
obj_TargetFile.initWithPath(aTargetFilename);
//new persistence object
var obj_Persist = Components.classes["@mozilla.org/embedding/browser/nsWebBrowserPersist;1"].createInstance(Components.interfaces.nsIWebBrowserPersist);
var obj_Persist = Components.classes["@mozilla.org/embedding/browser/nsWebBrowserPersist;1"]
.createInstance(Components.interfaces.nsIWebBrowserPersist);
// set flags
const nsIWBP = Components.interfaces.nsIWebBrowserPersist;
var flags = nsIWBP.PERSIST_FLAGS_REPLACE_EXISTING_FILES | nsIWBP.PERSIST_FLAGS_FROM_CACHE;
var flags = nsIWBP.PERSIST_FLAGS_REPLACE_EXISTING_FILES
| nsIWBP.PERSIST_FLAGS_FROM_CACHE;
//nsIWBP.PERSIST_FLAGS_BYPASS_CACHE;
obj_Persist.persistFlags = flags;
// has the url the same filetype like the file extension?
//save file to target
Zotero.Utilities.Internal.saveURI(wbp, obj_URI, obj_TargetFile);
Zotero.Utilities.Internal.saveURI(obj_Persist, obj_URI, obj_TargetFile);
return true;
} catch (ex) {
aSourceURL = this.removeGETFromURL(aSourceURL);
this.addError("[wpdCommon.downloadFile]:\n -> aSourceURL: " + aSourceURL.substring(aSourceURL.length - 60) + "\n -> aTargetFilename: " + aTargetFilename + "\n -> " + ex);
this.addError("[wpdCommon.downloadFile]:\n -> aSourceURL: " + aSourceURL.substring(aSourceURL.length - 60) + "\n -> aTargetFilename: " + aTargetFilename, ex);
}
return false;
},

View file

@ -503,7 +503,7 @@ var wpdDOMSaver = {
aNode.setAttribute("src", this.relativeLinkFix(newFileName));
}
} catch (ex) {
wpdCommon.addError("[wpdCommon.processDOMNode]:\n -> aNode.nodeName: " + aNode.nodeName + "\n -> " + ex);
wpdCommon.addError("[wpdCommon.processDOMNode]:\n -> aNode.nodeName: " + aNode.nodeName, ex);
}
break;
case "xmp":
@ -525,7 +525,7 @@ var wpdDOMSaver = {
aNode.removeAttribute("onload");
}
} catch (ex) {
wpdCommon.addError("[wpdDOMSaver.processDOMNode]:\n -> aNode.nodeName: " + aNode.nodeName + "\n -> " + ex);
wpdCommon.addError("[wpdDOMSaver.processDOMNode]:\n -> aNode.nodeName: " + aNode.nodeName, ex);
}
return aNode;
},
@ -750,7 +750,7 @@ var wpdDOMSaver = {
}
return newFileName;
} catch (ex) {
wpdCommon.addError("[wpdDOMSaver.download]\n -> aURLSpec: " + aURLSpec + "\n -> " + ex);
wpdCommon.addError("[wpdDOMSaver.download]\n -> aURLSpec: " + aURLSpec, ex);
return "";
}
},
@ -784,7 +784,7 @@ var wpdDOMSaver = {
rootNode.insertBefore(aDocument.createTextNode("\n"), rootNode.firstChild);
} catch (ex) {
wpdCommon.addError("[wpdDOMSaver.createDocTypeNode]\n -> " + ex);
wpdCommon.addError("[wpdDOMSaver.createDocTypeNode]", ex);
}
},
@ -795,7 +795,7 @@ var wpdDOMSaver = {
try {
return aHTMLText.replace("<wpd_doctype></wpd_doctype>", this.getDocType(aDocument));
} catch (ex) {
wpdCommon.addError("[wpdDOMSaver.replaceDocType]\n -> " + ex);
wpdCommon.addError("[wpdDOMSaver.replaceDocType]", ex);
}
return aHTMLText;
},
@ -857,7 +857,7 @@ var wpdDOMSaver = {
rootNode.firstChild.insertBefore(aDocument.createTextNode("\n"), rootNode.firstChild.firstChild);
} catch (ex) {
wpdCommon.addError("[wpdDOMSaver.createMetaCharsetNode]\n -> " + ex);
wpdCommon.addError("[wpdDOMSaver.createMetaCharsetNode]", ex);
}
},
@ -872,7 +872,7 @@ var wpdDOMSaver = {
rootNode.firstChild.insertBefore(aDocument.createTextNode("\n"), rootNode.firstChild.firstChild);
rootNode.firstChild.insertBefore(metaNode, rootNode.firstChild.firstChild);
} catch (ex) {
wpdCommon.addError("[wpdDOMSaver.createMetaNameNode]\n -> " + ex);
wpdCommon.addError("[wpdDOMSaver.createMetaNameNode]", ex);
}
},
@ -981,7 +981,7 @@ var wpdDOMSaver = {
Zotero.debug("[wpdDOMSaver.saveDocumentCSS]: " + this.currentDir + aFileName);
// write css file
var CSSFile = this.currentDir + aFileName;
if (!wpdCommon.writeFile(CSSText, CSSFile)) wpdCommon.addError("[wpdDOMSaver.saveDocumentCSS]: could not write CSS File\n");
if (!wpdCommon.writeFile(CSSText, CSSFile)) wpdCommon.addError("[wpdDOMSaver.saveDocumentCSS]: could not write CSS File");
return aFileName;
}
}
@ -1051,7 +1051,7 @@ var wpdDOMSaver = {
// and write the file...
var HTMLFile = this.currentDir + aFileName;
if (!wpdCommon.writeFile(HTMLText, HTMLFile)) wpdCommon.addError("[wpdDOMSaver.saveDocumentHTML]: could not write HTML File\n");
if (!wpdCommon.writeFile(HTMLText, HTMLFile)) wpdCommon.addError("[wpdDOMSaver.saveDocumentHTML]: could not write HTML File");
return aFileName;
},
@ -1083,7 +1083,7 @@ var wpdDOMSaver = {
try {
return this.saveDocumentEx(this.document, this.name);
} catch (ex) {
wpdCommon.addError("[wpdDOMSaver.saveHTMLDocument]\n -> " + ex);
wpdCommon.addError("[wpdDOMSaver.saveHTMLDocument]", ex);
}
}