diff --git a/chrome/chromeFiles/content/scholar/bibliography.xul b/chrome/chromeFiles/content/scholar/bibliography.xul index 04debab5d..17f3da96a 100644 --- a/chrome/chromeFiles/content/scholar/bibliography.xul +++ b/chrome/chromeFiles/content/scholar/bibliography.xul @@ -20,7 +20,8 @@ - + + diff --git a/chrome/chromeFiles/content/scholar/fileInterface.js b/chrome/chromeFiles/content/scholar/fileInterface.js index 26610d35d..f342a0663 100644 --- a/chrome/chromeFiles/content/scholar/fileInterface.js +++ b/chrome/chromeFiles/content/scholar/fileInterface.js @@ -198,8 +198,14 @@ Scholar_File_Interface = new function() { var newDialog = window.openDialog("chrome://scholar/content/bibliography.xul", "_blank","chrome,modal,centerscreen", io); + // determine output format + var format = "HTML"; + if(io.output == "save-as-rtf") { + format = "RTF"; + } + // generate bibliography - var bibliography = Scholar.Cite.getBibliography(io.style, items); + var bibliography = Scholar.Cite.getBibliography(io.style, items, format); if(io.output == "print") { // printable bibliography, using a hidden browser @@ -232,19 +238,8 @@ Scholar_File_Interface = new function() { Scholar.Browser.deleteHiddenBrowser(browser); bibliographyStream.close(); } else if(io.output == "save-as-html") { - // savable bibliography, using a file stream - const nsIFilePicker = Components.interfaces.nsIFilePicker; - var fp = Components.classes["@mozilla.org/filepicker;1"] - .createInstance(nsIFilePicker); - fp.init(window, "Save Bibliography", nsIFilePicker.modeSave); - fp.appendFilters(nsIFilePicker.filterHTML); - var rv = fp.show(); - if (rv == nsIFilePicker.returnOK || rv == nsIFilePicker.returnReplace) { - // open file - var fStream = Components.classes["@mozilla.org/network/file-output-stream;1"]. - createInstance(Components.interfaces.nsIFileOutputStream); - fStream.init(fp.file, 0x02 | 0x08 | 0x20, 0664, 0); // write, create, truncate - + var fStream = _saveBibliography("HTML"); + if(fStream !== false) { var html = ""; html +='\n'; html +='\n'; @@ -257,7 +252,12 @@ Scholar_File_Interface = new function() { html +='\n'; html +='\n'; fStream.write(html, html.length); - + fStream.close(); + } + } else if(io.output == "save-as-rtf") { + var fStream = _saveBibliography("RTF"); + if(fStream !== false) { + fStream.write(bibliography, bibliography.length); fStream.close(); } } else if(io.output == "copy-to-clipboard") { @@ -278,6 +278,31 @@ Scholar_File_Interface = new function() { clipboardService.setData(transferable, null, Components.interfaces.nsIClipboard.kGlobalClipboard); } } + + function _saveBibliography(format) { + // savable bibliography, using a file stream + const nsIFilePicker = Components.interfaces.nsIFilePicker; + var fp = Components.classes["@mozilla.org/filepicker;1"] + .createInstance(nsIFilePicker); + fp.init(window, "Save Bibliography", nsIFilePicker.modeSave); + + if(format == "RTF") { + fp.appendFilter("RTF", "*.rtf"); + } else { + fp.appendFilters(nsIFilePicker.filterHTML); + } + + var rv = fp.show(); + if (rv == nsIFilePicker.returnOK || rv == nsIFilePicker.returnReplace) { + // open file + var fStream = Components.classes["@mozilla.org/network/file-output-stream;1"]. + createInstance(Components.interfaces.nsIFileOutputStream); + fStream.init(fp.file, 0x02 | 0x08 | 0x20, 0664, 0); // write, create, truncate + return fStream; + } else { + return false; + } + } } // Handles the display of a progress indicator diff --git a/chrome/chromeFiles/content/scholar/xpcom/cite.js b/chrome/chromeFiles/content/scholar/xpcom/cite.js index 517e1a107..eccf77f51 100644 --- a/chrome/chromeFiles/content/scholar/xpcom/cite.js +++ b/chrome/chromeFiles/content/scholar/xpcom/cite.js @@ -23,7 +23,7 @@ Scholar.Cite = new function() { return stylesObject; } - function getBibliography(cslID, items) { + function getBibliography(cslID, items, format) { // get style var sql = "SELECT csl FROM csl WHERE cslID = ?"; var style = Scholar.DB.valueQuery(sql, [cslID]); @@ -37,7 +37,7 @@ Scholar.Cite = new function() { // create a CSL instance var cslInstance = new CSL(style); // return bibliography - return cslInstance.createBibliography(itemArrays, "HTML"); + return cslInstance.createBibliography(itemArrays, format); } } @@ -68,7 +68,6 @@ CSL = function(csl) { } // load defaults from CSL this._parseFieldDefaults(this._csl.defaults); - Scholar.debug(this._defaults); // decide whether to parse bibliography, or, if none exists, citation if(this._csl.bibliography.length()) { @@ -106,8 +105,6 @@ CSL = function(csl) { this._serializations[0] = new Object(); this._types[0] = this._parseFields(this._itemElement.children(), 0); } - - Scholar.debug(this._types); } /* @@ -131,6 +128,19 @@ CSL.prototype.createBibliography = function(items, format) { // process items var output = ""; + + if(format == "HTML") { + var style = ""; + if(this._opt.hangingIndent) { + style = "margin-left:0.5in;text-indent:-0.5in;"; + } + } else if(format == "RTF") { + output += "{\\rtf\\mac\\ansicpg10000{\\fonttbl\\f0\\froman Times New Roman;}{\\colortbl;\\red255\\green255\\blue255;}\\pard\\f0"; + if(this._opt.hangingIndent) { + output += "\\li720\\fi-720"; + } + } + for(var i in items) { var item = items[i]; if(item.itemType == "note" || item.itemType == "file") { @@ -185,19 +195,31 @@ CSL.prototype.createBibliography = function(items, format) { string = string + this._opt.format.suffix; } } - - if(format == "HTML") { - output += '

'; - if(this._class == "note") { - // add superscript number for footnotes - output += (parseInt(i)+1).toString()+". "; + if(this._class == "note") { + // add superscript number for footnotes + string += (parseInt(i)+1).toString()+". "; + } + + // add line feeds + if(format == "HTML") { + output += "'; + output += ">"+string+"

"; + } else if(format == "RTF") { + output += string+"\\\r\n\\\r\n"; } } + if(format == "RTF") { + // drop last 6 characters of output (last two returns) + output = output.substr(0, output.length-6)+"}"; + } + return output; } @@ -687,17 +709,15 @@ CSL.prototype._processDate = function(string) { * formats a string according to the cs-format attributes on element */ CSL.prototype._formatString = function(element, string, format) { - if(element["text-transform"]) { - if(element["text-transform"] == "lowercase") { - // all lowercase - string = string.toLowerCase(); - } else if(element["text-transform"] == "uppercase") { - // all uppercase - string = string.toUpperCase(); - } else if(element["text-transform"] == "capitalize") { - // capitalize first - string = string[0].toUpperCase()+string.substr(1); - } + if(element["text-transform"] == "lowercase") { + // all lowercase + string = string.toLowerCase(); + } else if(element["text-transform"] == "uppercase") { + // all uppercase + string = string.toUpperCase(); + } else if(element["text-transform"] == "capitalize") { + // capitalize first + string = string[0].toUpperCase()+string.substr(1); } if(format == "HTML") { @@ -714,6 +734,16 @@ CSL.prototype._formatString = function(element, string, format) { if(style) { string = ''+string+''; } + } else if(format == "RTF") { + if(element["font-style"] == "oblique" || element["font-style"] == "italic") { + string = "\\i "+string+"\\i0 "; + } + if(element["font-variant"] == "small-caps") { + string = "\\scaps "+string+"\\scaps0 "; + } + if(element["font-weight"] == "bold") { + string = "\\b "+string+"\\b0 "; + } } if(format != "compare" && element.prefix) { diff --git a/chrome/chromeFiles/locale/en-US/scholar/scholar.dtd b/chrome/chromeFiles/locale/en-US/scholar/scholar.dtd index aa4eaaaa2..370c1ce6d 100644 --- a/chrome/chromeFiles/locale/en-US/scholar/scholar.dtd +++ b/chrome/chromeFiles/locale/en-US/scholar/scholar.dtd @@ -48,7 +48,8 @@ - + + diff --git a/scrapers.sql b/scrapers.sql index 4f66e21cd..bfa3f6c95 100644 --- a/scrapers.sql +++ b/scrapers.sql @@ -1,4 +1,4 @@ --- 47 +-- 48 -- Set the following timestamp to the most recent scraper update date REPLACE INTO "version" VALUES ('repository', STRFTIME('%s', '2006-08-11 11:18:00')); @@ -4990,7 +4990,7 @@ REPLACE INTO "csl" VALUES('http://purl.org/net/xbiblio/csl/styles/apa.csl', '200 - +