Merge branch '3.0'

Conflicts:
	chrome/content/zotero/xpcom/storage/webdav.js
	chrome/content/zotero/xpcom/storage/zfs.js
This commit is contained in:
Simon Kornblith 2012-11-12 16:04:39 -05:00
commit 585e5981f6
11 changed files with 1425 additions and 1417 deletions

View File

@ -1205,7 +1205,13 @@ function downloadPDFTool(tool, version, callback) {
wbp.progressListener = progressListener; wbp.progressListener = progressListener;
Zotero.debug("Saving " + uri.spec + " to " + fileURL.spec); Zotero.debug("Saving " + uri.spec + " to " + fileURL.spec);
try {
wbp.saveURI(uri, null, null, null, null, fileURL); wbp.saveURI(uri, null, null, null, null, fileURL);
} catch(e if e.name === "NS_ERROR_XPC_NOT_ENOUGH_ARGS") {
// https://bugzilla.mozilla.org/show_bug.cgi?id=794602
// XXX Always use when we no longer support Firefox < 18
wbp.saveURI(uri, null, null, null, null, fileURL, null);
}
} }

View File

@ -33,7 +33,6 @@
* the terms of any one of the MPL, the GPL or the LGPL. * the terms of any one of the MPL, the GPL or the LGPL.
* *
* ***** END LICENSE BLOCK ***** */ * ***** END LICENSE BLOCK ***** */
// -------------------------------------------------------------------------------- // --------------------------------------------------------------------------------
// "WebPageDump" Firefox Extension // "WebPageDump" Firefox Extension
// -------------------------------------------------------------------------------- // --------------------------------------------------------------------------------
@ -42,8 +41,6 @@
// provides common functions (file, preferences, windows, error,...) // provides common functions (file, preferences, windows, error,...)
// //
// -------------------------------------------------------------------------------- // --------------------------------------------------------------------------------
var gBrowserWindow = null; var gBrowserWindow = null;
var gExceptLocation = "about:blank"; var gExceptLocation = "about:blank";
var gCallback = ""; var gCallback = "";
@ -52,10 +49,10 @@ var gTimedOut = false;
var gWaitForPaint = false; var gWaitForPaint = false;
var MODE_SIMULATE = false; var MODE_SIMULATE = false;
var WPD_DEFAULTWIDTH=1024; var WPD_DEFAULTWIDTH = 1024;
var WPD_DEFAULTHEIGHT=768; var WPD_DEFAULTHEIGHT = 768;
var WPD_MAXUIERRORCOUNT=8; var WPD_MAXUIERRORCOUNT = 8;
/*function wpdGetTopBrowserWindow() /*function wpdGetTopBrowserWindow()
@ -74,14 +71,14 @@ var WPD_MAXUIERRORCOUNT=8;
/* [14:55:15] paolinho:  var browserWin = windowMediator.getMostRecentWindow("navigator:browser"); /* [14:55:15] paolinho:  var browserWin = windowMediator.getMostRecentWindow("navigator:browser");
const mainTabBox = browserWin.getBrowser().mTabBox; const mainTabBox = browserWin.getBrowser().mTabBox;
const topWindow = browserWin.getBrowser().browsers[mainTabBox.selectedIndex].contentWindow; const topWindow = browserWin.getBrowser().browsers[mainTabBox.selectedIndex].contentWindow;
[14:55:50]   var windowMediator = Components.classes["@mozilla.org/appshell/window-mediator;1"].getService(Components.interfaces.nsIWindowMediator); [14:55:50]
  var windowMediator = Components.classes["@mozilla.org/appshell/window-mediator;1"].getService(Components.interfaces.nsIWindowMediator);
*/ */
function wpdGetTopBrowserWindow() function wpdGetTopBrowserWindow() {
{
var windowManager = Components.classes['@mozilla.org/appshell/window-mediator;1'].getService(); var windowManager = Components.classes['@mozilla.org/appshell/window-mediator;1'].getService();
var windowManagerInterface = windowManager.QueryInterface( Components.interfaces.nsIWindowMediator); var windowManagerInterface = windowManager.QueryInterface(Components.interfaces.nsIWindowMediator);
var topWindowOfType = windowManagerInterface.getMostRecentWindow( "navigator:browser" ); var topWindowOfType = windowManagerInterface.getMostRecentWindow("navigator:browser");
if (topWindowOfType) { if (topWindowOfType) {
return topWindowOfType; return topWindowOfType;
@ -90,8 +87,7 @@ function wpdGetTopBrowserWindow()
} }
function wpdWindowLoaded() function wpdWindowLoaded() {
{
try { try {
// this will be called multiple times if the page contains more than one document (frames, flash,...) // this will be called multiple times if the page contains more than one document (frames, flash,...)
//var browser=this.document.getElementById("content"); //var browser=this.document.getElementById("content");
@ -101,91 +97,88 @@ function wpdWindowLoaded()
if (!(browser.webProgress.isLoadingDocument || browser.contentDocument.location == gExceptLocation)) { if (!(browser.webProgress.isLoadingDocument || browser.contentDocument.location == gExceptLocation)) {
Zotero.debug("[wpdWindowLoaded] window finally loaded"); Zotero.debug("[wpdWindowLoaded] window finally loaded");
gBrowserWindow.clearTimeout(gTimeOutID); gBrowserWindow.clearTimeout(gTimeOutID);
gBrowserWindow.removeEventListener("load",wpdWindowLoaded,true); gBrowserWindow.removeEventListener("load", wpdWindowLoaded, true);
//dump("[wpdWindowLoaded] calling "+gCallback+"\n"); //dump("[wpdWindowLoaded] calling "+gCallback+"\n");
if (gWaitForPaint) { if (gWaitForPaint) {
wpdCommon.sizeWindow(WPD_DEFAULTWIDTH-1,WPD_DEFAULTHEIGHT); // this is for the strange empty lines bug wpdCommon.sizeWindow(WPD_DEFAULTWIDTH - 1, WPD_DEFAULTHEIGHT); // this is for the strange empty lines bug
wpdCommon.sizeWindow(WPD_DEFAULTWIDTH,WPD_DEFAULTHEIGHT); wpdCommon.sizeWindow(WPD_DEFAULTWIDTH, WPD_DEFAULTHEIGHT);
} }
var w=0; var w = 0;
if (gWaitForPaint) w=5000; // wait for painting if (gWaitForPaint) w = 5000; // wait for painting
gBrowserWindow.setTimeout(gCallback, w); gBrowserWindow.setTimeout(gCallback, w);
} }
} catch (ex) { } catch (ex) {
Zotero.debug("[wpdWindowLoaded] EXCEPTION: "+ex); Zotero.debug("[wpdWindowLoaded] EXCEPTION: " + ex);
} }
} }
function wpdTimeOut() function wpdTimeOut() {
{
Zotero.debug("[wpdTimeOut] timeout triggered!"); Zotero.debug("[wpdTimeOut] timeout triggered!");
gTimedOut=true; gTimedOut = true;
gBrowserWindow.clearTimeout(gTimeOutID); gBrowserWindow.clearTimeout(gTimeOutID);
gBrowserWindow.removeEventListener("load",wpdWindowLoaded,true); gBrowserWindow.removeEventListener("load", wpdWindowLoaded, true);
gBrowserWindow.setTimeout(gCallback, 0); gBrowserWindow.setTimeout(gCallback, 0);
} }
function wpdIsTimedOut() function wpdIsTimedOut() {
{
return gTimedOut; return gTimedOut;
} }
function wpdLoadURL(aURI,aCallback) function wpdLoadURL(aURI, aCallback) {
{
try { try {
gTimedOut=false; gTimedOut = false;
Zotero.debug("[wpdLoadURL] aURI: "+aURI); Zotero.debug("[wpdLoadURL] aURI: " + aURI);
if (aURI=="") return; if (aURI == "") return;
gBrowserWindow = wpdGetTopBrowserWindow(); gBrowserWindow = wpdGetTopBrowserWindow();
gBrowserWindow.loadURI(aURI); gBrowserWindow.loadURI(aURI);
gCallback = aCallback; gCallback = aCallback;
// 30 seconds maximum for loading the page // 30 seconds maximum for loading the page
gTimeOutID=gBrowserWindow.setTimeout(wpdTimeOut, 60000); gTimeOutID = gBrowserWindow.setTimeout(wpdTimeOut, 60000);
gBrowserWindow.addEventListener("load",wpdWindowLoaded, true); gBrowserWindow.addEventListener("load", wpdWindowLoaded, true);
} catch (ex) { } catch (ex) {
Zotero.debug("[wpdLoadURL] EXCEPTION: "+ex); Zotero.debug("[wpdLoadURL] EXCEPTION: " + ex);
} }
} }
var wpdCommon = { var wpdCommon = {
errList : "", errList: "",
errCount : 0, errCount: 0,
downloading : false, downloading: false,
downloaded : false, downloaded: false,
allowed_entities: allowed_entities:
"&quot;&amp;&apos;&lt;&gt;&nbsp;&iexcl;&cent;&pound;&curren;&yen;&brvbar;"+ "&quot;&amp;&apos;&lt;&gt;&nbsp;&iexcl;&cent;&pound;&curren;&yen;&brvbar;" +
"&sect;&uml;&copy;&ordf;&laquo;&not;&shy;&reg;&macr;&deg;&plusmn;"+ "&sect;&uml;&copy;&ordf;&laquo;&not;&shy;&reg;&macr;&deg;&plusmn;" +
"&sup2;&sup3;&acute;&micro;&para;&middot;&cedil;&sup1;&ordm;&raquo;"+ "&sup2;&sup3;&acute;&micro;&para;&middot;&cedil;&sup1;&ordm;&raquo;" +
"&frac14;&frac12;&frac34;&iquest;&Agrave;&Aacute;&Acirc;&Atilde;&Auml;"+ "&frac14;&frac12;&frac34;&iquest;&Agrave;&Aacute;&Acirc;&Atilde;&Auml;" +
"&Aring;&AElig;&Ccedil;&Egrave;&Eacute;&Ecirc;&Euml;&Igrave;&Iacute;"+ "&Aring;&AElig;&Ccedil;&Egrave;&Eacute;&Ecirc;&Euml;&Igrave;&Iacute;" +
"&Icirc;&Iuml;&ETH;&Ntilde;&Ograve;&Oacute;&Ocirc;&Otilde;&Ouml;"+ "&Icirc;&Iuml;&ETH;&Ntilde;&Ograve;&Oacute;&Ocirc;&Otilde;&Ouml;" +
"&times;&Oslash;&Ugrave;&Uacute;&Ucirc;&Uuml;&Yacute;&THORN;&szlig;"+ "&times;&Oslash;&Ugrave;&Uacute;&Ucirc;&Uuml;&Yacute;&THORN;&szlig;" +
"&agrave;&aacute;&acirc;&atilde;&auml;&aring;&aelig;&ccedil;&egrave;"+ "&agrave;&aacute;&acirc;&atilde;&auml;&aring;&aelig;&ccedil;&egrave;" +
"&eacute;&ecirc;&euml;&igrave;&iacute;&icirc;&iuml;&eth;&ntilde;&ograve;"+ "&eacute;&ecirc;&euml;&igrave;&iacute;&icirc;&iuml;&eth;&ntilde;&ograve;" +
"&oacute;&ocirc;&otilde;&ouml;&divide;&oslash;&ugrave;&uacute;&ucirc;&uuml;"+ "&oacute;&ocirc;&otilde;&ouml;&divide;&oslash;&ugrave;&uacute;&ucirc;&uuml;" +
"&yacute;&thorn;&yuml;&OElig;&oelig;&Scaron;&scaron;&Yuml;&fnof;&circ;"+ "&yacute;&thorn;&yuml;&OElig;&oelig;&Scaron;&scaron;&Yuml;&fnof;&circ;" +
"&tilde;&Alpha;&Beta;&Gamma;&Delta;&Epsilon;&Zeta;&Eta;&Theta;&Iota;&Kappa;"+ "&tilde;&Alpha;&Beta;&Gamma;&Delta;&Epsilon;&Zeta;&Eta;&Theta;&Iota;&Kappa;" +
"&Lambda;&Mu;&Nu;&Xi;&Omicron;&Pi;&Rho;&Sigma;&Tau;&Upsilon;&Phi;&Chi;&Psi;"+ "&Lambda;&Mu;&Nu;&Xi;&Omicron;&Pi;&Rho;&Sigma;&Tau;&Upsilon;&Phi;&Chi;&Psi;" +
"&Omega;&alpha;&beta;&gamma;&delta;&epsilon;&zeta;&eta;&theta;&iota;&kappa;"+ "&Omega;&alpha;&beta;&gamma;&delta;&epsilon;&zeta;&eta;&theta;&iota;&kappa;" +
"&lambda;&mu;&nu;&xi;&omicron;&pi;&rho;&sigmaf;&sigma;&tau;&upsilon;&phi;"+ "&lambda;&mu;&nu;&xi;&omicron;&pi;&rho;&sigmaf;&sigma;&tau;&upsilon;&phi;" +
"&chi;&psi;&omega;&thetasym;&upsih;&phi;&piv;&ensp;&emsp;&thinsp;&zwnj;"+ "&chi;&psi;&omega;&thetasym;&upsih;&phi;&piv;&ensp;&emsp;&thinsp;&zwnj;" +
"&zwj;&lrm;&rlm;&ndash;&mdash;&lsquo;&rsquo;&sbquo;&ldquo;&rdquo;&bdquo;"+ "&zwj;&lrm;&rlm;&ndash;&mdash;&lsquo;&rsquo;&sbquo;&ldquo;&rdquo;&bdquo;" +
"&dagger;&Dagger;&bull;&hellip;&permil;&prime;&Prime;&lsaquo;&rsaquo;"+ "&dagger;&Dagger;&bull;&hellip;&permil;&prime;&Prime;&lsaquo;&rsaquo;" +
"&oline;&frasl;&euro;&image;&weierp;&real;&trade;&alefsym;&larr;&uarr;"+ "&oline;&frasl;&euro;&image;&weierp;&real;&trade;&alefsym;&larr;&uarr;" +
"&rarr;&darr;&harr;&crarr;&lArr;&uArr;&rArr;&dArr;&hArr;&forall;"+ "&rarr;&darr;&harr;&crarr;&lArr;&uArr;&rArr;&dArr;&hArr;&forall;" +
"&part;&exist;&empty;&nabla;&isin;&notin;&ni;&prod;&sum;&minus;&lowast;&radic;"+ "&part;&exist;&empty;&nabla;&isin;&notin;&ni;&prod;&sum;&minus;&lowast;&radic;" +
"&prop;&infin;&ang;&or;&cap;&cup;&int;&there4;&sim;&cong;&asymp;&ne;&equiv;"+ "&prop;&infin;&ang;&or;&cap;&cup;&int;&there4;&sim;&cong;&asymp;&ne;&equiv;" +
"&le;&ge;&sub;&sup;&nsub;&sube;&supe;&oplus;&otimes;&perp;&sdot;&lceil;"+ "&le;&ge;&sub;&sup;&nsub;&sube;&supe;&oplus;&otimes;&perp;&sdot;&lceil;" +
"&rceil;&lfloor;&rfloor;&lang;&rang;&loz;&spades;&clubs;&hearts;&diams;", "&rceil;&lfloor;&rfloor;&lang;&rang;&loz;&spades;&clubs;&hearts;&diams;",
trim : function (aString) { trim: function (aString) {
try { try {
return (aString.replace(/\s+$/,"").replace(/^\s+/,"")); return (aString.replace(/\s+$/, "").replace(/^\s+/, ""));
} catch(ex) { } catch (ex) {
return aString; return aString;
} }
}, },
@ -193,27 +186,26 @@ var wpdCommon = {
// checks the CRLFs at the beginning - if there are CRLFs present // checks the CRLFs at the beginning - if there are CRLFs present
// one additional CRLF will be added at the beginning // one additional CRLF will be added at the beginning
checkCRLF : function (aNode) checkCRLF: function (aNode) {
{
try { try {
var before=false; var before = false;
var after=false; var after = false;
if (aNode.parentNode.firstChild==aNode) before=true; if (aNode.parentNode.firstChild == aNode) before = true;
if (!before && !after) { if (!before && !after) {
throw new Error("return"); throw new Error("return");
} }
// why <BR>? Because the <BR> Tag ist not present in text DOM nodes... // why <BR>? Because the <BR> Tag ist not present in text DOM nodes...
var aString=aNode.nodeValue; var aString = aNode.nodeValue;
if (aString.search(/\n/)==-1) throw new Error("return"); if (aString.search(/\n/) == -1) throw new Error("return");
aString=(aString.replace(/\r\n/g,"<br>").replace(/\n/g,"<br>")); aString = (aString.replace(/\r\n/g, "<br>").replace(/\n/g, "<br>"));
var a=aString.split("<br>"); var a = aString.split("<br>");
var s=0; var s = 0;
var e=0; var e = 0;
if (before) { if (before) {
for (var i=0;i<a.length;i++) { for (var i = 0; i < a.length; i++) {
if (this.trim(a[i])!="") { if (this.trim(a[i]) != "") {
break; break;
} else { } else {
s++; s++;
@ -222,8 +214,8 @@ var wpdCommon = {
} }
} }
aString=a.join("\r\n"); aString = a.join("\r\n");
if (s>0) aString="\r\n"+aString; if (s > 0) aString = "\r\n" + aString;
return aString; return aString;
} catch (ex) { } catch (ex) {
@ -231,29 +223,26 @@ var wpdCommon = {
} }
}, },
unicodeToEntity : function (text,charset) unicodeToEntity: function (text, charset) {
{
function convertEntity(letter) { function convertEntity(letter) {
try { try {
var l = gEntityConverter.ConvertToEntity(letter,entityVersion); var l = gEntityConverter.ConvertToEntity(letter, entityVersion);
// is the entity allowed? // is the entity allowed?
if (entities.indexOf(l)>=0) { if (entities.indexOf(l) >= 0) {
return l; return l;
} else if ( (l!=letter) ) { } else if ((l != letter)) {
return "&#"+letter.charCodeAt(0)+";"; return "&#" + letter.charCodeAt(0) + ";";
}
} catch (ex) {
} }
} catch (ex) {}
// now we check if the letter is valid inside the destination charset // now we check if the letter is valid inside the destination charset
// (if the result is a ? it is not valid - except letter=?) // (if the result is a ? it is not valid - except letter=?)
try { try {
var s=gUnicodeConverter.ConvertFromUnicode(letter); var s = gUnicodeConverter.ConvertFromUnicode(letter);
if ( (charset!="UTF-8") && (s=="?") ) { if ((charset != "UTF-8") && (s == "?")) {
return "&#"+letter.charCodeAt(0)+";"; return "&#" + letter.charCodeAt(0) + ";";
}
} catch (ex) {
} }
} catch (ex) {}
return letter; return letter;
} }
@ -261,16 +250,16 @@ var wpdCommon = {
try { try {
var gUnicodeConverter = Components.classes['@mozilla.org/intl/scriptableunicodeconverter'].getService(Components.interfaces.nsIScriptableUnicodeConverter); var gUnicodeConverter = Components.classes['@mozilla.org/intl/scriptableunicodeconverter'].getService(Components.interfaces.nsIScriptableUnicodeConverter);
gUnicodeConverter.charset = charset; gUnicodeConverter.charset = charset;
} catch(ex) { } catch (ex) {
Zotero.debug ("gUnicodeConverter EXCEPTION:"+ex); Zotero.debug("gUnicodeConverter EXCEPTION:" + ex);
} }
} }
if (!gEntityConverter) { if (!gEntityConverter) {
try { try {
var gEntityConverter = Components.classes["@mozilla.org/intl/entityconverter;1"].createInstance(Components.interfaces.nsIEntityConverter); var gEntityConverter = Components.classes["@mozilla.org/intl/entityconverter;1"].createInstance(Components.interfaces.nsIEntityConverter);
} catch(e) { } catch (e) {
Zotero.debug ("gEntityConverter EXCEPTION:"+ex); Zotero.debug("gEntityConverter EXCEPTION:" + ex);
} }
} }
@ -293,51 +282,45 @@ var wpdCommon = {
}, },
playSound : function() playSound: function () {
{
try { try {
var sound = Components.classes["@mozilla.org/sound;1"].createInstance(Components.interfaces.nsISound); var sound = Components.classes["@mozilla.org/sound;1"].createInstance(Components.interfaces.nsISound);
sound.playSystemSound("ringin.wav"); sound.playSystemSound("ringin.wav");
} catch(ex) { } catch (ex) {}
}
}, },
// return the current focused window // return the current focused window
getFocusedWindow : function() getFocusedWindow: function () {
{
var win = document.commandDispatcher.focusedWindow; var win = document.commandDispatcher.focusedWindow;
if ( !win || win == window || win instanceof Components.interfaces.nsIDOMChromeWindow ) win = window._content; if (!win || win == window || win instanceof Components.interfaces.nsIDOMChromeWindow) win = window._content;
return win; return win;
}, },
sizeWindow : function(w,h) sizeWindow: function (w, h) {
{
try { try {
var window=this.getFocusedWindow(); var window = this.getFocusedWindow();
window.moveTo(0,0); window.moveTo(0, 0);
if ((w==0) || (w>screen.availWidth)) w=screen.availWidth; if ((w == 0) || (w > screen.availWidth)) w = screen.availWidth;
if ((h==0) || (w>screen.availHeight)) h=screen.availHeight; if ((h == 0) || (w > screen.availHeight)) h = screen.availHeight;
window.resizeTo(w,h); window.resizeTo(w, h);
window.focus(); window.focus();
} catch(ex) { } catch (ex) {}
}
}, },
// add a line to the error list (displays a maximum of 15 errors) // add a line to the error list (displays a maximum of 15 errors)
addError : function(aError) addError: function (aError) {
{ Zotero.debug('ERROR: ' + aError);
Zotero.debug('ERROR: '+aError); if (this.errCount < WPD_MAXUIERRORCOUNT) {
if (this.errCount<WPD_MAXUIERRORCOUNT) { if (this.errList.indexOf(aError) > -1) return; // is the same
if (this.errList.indexOf(aError)>-1) return; // is the same this.errList = this.errList + aError + "\n";
this.errList = this.errList+aError+"\n"; } else if (this.errCount == WPD_MAXUIERRORCOUNT) {
} else if (this.errCount==WPD_MAXUIERRORCOUNT) { this.errList = this.errList + '...';
this.errList = this.errList+'...';
} }
this.errCount++; this.errCount++;
}, },
saveWebPage : function(aDestFile) { saveWebPage: function (aDestFile) {
Zotero.debug("[saveWebPage] "+aDestFile); Zotero.debug("[saveWebPage] " + aDestFile);
var nsIWBP = Components.classes["@mozilla.org/embedding/browser/nsWebBrowserPersist;1"].createInstance(Components.interfaces.nsIWebBrowserPersist); var nsIWBP = Components.classes["@mozilla.org/embedding/browser/nsWebBrowserPersist;1"].createInstance(Components.interfaces.nsIWebBrowserPersist);
var doc = window.content.document; var doc = window.content.document;
var file = Components.classes["@mozilla.org/file/local;1"].createInstance(Components.interfaces.nsILocalFile); var file = Components.classes["@mozilla.org/file/local;1"].createInstance(Components.interfaces.nsILocalFile);
@ -348,20 +331,18 @@ var wpdCommon = {
}, },
// returns num as string of length i filled up with 0s // returns num as string of length i filled up with 0s
addLeftZeros : function(num,i) addLeftZeros: function (num, i) {
{ var s = "" + num;
var s=""+num; var r = "";
var r=""; for (var f = 0; f < i - s.length; f++) r = r + "0";
for (var f=0;f<i-s.length;f++) r=r+"0"; return r + s;
return r+s;
}, },
// split the filename in filename and extension // split the filename in filename and extension
splitFileName : function(aFileName) splitFileName: function (aFileName) {
{
var pos = aFileName.lastIndexOf("."); var pos = aFileName.lastIndexOf(".");
var ret = []; var ret = [];
if ( pos != -1 ) { if (pos != -1) {
ret[0] = aFileName.substring(0, pos); ret[0] = aFileName.substring(0, pos);
ret[1] = aFileName.substring(pos + 1, aFileName.length); ret[1] = aFileName.substring(pos + 1, aFileName.length);
} else { } else {
@ -372,8 +353,7 @@ var wpdCommon = {
}, },
// replace illegal characters // replace illegal characters
getValidFileName : function(aFileName) getValidFileName: function (aFileName) {
{
aFileName = aFileName.replace(/[\"\?!~`]+/g, ""); aFileName = aFileName.replace(/[\"\?!~`]+/g, "");
aFileName = aFileName.replace(/[\*\&]+/g, "+"); aFileName = aFileName.replace(/[\*\&]+/g, "+");
aFileName = aFileName.replace(/[\\\/\|\:;]+/g, "-"); aFileName = aFileName.replace(/[\\\/\|\:;]+/g, "-");
@ -384,141 +364,127 @@ var wpdCommon = {
return aFileName; return aFileName;
}, },
getURL : function() getURL: function () {
{
return top.window._content.document.location.href; return top.window._content.document.location.href;
}, },
// remove get variables from an URL // remove get variables from an URL
removeGETFromURL : function(aURL) removeGETFromURL: function (aURL) {
{
var pos; var pos;
aURL = ( (pos = aURL.indexOf("?")) != -1 ) ? aURL.substring(0, pos) : aURL; aURL = ((pos = aURL.indexOf("?")) != -1) ? aURL.substring(0, pos) : aURL;
aURL = ( (pos = aURL.indexOf("#")) != -1 ) ? aURL.substring(0, pos) : aURL; aURL = ((pos = aURL.indexOf("#")) != -1) ? aURL.substring(0, pos) : aURL;
return aURL; return aURL;
}, },
// extract filename from URL // extract filename from URL
getFileName : function(aURL) getFileName: function (aURL) {
{
var pos; var pos;
aURL = this.removeGETFromURL(aURL); aURL = this.removeGETFromURL(aURL);
aURL = ( (pos = aURL.lastIndexOf("/")) != -1 ) ? aURL.substring(++pos) : aURL; aURL = ((pos = aURL.lastIndexOf("/")) != -1) ? aURL.substring(++pos) : aURL;
return aURL; return aURL;
}, },
filePathToURI: function(filePath) filePathToURI: function (filePath) {
{
var obj_File = Components.classes["@mozilla.org/file/local;1"].getService(Components.interfaces.nsILocalFile); var obj_File = Components.classes["@mozilla.org/file/local;1"].getService(Components.interfaces.nsILocalFile);
obj_File.initWithPath(filePath); obj_File.initWithPath(filePath);
var obj_FPH = Components.classes["@mozilla.org/network/protocol;1?name=file"].getService(Components.interfaces.nsIFileProtocolHandler); var obj_FPH = Components.classes["@mozilla.org/network/protocol;1?name=file"].getService(Components.interfaces.nsIFileProtocolHandler);
return obj_FPH.getURLSpecFromFile(obj_File); return obj_FPH.getURLSpecFromFile(obj_File);
}, },
URLToFilePath: function(aURL) URLToFilePath: function (aURL) {
{
var obj_FPH = Components.classes["@mozilla.org/network/protocol;1?name=file"].getService(Components.interfaces.nsIFileProtocolHandler); var obj_FPH = Components.classes["@mozilla.org/network/protocol;1?name=file"].getService(Components.interfaces.nsIFileProtocolHandler);
try { try {
return obj_FPH.getFileFromURLSpec(aURL).path; return obj_FPH.getFileFromURLSpec(aURL).path;
} catch(ex) { } catch (ex) {
return aURL; return aURL;
} }
}, },
// right part of filepath/filename // right part of filepath/filename
getFileLeafName: function(filePath) getFileLeafName: function (filePath) {
{
var obj_File = Components.classes["@mozilla.org/file/local;1"].getService(Components.interfaces.nsILocalFile); var obj_File = Components.classes["@mozilla.org/file/local;1"].getService(Components.interfaces.nsILocalFile);
obj_File.initWithPath(filePath); obj_File.initWithPath(filePath);
return obj_File.leafName; return obj_File.leafName;
}, },
getFilePath: function(filePath) getFilePath: function (filePath) {
{
var obj_File = Components.classes["@mozilla.org/file/local;1"].getService(Components.interfaces.nsILocalFile); var obj_File = Components.classes["@mozilla.org/file/local;1"].getService(Components.interfaces.nsILocalFile);
obj_File.initWithPath(filePath); obj_File.initWithPath(filePath);
var pos; // Added by Dan S. for Zotero var pos; // Added by Dan S. for Zotero
return ( (pos = filePath.lastIndexOf(obj_File.leafName)) != -1 ) ? filePath.substring(0,pos) : filePath; return ((pos = filePath.lastIndexOf(obj_File.leafName)) != -1) ? filePath.substring(0, pos) : filePath;
}, },
appendFilePath: function(filePath,appendPath) appendFilePath: function (filePath, appendPath) {
{
var obj_File = Components.classes["@mozilla.org/file/local;1"].getService(Components.interfaces.nsILocalFile); var obj_File = Components.classes["@mozilla.org/file/local;1"].getService(Components.interfaces.nsILocalFile);
obj_File.initWithPath(filePath); obj_File.initWithPath(filePath);
obj_File.appendRelativePath(appendPath); obj_File.appendRelativePath(appendPath);
return obj_File.path; return obj_File.path;
}, },
pathExists: function(filePath) pathExists: function (filePath) {
{
var obj_File = Components.classes["@mozilla.org/file/local;1"].getService(Components.interfaces.nsILocalFile); var obj_File = Components.classes["@mozilla.org/file/local;1"].getService(Components.interfaces.nsILocalFile);
try { try {
obj_File.initWithPath(filePath); obj_File.initWithPath(filePath);
return obj_File.exists(); return obj_File.exists();
} catch(ex) { } catch (ex) {
return false; return false;
} }
}, },
// add the HTML Tag Stuff to aNode and embedd the aNode.innerHTML between the tags // add the HTML Tag Stuff to aNode and embedd the aNode.innerHTML between the tags
nodeToHTMLString: function(aNode) nodeToHTMLString: function (aNode) {
{ if (aNode == null) return "";
if (aNode==null) return "";
var tag = "<" + aNode.nodeName.toLowerCase(); var tag = "<" + aNode.nodeName.toLowerCase();
for ( var i=0; i<aNode.attributes.length; i++ ) for (var i = 0; i < aNode.attributes.length; i++) {
tag += ' ' + aNode.attributes[i].name + '="' + aNode.attributes[i].value + '"'; tag += ' ' + aNode.attributes[i].name + '="' + aNode.attributes[i].value + '"';
}
tag += ">\n"; tag += ">\n";
return tag + aNode.innerHTML + "</" + aNode.nodeName.toLowerCase() + ">\n"; return tag + aNode.innerHTML + "</" + aNode.nodeName.toLowerCase() + ">\n";
}, },
ConvertFromUnicode16 : function(aString,charset) ConvertFromUnicode16: function (aString, charset) {
{ if (!aString) return "";
if ( !aString ) return "";
try { try {
var UNICODE = Components.classes['@mozilla.org/intl/scriptableunicodeconverter'].getService(Components.interfaces.nsIScriptableUnicodeConverter); var UNICODE = Components.classes['@mozilla.org/intl/scriptableunicodeconverter'].getService(Components.interfaces.nsIScriptableUnicodeConverter);
UNICODE.charset = charset; UNICODE.charset = charset;
aString = UNICODE.ConvertFromUnicode(aString); aString = UNICODE.ConvertFromUnicode(aString);
aString = aString + UNICODE.Finish(); aString = aString + UNICODE.Finish();
} catch(ex) { } catch (ex) {
//this.addError("[wpdCommon.convertStringToCharset]:\n -> charset: "+charset+"\n -> "+ex); //this.addError("[wpdCommon.convertStringToCharset]:\n -> charset: "+charset+"\n -> "+ex);
} }
return aString; return aString;
}, },
ConvertToUnicode16 : function(aString,charset) ConvertToUnicode16: function (aString, charset) {
{ if (!aString) return "";
if ( !aString ) return "";
try { try {
var UNICODE = Components.classes['@mozilla.org/intl/scriptableunicodeconverter'].getService(Components.interfaces.nsIScriptableUnicodeConverter); var UNICODE = Components.classes['@mozilla.org/intl/scriptableunicodeconverter'].getService(Components.interfaces.nsIScriptableUnicodeConverter);
UNICODE.charset = charset; UNICODE.charset = charset;
aString = UNICODE.ConvertToUnicode(aString); aString = UNICODE.ConvertToUnicode(aString);
} catch(ex) { } catch (ex) {
//this.addError("[wpdCommon.convertStringToCharset]:\n -> charset: "+charset+"\n -> "+ex); //this.addError("[wpdCommon.convertStringToCharset]:\n -> charset: "+charset+"\n -> "+ex);
} }
return aString; return aString;
}, },
// convert the doctype to an HTML doctype String // convert the doctype to an HTML doctype String
doctypeToHTMLString : function(aDoctype) doctypeToHTMLString: function (aDoctype) {
{ if (!aDoctype) return "";
if ( !aDoctype ) return "";
var ret = "<!DOCTYPE " + aDoctype.name; var ret = "<!DOCTYPE " + aDoctype.name;
if ( aDoctype.publicId ) ret += ' PUBLIC "' + aDoctype.publicId + '"'; if (aDoctype.publicId) ret += ' PUBLIC "' + aDoctype.publicId + '"';
if ( aDoctype.systemId ) ret += ' "' + aDoctype.systemId + '"'; if (aDoctype.systemId) ret += ' "' + aDoctype.systemId + '"';
ret += ">\n"; ret += ">\n";
return ret; return ret;
}, },
addCommentTag : function(targetNode, aComment) addCommentTag: function (targetNode, aComment) {
{
targetNode.appendChild(document.createTextNode("\n")); targetNode.appendChild(document.createTextNode("\n"));
targetNode.appendChild(document.createComment(aComment)); targetNode.appendChild(document.createComment(aComment));
targetNode.appendChild(document.createTextNode("\n")); targetNode.appendChild(document.createTextNode("\n"));
}, },
removeNodeFromParent : function(aNode) removeNodeFromParent: function (aNode) {
{
// Added by Dan S. for Zotero // Added by Dan S. for Zotero
var document = aNode.ownerDocument; var document = aNode.ownerDocument;
@ -530,113 +496,102 @@ var wpdCommon = {
// convert URL String to Object // convert URL String to Object
// for easier URL handling // for easier URL handling
convertURLToObject : function(aURLString) convertURLToObject: function (aURLString) {
{
var aURL = Components.classes['@mozilla.org/network/standard-url;1'].createInstance(Components.interfaces.nsIURL); var aURL = Components.classes['@mozilla.org/network/standard-url;1'].createInstance(Components.interfaces.nsIURL);
aURL.spec = aURLString; aURL.spec = aURLString;
return aURL; return aURL;
}, },
// resolves the relative URL (aRelURL) with the base URL (aBaseURL) // resolves the relative URL (aRelURL) with the base URL (aBaseURL)
resolveURL : function(aBaseURL, aRelURL) resolveURL: function (aBaseURL, aRelURL) {
{
try { try {
var aBaseURLObj = this.convertURLToObject(aBaseURL); var aBaseURLObj = this.convertURLToObject(aBaseURL);
return aBaseURLObj.resolve(aRelURL); return aBaseURLObj.resolve(aRelURL);
} catch(ex) { } catch (ex) {
this.addError("[wpdCommon.resolveURL]:\n -> aBaseURL: "+aBaseURL+"\n -> aRelURL: "+aRelURL+"\n -> "+ex); this.addError("[wpdCommon.resolveURL]:\n -> aBaseURL: " + aBaseURL + "\n -> aRelURL: " + aRelURL + "\n -> " + ex);
} }
return ""; return "";
}, },
getHostName : function(aURL) getHostName: function (aURL) {
{
try { try {
var aURLObj = Components.classes['@mozilla.org/network/standard-url;1'].createInstance(Components.interfaces.nsIURI); var aURLObj = Components.classes['@mozilla.org/network/standard-url;1'].createInstance(Components.interfaces.nsIURI);
aURLObj.spec = aURL aURLObj.spec = aURL
return aURLObj.asciiHost; return aURLObj.asciiHost;
} catch(ex) { } catch (ex) {
this.addError("[wpdCommon.getHostName]:\n -> aURL: "+aURL+"\n -> "+ex); this.addError("[wpdCommon.getHostName]:\n -> aURL: " + aURL + "\n -> " + ex);
} }
return ""; return "";
}, },
convertUrlToASCII : function(aURL) convertUrlToASCII: function (aURL) {
{
try { try {
var aURLObj = Components.classes['@mozilla.org/network/standard-url;1'].createInstance(Components.interfaces.nsIURI); var aURLObj = Components.classes['@mozilla.org/network/standard-url;1'].createInstance(Components.interfaces.nsIURI);
aURLObj.spec = aURL aURLObj.spec = aURL
return aURLObj.asciiSpec; return aURLObj.asciiSpec;
} catch(ex) { } catch (ex) {
this.addError("[wpdCommon.getHostName]:\n -> aURL: "+aURL+"\n -> "+ex); this.addError("[wpdCommon.getHostName]:\n -> aURL: " + aURL + "\n -> " + ex);
} }
return ""; return "";
}, },
createDir : function(str_Dir) createDir: function (str_Dir) {
{
var obj_File = Components.classes["@mozilla.org/file/local;1"].createInstance(Components.interfaces.nsILocalFile); var obj_File = Components.classes["@mozilla.org/file/local;1"].createInstance(Components.interfaces.nsILocalFile);
obj_File.initWithPath(str_Dir); obj_File.initWithPath(str_Dir);
if (!obj_File.exists()) if (!obj_File.exists()) obj_File.create(obj_File.DIRECTORY_TYPE, 0700);
obj_File.create(obj_File.DIRECTORY_TYPE, 0700);
}, },
readDir : function(str_Dir) readDir: function (str_Dir) {
{
var obj_File = Components.classes["@mozilla.org/file/local;1"].createInstance(Components.interfaces.nsILocalFile); var obj_File = Components.classes["@mozilla.org/file/local;1"].createInstance(Components.interfaces.nsILocalFile);
obj_File.initWithPath(str_Dir); obj_File.initWithPath(str_Dir);
if (obj_File.exists()) return obj_File.directoryEntries; if (obj_File.exists()) return obj_File.directoryEntries;
return []; return [];
}, },
fileSize : function(str_Filename) fileSize: function (str_Filename) {
{
var obj_File = Components.classes["@mozilla.org/file/local;1"].createInstance(Components.interfaces.nsILocalFile); var obj_File = Components.classes["@mozilla.org/file/local;1"].createInstance(Components.interfaces.nsILocalFile);
obj_File.initWithPath(str_Filename); obj_File.initWithPath(str_Filename);
return obj_File.fileSize; return obj_File.fileSize;
}, },
// read the file (str_Filename) to a String Buffer (str_Buffer) // read the file (str_Filename) to a String Buffer (str_Buffer)
readFile : function(str_Filename,removeComments,text) readFile: function (str_Filename, removeComments, text) {
{ try {
try{
var obj_File = Components.classes["@mozilla.org/file/local;1"].createInstance(Components.interfaces.nsILocalFile); var obj_File = Components.classes["@mozilla.org/file/local;1"].createInstance(Components.interfaces.nsILocalFile);
obj_File.initWithPath(str_Filename); obj_File.initWithPath(str_Filename);
if (!obj_File.exists()) { if (!obj_File.exists()) {
this.addError("[wpdCommon.readFile]:\n -> str_Filename: "+str_Filename+"\n -> file not found!"); this.addError("[wpdCommon.readFile]:\n -> str_Filename: " + str_Filename + "\n -> file not found!");
return ""; return "";
} }
var obj_Transport = Components.classes["@mozilla.org/network/file-input-stream;1"].createInstance(Components.interfaces.nsIFileInputStream); var obj_Transport = Components.classes["@mozilla.org/network/file-input-stream;1"].createInstance(Components.interfaces.nsIFileInputStream);
obj_Transport.init( obj_File, 0x01 , 004, 0 ); obj_Transport.init(obj_File, 0x01, 004, 0);
var sis = Components.classes["@mozilla.org/scriptableinputstream;1"].createInstance( Components.interfaces.nsIScriptableInputStream ); var sis = Components.classes["@mozilla.org/scriptableinputstream;1"].createInstance(Components.interfaces.nsIScriptableInputStream);
sis.init( obj_Transport ); sis.init(obj_Transport);
var output = sis.read( sis.available() ); var output = sis.read(sis.available());
if (text) output = output.replace(/\r/g,""); if (text) output = output.replace(/\r/g, "");
if (text && removeComments) { if (text && removeComments) {
output = output.replace(/^\/\/.*/g,""); output = output.replace(/^\/\/.*/g, "");
output = output.replace(/\n\/\/.*/g,""); output = output.replace(/\n\/\/.*/g, "");
output = output.replace(/\n\n+/g,"\n"); output = output.replace(/\n\n+/g, "\n");
} }
if (text) output = output.split(/\n/g); if (text) output = output.split(/\n/g);
return output; return output;
} catch (ex) { } catch (ex) {
this.addError("[wpdCommon.readFile]:\n -> str_Filename: "+str_Filename+"\n -> "+ex); this.addError("[wpdCommon.readFile]:\n -> str_Filename: " + str_Filename + "\n -> " + ex);
} }
return ""; return "";
}, },
// write the String Buffer (str_Buffer) to a file (str_Filename) // write the String Buffer (str_Buffer) to a file (str_Filename)
writeFile : function(str_Buffer,str_Filename) writeFile: function (str_Buffer, str_Filename) {
{
if (MODE_SIMULATE) return true; if (MODE_SIMULATE) return true;
try{ try {
var obj_File = Components.classes["@mozilla.org/file/local;1"].createInstance(Components.interfaces.nsILocalFile); var obj_File = Components.classes["@mozilla.org/file/local;1"].createInstance(Components.interfaces.nsILocalFile);
obj_File.initWithPath(str_Filename); obj_File.initWithPath(str_Filename);
if (!obj_File.exists()) if (!obj_File.exists()) obj_File.create(Components.interfaces.nsIFile.NORMAL_FILE_TYPE, 0666);
obj_File.create( Components.interfaces.nsIFile.NORMAL_FILE_TYPE, 0666 );
var obj_Transport = Components.classes["@mozilla.org/network/file-output-stream;1"].createInstance(Components.interfaces.nsIFileOutputStream); var obj_Transport = Components.classes["@mozilla.org/network/file-output-stream;1"].createInstance(Components.interfaces.nsIFileOutputStream);
@ -663,43 +618,39 @@ var wpdCommon = {
00002 Write by others 00002 Write by others
00001 Execute by others. 00001 Execute by others.
*/ */
obj_Transport.init( obj_File, 0x20 | 0x04 | 0x08, 064, 0 ); obj_Transport.init(obj_File, 0x20 | 0x04 | 0x08, 064, 0);
obj_Transport.write(str_Buffer,str_Buffer.length); obj_Transport.write(str_Buffer, str_Buffer.length);
obj_Transport.flush(); obj_Transport.flush();
obj_Transport.close(); obj_Transport.close();
return true; return true;
} catch (ex) { } catch (ex) {
this.addError("[wpdCommon.writeFile]:\n -> str_Filename: "+str_Filename+"\n -> "+ex); this.addError("[wpdCommon.writeFile]:\n -> str_Filename: " + str_Filename + "\n -> " + ex);
} }
return false; return false;
}, },
copyFile : function(sourcefile,destfile) copyFile: function (sourcefile, destfile) {
{
var destdir=this.getFilePath(destfile); var destdir = this.getFilePath(destfile);
destfile=this.getFileLeafName(destfile); destfile = this.getFileLeafName(destfile);
var aFile = Components.classes["@mozilla.org/file/local;1"] var aFile = Components.classes["@mozilla.org/file/local;1"].createInstance(Components.interfaces.nsILocalFile);
.createInstance(Components.interfaces.nsILocalFile);
if (!aFile) return false; if (!aFile) return false;
var aDir = Components.classes["@mozilla.org/file/local;1"] var aDir = Components.classes["@mozilla.org/file/local;1"].createInstance(Components.interfaces.nsILocalFile);
.createInstance(Components.interfaces.nsILocalFile);
if (!aDir) return false; if (!aDir) return false;
aFile.initWithPath(sourcefile); aFile.initWithPath(sourcefile);
aDir.initWithPath(destdir); aDir.initWithPath(destdir);
aFile.copyTo(aDir,destfile); aFile.copyTo(aDir, destfile);
return true; // Added by Dan S. for Zotero return true; // Added by Dan S. for Zotero
}, },
// download aSourceURL to aTargetFilename // download aSourceURL to aTargetFilename
// (works also on local files...) // (works also on local files...)
downloadFile : function (aSourceURL,aTargetFilename) downloadFile: function (aSourceURL, aTargetFilename) {
{
if (MODE_SIMULATE) return true; if (MODE_SIMULATE) return true;
try { try {
//new obj_URI object //new obj_URI object
@ -718,76 +669,72 @@ var wpdCommon = {
// set flags // set flags
const nsIWBP = Components.interfaces.nsIWebBrowserPersist; const nsIWBP = Components.interfaces.nsIWebBrowserPersist;
var flags = nsIWBP.PERSIST_FLAGS_REPLACE_EXISTING_FILES | var flags = nsIWBP.PERSIST_FLAGS_REPLACE_EXISTING_FILES | nsIWBP.PERSIST_FLAGS_FROM_CACHE;
nsIWBP.PERSIST_FLAGS_FROM_CACHE;
//nsIWBP.PERSIST_FLAGS_BYPASS_CACHE; //nsIWBP.PERSIST_FLAGS_BYPASS_CACHE;
obj_Persist.persistFlags = flags; obj_Persist.persistFlags = flags;
// has the url the same filetype like the file extension? // has the url the same filetype like the file extension?
//save file to target //save file to target
obj_Persist.saveURI(obj_URI,null,null,null,null,obj_TargetFile); try {
obj_Persist.saveURI(obj_URI, null, null, null, null, obj_TargetFile);
} catch(e if e.name === "NS_ERROR_XPC_NOT_ENOUGH_ARGS") {
// https://bugzilla.mozilla.org/show_bug.cgi?id=794602
// XXX Always use when we no longer support Firefox < 18
obj_Persist.saveURI(obj_URI, null, null, null, null, obj_TargetFile, null);
}
return true; return true;
} catch (ex) { } catch (ex) {
aSourceURL=this.removeGETFromURL(aSourceURL); 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 + "\n -> " + ex);
} }
return false; return false;
}, },
// get the integer preferences // get the integer preferences
getIntPrefs : function (branch) getIntPrefs: function (branch) {
{ var mPrefSvc = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefService);
var mPrefSvc=Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefService);
return mPrefSvc.getIntPref(branch); return mPrefSvc.getIntPref(branch);
}, },
// set the integer preferences // set the integer preferences
setIntPrefs : function (branch,value) setIntPrefs: function (branch, value) {
{ var mPrefSvc = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefService);
var mPrefSvc=Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefService); return mPrefSvc.setIntPref(branch, value);
return mPrefSvc.setIntPref(branch,value);
}, },
// get the integer preferences // get the integer preferences
getStrPrefs : function (branch) getStrPrefs: function (branch) {
{ var mPrefSvc = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefService);
var mPrefSvc=Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefService);
return mPrefSvc.getCharPref(branch); return mPrefSvc.getCharPref(branch);
}, },
// set the string preferences // set the string preferences
setStrPrefs : function (branch,value) setStrPrefs: function (branch, value) {
{ var mPrefSvc = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefService);
var mPrefSvc=Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefService); return mPrefSvc.setCharPref(branch, value);
return mPrefSvc.setCharPref(branch,value);
}, },
// get the string preferences // get the string preferences
getStrPrefsEx : function (branch) getStrPrefsEx: function (branch) {
{ var mPrefSvc = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefBranch);
var mPrefSvc=Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefBranch); return mPrefSvc.getComplexValue(branch, Components.interfaces.nsISupportsString).data;
return mPrefSvc.getComplexValue(branch,Components.interfaces.nsISupportsString).data;
}, },
// set the string preferences // set the string preferences
setStrPrefsEx : function (branch,value) setStrPrefsEx: function (branch, value) {
{
var str = Components.classes["@mozilla.org/supports-string;1"].createInstance(Components.interfaces.nsISupportsString); var str = Components.classes["@mozilla.org/supports-string;1"].createInstance(Components.interfaces.nsISupportsString);
str.data = value; str.data = value;
var mPrefSvc=Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefBranch); var mPrefSvc = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefBranch);
return mPrefSvc.setComplexValue(branch,Components.interfaces.nsISupportsString,str); return mPrefSvc.setComplexValue(branch, Components.interfaces.nsISupportsString, str);
}, },
// Get the preferences branch ("browser.download." for normal 'save' mode)... // Get the preferences branch ("browser.download." for normal 'save' mode)...
setBoolPrefs : function (branch,value) setBoolPrefs: function (branch, value) {
{ var mPrefSvc = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefService);
var mPrefSvc=Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefService); return mPrefSvc.setBoolPref(branch, value);
return mPrefSvc.setBoolPref(branch,value);
} }
}; };

File diff suppressed because it is too large Load Diff

View File

@ -965,7 +965,13 @@ Zotero.Sync.Storage.WebDAV = (function () {
.createInstance(nsIWBP); .createInstance(nsIWBP);
wbp.persistFlags = nsIWBP.PERSIST_FLAGS_BYPASS_CACHE; wbp.persistFlags = nsIWBP.PERSIST_FLAGS_BYPASS_CACHE;
wbp.progressListener = listener; wbp.progressListener = listener;
try {
wbp.saveURI(uri, null, null, null, null, destFile); wbp.saveURI(uri, null, null, null, null, destFile);
} catch(e if e.name === "NS_ERROR_XPC_NOT_ENOUGH_ARGS") {
// https://bugzilla.mozilla.org/show_bug.cgi?id=794602
// XXX Always use when we no longer support Firefox < 18
wbp.saveURI(uri, null, null, null, null, destFile, null);
}
} }
catch (e) { catch (e) {
request.error(e); request.error(e);

View File

@ -861,7 +861,13 @@ Zotero.Sync.Storage.ZFS = (function () {
.createInstance(nsIWBP); .createInstance(nsIWBP);
wbp.persistFlags = nsIWBP.PERSIST_FLAGS_BYPASS_CACHE; wbp.persistFlags = nsIWBP.PERSIST_FLAGS_BYPASS_CACHE;
wbp.progressListener = listener; wbp.progressListener = listener;
try {
wbp.saveURI(uri, null, null, null, null, destFile); wbp.saveURI(uri, null, null, null, null, destFile);
} catch(e if e.name === "NS_ERROR_XPC_NOT_ENOUGH_ARGS") {
// https://bugzilla.mozilla.org/show_bug.cgi?id=794602
// XXX Always use when we no longer support Firefox < 18
wbp.saveURI(uri, null, null, null, null, destFile, null);
}
} }
catch (e) { catch (e) {
Zotero.Sync.Storage.EventManager.error(e); Zotero.Sync.Storage.EventManager.error(e);

View File

@ -595,6 +595,17 @@ Zotero.Translate.Sandbox = {
} }
} }
} }
// Remap attachment (but not link) URLs
var properToProxy = translate.translator[0].properToProxy;
if(properToProxy && item.attachments) {
for(var i=0; i<item.attachments.length; i++) {
var attachment = item.attachments[i];
if(attachment.snapshot !== false && attachment.url) {
attachment.url = properToProxy(attachment.url);
}
}
}
} }
// call super // call super

View File

@ -35,6 +35,7 @@ const BOMs = {
} }
Components.utils.import("resource://gre/modules/NetUtil.jsm"); Components.utils.import("resource://gre/modules/NetUtil.jsm");
Components.utils.import("resource://gre/modules/Services.jsm");
Zotero.Translate.DOMWrapper = new function() { Zotero.Translate.DOMWrapper = new function() {
/* /*

View File

@ -272,6 +272,45 @@ Zotero.Utilities = {
return doi ? doi[0] : null; return doi ? doi[0] : null;
}, },
/**
* Clean and validate ISBN.
* Return isbn if valid, otherwise return false
*/
"cleanISBN":function(/**String*/ isbn) {
isbn = isbn.replace(/[^x\d]+/ig, '').toUpperCase();
if(isbn.length == 10) {
// Verify ISBN-10 checksum
var sum = 0;
for (var i = 0; i < 9; i++) {
if(isbn[i] == 'X') return false; //X can only be a check digit
sum += isbn[i] * (10-i);
}
//check digit might be 'X'
sum += (isbn[9] == 'X')? 10 : isbn[9]*1;
return (sum % 11 == 0) ? isbn : false;
}
isbn = isbn.replace(/X/g, ''); //get rid of Xs
if(isbn.length == 13) {
// ISBN-13 should start with 978 or 979 i.e. GS1 for book publishing industry
var prefix = isbn.slice(0,3);
if (prefix != "978" && prefix != "979") return false;
// Verify checksum
var sum = 0;
for (var i = 0; i < 12; i+=2) sum += isbn[i]*1; //to make sure it's int
for (i = 1; i < 12; i+=2) sum += isbn[i]*3;
sum += isbn[12]*1; //add the check digit
return (sum % 10 == 0 )? isbn : false;
}
return false;
},
/** /**
* Convert plain text to HTML by replacing special characters and replacing newlines with BRs or * Convert plain text to HTML by replacing special characters and replacing newlines with BRs or
* P tags * P tags

View File

@ -1253,6 +1253,10 @@ Components.utils.import("resource://gre/modules/Services.jsm");
*/ */
this.getInstalledExtensions = function(callback) { this.getInstalledExtensions = function(callback) {
function onHaveInstalledAddons(installed) { function onHaveInstalledAddons(installed) {
installed.sort(function(a, b) {
return ((a.appDisabled || a.userDisabled) ? 1 : 0) -
((b.appDisabled || b.userDisabled) ? 1 : 0);
});
var addons = []; var addons = [];
for each(var addon in installed) { for each(var addon in installed) {
switch (addon.id) { switch (addon.id) {
@ -1262,7 +1266,9 @@ Components.utils.import("resource://gre/modules/Services.jsm");
} }
addons.push(addon.name + " (" + addon.version addons.push(addon.name + " (" + addon.version
+ (addon.type != 2 ? ", " + addon.type : "") + ")"); + (addon.type != 2 ? ", " + addon.type : "")
+ ((addon.appDisabled || addon.userDisabled) ? ", disabled" : "")
+ ")");
} }
callback(addons); callback(addons);
} }

View File

@ -819,6 +819,11 @@ function ChromeExtensionHandler() {
var fileURI = ph.newFileURI(file); var fileURI = ph.newFileURI(file);
} }
var channel = ioService.newChannelFromURI(fileURI); var channel = ioService.newChannelFromURI(fileURI);
//set originalURI so that it seems like we're serving from zotero:// protocol
//this is necessary to allow url() links to work from within css files
//otherwise they try to link to files on the file:// protocol, which is not allowed
channel.originalURI = uri;
return channel; return channel;
} }
catch (e) { catch (e) {

View File

@ -17,7 +17,7 @@
"alias": "Google Scholar", "alias": "Google Scholar",
"_urlTemplate": "http://scholar.google.com/scholar?as_q=&as_epq={z:title}&as_occt=title&as_sauthors={rft:aufirst?}+{rft:aulast?}&as_ylo={z:year?}&as_yhi={z:year?}&as_sdt=1.&as_sdtp=on&as_sdtf=&as_sdts=22&", "_urlTemplate": "http://scholar.google.com/scholar?as_q=&as_epq={z:title}&as_occt=title&as_sauthors={rft:aufirst?}+{rft:aulast?}&as_ylo={z:year?}&as_yhi={z:year?}&as_sdt=1.&as_sdtp=on&as_sdtf=&as_sdts=22&",
"description": "Google Scholar Search", "description": "Google Scholar Search",
"hidden": true, "hidden": false,
"_urlParams": [], "_urlParams": [],
"_urlNamespaces": { "_urlNamespaces": {
"rft": "info:ofi/fmt:kev:mtx:journal", "rft": "info:ofi/fmt:kev:mtx:journal",
@ -25,19 +25,5 @@
"": "http://a9.com/-/spec/opensearch/1.1/" "": "http://a9.com/-/spec/opensearch/1.1/"
}, },
"_iconSourceURI": "http://scholar.google.com/favicon.ico" "_iconSourceURI": "http://scholar.google.com/favicon.ico"
},
{
"name": "Pubget Lookup",
"alias": "Pubget",
"_urlTemplate": "http://pubget.com/openurl?rft.title={rft:title}&rft.issue={rft:issue?}&rft.spage={rft:spage?}&rft.epage={rft:epage?}&rft.issn={rft:issn?}&rft.jtitle={rft:stitle?}&doi={z:DOI?}",
"description": "Pubget Article Lookup",
"hidden": true,
"_urlParams": [],
"_urlNamespaces": {
"rft": "info:ofi/fmt:kev:mtx:journal",
"z": "http://www.zotero.org/namespaces/openSearch#",
"": "http://a9.com/-/spec/opensearch/1.1/"
},
"_iconSourceURI": "http://pubget.com/favicon.ico"
} }
] ]