www

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | Submodules | README | LICENSE

commit 6efd6d2cc42d65bab7c462156643e2856b11e103
parent af080fe3847e92ff67e412032b9fbaa848dc538b
Author: Simon Kornblith <simon@simonster.com>
Date:   Tue,  8 Aug 2006 23:00:33 +0000

closes #99, add options for export


Diffstat:
Achrome/chromeFiles/content/scholar/exportOptions.js | 73+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Achrome/chromeFiles/content/scholar/exportOptions.xul | 15+++++++++++++++
Mchrome/chromeFiles/content/scholar/fileInterface.js | 57++++++++++++++-------------------------------------------
Mchrome/chromeFiles/content/scholar/xpcom/translate.js | 47++++++++++++++++++++++++++++++++++++++++-------
Mchrome/chromeFiles/locale/en-US/scholar/scholar.dtd | 6++++--
Mchrome/chromeFiles/locale/en-US/scholar/scholar.properties | 7+++++--
Mscrapers.sql | 54+++++++++++++++++++++++++++++++-----------------------
7 files changed, 182 insertions(+), 77 deletions(-)

diff --git a/chrome/chromeFiles/content/scholar/exportOptions.js b/chrome/chromeFiles/content/scholar/exportOptions.js @@ -0,0 +1,72 @@ +////////////////////////////////////////////////////////////////////////////// +// +// Scholar_File_Interface_Export +// +////////////////////////////////////////////////////////////////////////////// + +// Class to provide options for export + +Scholar_File_Interface_Export = new function() { + var _options; + + this.init = init; + this.accept = accept; + this.cancel = cancel; + + /* + * add options to export + */ + function init() { + _options = window.arguments[0].options; + + // add options to dialog + var dialog = document.getElementById("scholar-export-options"); + for(var option in _options) { + var defValue = _options[option]; + + // get readable name for option + try { + var optionLabel = Scholar.getString("exportOptions."+option); + } catch(e) { + var optionLabel = option; + } + + // right now, option interface supports only boolean values, which + // it interprets as checkboxes + Scholar.debug(option+" ("+optionLabel+") = "+defValue+" ("+typeof(defValue)+")"); + if(typeof(defValue) == "boolean") { + var checkbox = document.createElement("checkbox"); + checkbox.setAttribute("id", option); + checkbox.setAttribute("label", optionLabel); + checkbox.setAttribute("checked", (defValue ? "true" : "false")); + dialog.appendChild(checkbox); + } + } + } + + /* + * make option array reflect status + */ + function accept() { + for(var option in _options) { + var defValue = _options[option]; + var element = document.getElementById(option); + + if(typeof(defValue) == "bool") { + if(element.checked == "true") { + _options[option] = true; + } else { + _options[option] = false; + } + } + } + Scholar.debug(_options); + } + + /* + * make option array reflect status + */ + function cancel() { + window.arguments[0].options = false; + } +} +\ No newline at end of file diff --git a/chrome/chromeFiles/content/scholar/exportOptions.xul b/chrome/chromeFiles/content/scholar/exportOptions.xul @@ -0,0 +1,14 @@ +<?xml version="1.0"?> +<?xml-stylesheet href="chrome://global/skin/" type="text/css"?> +<!DOCTYPE window SYSTEM "chrome://scholar/locale/scholar.dtd"> +<dialog xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" + title="&exportOptions.title;" buttons="cancel,accept" + ondialogaccept="Scholar_File_Interface_Export.accept()" + ondialogcancel="Scholar_File_Interface_Export.cancel()" + id="scholar-export-options" + onload="Scholar_File_Interface_Export.init()"> + +<script src="include.js"/> +<script src="exportOptions.js"/> + +</dialog> +\ No newline at end of file diff --git a/chrome/chromeFiles/content/scholar/fileInterface.js b/chrome/chromeFiles/content/scholar/fileInterface.js @@ -23,8 +23,7 @@ Scholar_File_Interface = new function() { if (rv == nsIFilePicker.returnOK || rv == nsIFilePicker.returnReplace) { translation.setLocation(fp.file); translation.setTranslator(translators[fp.filterIndex]); - //translation.setHandler("itemCount", _exportItemCount); - //translation.setHandler("itemDone", _exportItemDone); + translation.setHandler("options", _exportOptions); translation.setHandler("done", _exportDone); _disableUnresponsive(); Scholar_File_Interface.Progress.show( @@ -36,18 +35,19 @@ Scholar_File_Interface = new function() { } /* - * set progress indicator length - */ - function _exportItemCount(obj, number) { - Scholar.debug("count called with "+number); - Scholar_File_Interface.Progress.setNumber(number); - } - - /* - * Increment progress for each item exported + * closes items exported indicator */ - function _exportItemDone(obj, item) { - Scholar_File_Interface.Progress.increment(); + function _exportOptions(obj, options) { + var io = {options:options} + window.openDialog("chrome://scholar/content/exportOptions.xul", + "_blank","chrome,modal,centerscreen", io); + if(io.options) { + // refocus dialog + Scholar_File_Interface.Progress.show(); + return options; + } else { + return false; + } } /* @@ -58,7 +58,6 @@ Scholar_File_Interface = new function() { _restoreUnresponsive(); } - /* * Creates Scholar.Translate instance and shows file picker for file import */ @@ -105,7 +104,6 @@ Scholar_File_Interface = new function() { * "items imported" indicator, too. */ function _importItemDone(obj, item) { - //Scholar_File_Interface.Progress.increment(); _importCollection.addItem(item.getID()); } @@ -256,12 +254,11 @@ Scholar_File_Interface.Progress = new function() { var _loadHeadline, _loadNumber, _outOf, _callback; this.show = show; - //this.setNumber = setNumber; - //this.increment = increment; this.close = close; function show(headline, callback) { if(_windowLoading || _windowLoaded) { // already loading or loaded + _progressWindow.focus(); return false; } _windowLoading = true; @@ -275,26 +272,6 @@ Scholar_File_Interface.Progress = new function() { _progressWindow.addEventListener("pageshow", _onWindowLoaded, false); } - /*function setNumber(number) { - _outOf = number; - if(_windowLoaded) { - var progressMeter = _progressWindow.document.getElementById("progress-indicator"); - progressMeter.mode = "normal"; - progressMeter.value = "0%"; - } - } - - function increment() { - _loadNumber++; - if(_windowLoaded) { - _progressWindow.document.getElementById("progress-items").value = _loadNumber; - if(_outOf) { - _progressWindow.document.getElementById("progress-indicator").value = ((_loadNumber/_outOf)*100).toString()+"%"; - } - _progressWindow.getSelection(); - } - }*/ - function close() { _windowLoaded = false; try { @@ -307,12 +284,6 @@ Scholar_File_Interface.Progress = new function() { _windowLoaded = true; // do things we delayed because the winodw was loading - /*if(_outOf) { - var progressMeter = _progressWindow.document.getElementById("progress-indicator"); - progressMeter.mode = "normal"; - progressMeter.value = ((_loadNumber/_outOf)*100).toString()+"%"; - } - _progressWindow.document.getElementById("progress-items").value = _loadNumber;*/ _progressWindow.document.getElementById("progress-label").value = _loadHeadline; if(_callback) { diff --git a/chrome/chromeFiles/content/scholar/xpcom/translate.js b/chrome/chromeFiles/content/scholar/xpcom/translate.js @@ -216,6 +216,12 @@ Scholar.Translate.prototype.setTranslator = function(translator) { * as the first argument, all handlers will be passed the current function. the * second argument is dependent on the handler. * + * options + * valid: export + * called: when options requiring user interaction are available + * passed: an associative array of options and default values + * returns: an associative array of options + * * select * valid: web * called: when the user needs to select from a list of available items @@ -291,13 +297,10 @@ Scholar.Translate.prototype.getTranslators = function() { } /* - * gets translator options to be displayed in a dialog - * - * NOT IMPLEMENTED + * finds applicable translators from a list. if the second argument is given, + * extension-based exclusion is inverted, so that only detectCode is used to + * determine if a translator can be run. */ -Scholar.Translate.prototype.displayOptions = function() { -} - Scholar.Translate.prototype._findTranslators = function(translators, ignoreExtensions) { var possibleTranslators = new Array(); for(var i in translators) { @@ -323,6 +326,9 @@ Scholar.Translate.prototype._findTranslators = function(translators, ignoreExten return possibleTranslators; } +/* + * loads a translator into a sandbox + */ Scholar.Translate.prototype._loadTranslator = function() { if(!this._sandbox || this.type == "search") { // create a new sandbox if none exists, or for searching (so that it's @@ -367,7 +373,16 @@ Scholar.Translate.prototype.translate = function() { return; } - this._sandbox.Scholar.scraperName = this.translator[0].label; + + // hack to see if there are any options, bc length does not work on objects + for(var i in this._displayOptions) { + // run handler for options if there are any + if(!(this._displayOptions = this._runHandler("options", this._displayOptions))) { + this._translationComplete(true); + return false; + } + break; + } var returnValue; if(this.type == "web") { @@ -461,6 +476,8 @@ Scholar.Translate.prototype._generateSandbox = function() { this._sandbox.Scholar.configure = function(option, value) {me._configure(option, value) }; // for adding displayed options this._sandbox.Scholar.addOption = function(option, value) {me._addOption(option, value) }; + // for getting the value of displayed options + this._sandbox.Scholar.getOption = function(option) { return me._getOption(option) }; // for loading other translators and accessing their methods this._sandbox.Scholar.loadTranslator = function(type, translatorID) { @@ -488,6 +505,7 @@ Scholar.Translate.prototype._generateSandbox = function() { safeTranslator.setItem = function(arg) { return translation.setItem(arg) }; safeTranslator.setBrowser = function(arg) { return translation.setBrowser(arg) }; safeTranslator.setHandler = function(arg1, arg2) { translation.setHandler(arg1, arg2) }; + safeTranslator.setString = function(arg) { translation.setString(arg) }; safeTranslator.setTranslator = function(arg) { return translation.setTranslator(arg) }; safeTranslator.getTranslators = function() { return translation.getTranslators() }; safeTranslator.translate = function() { return translation.translate() }; @@ -521,6 +539,11 @@ Scholar.Translate.prototype._canTranslate = function(translator, ignoreExtension // if we're ignoring extensions, that means we already tried // everything without ignoring extensions and it didn't work canTranslate = !canTranslate; + + // if a translator has no detectCode, don't offer it as an option + if(!translator.detectCode) { + return false; + } } } else { var canTranslate = true; @@ -631,6 +654,16 @@ Scholar.Translate.prototype._addOption = function(option, value) { } /* + * gets translator options that were displayed in a dialog + * + * called as getOption() in detect code + * + */ +Scholar.Translate.prototype._getOption = function(option) { + return this._displayOptions[option]; +} + +/* * makes translation API wait until done() has been called from the translator * before executing _translationComplete * diff --git a/chrome/chromeFiles/locale/en-US/scholar/scholar.dtd b/chrome/chromeFiles/locale/en-US/scholar/scholar.dtd @@ -51,4 +51,6 @@ <!ENTITY bibliography.copyToClipboard.label "Copy to Clipboard"> <!ENTITY bibliography.print.label "Print"> -<!ENTITY progress.title "Progress"> -\ No newline at end of file +<!ENTITY progress.title "Progress"> + +<!ENTITY exportOptions.title "Export..."> +\ No newline at end of file diff --git a/chrome/chromeFiles/locale/en-US/scholar/scholar.properties b/chrome/chromeFiles/locale/en-US/scholar/scholar.properties @@ -99,4 +99,7 @@ searchOperator.doesNotContain = does not contain searchOperator.lessThan = is less than searchOperator.greaterThan = is greater than searchOperator.isBefore = is before -searchOperator.isAfter = is after -\ No newline at end of file +searchOperator.isAfter = is after + +exportOptions.exportNotes = Export Notes +exportOptions.exportFileData = Export Files +\ No newline at end of file diff --git a/scrapers.sql b/scrapers.sql @@ -1,4 +1,4 @@ --- 40 +-- 41 -- Set the following timestamp to the most recent scraper update date REPLACE INTO "version" VALUES ('repository', STRFTIME('%s', '2006-08-08 17:12:00')); @@ -2738,7 +2738,6 @@ function doSearch(item) { REPLACE INTO "translators" VALUES ('0e2235e7-babf-413c-9acf-f27cce5f059c', '2006-07-05 23:40:00', 3, 'MODS (XML)', 'Simon Kornblith', 'xml', 'Scholar.addOption("exportNotes", true); -Scholar.addOption("exportFileData", true); function detectImport() { var read = Scholar.read(512); @@ -3003,10 +3002,12 @@ function doExport() { /** NOTES **/ - for(var j in item.notes) { - // Add note tag - var note = <note type="content">{item.notes[j].note}</note>; - mods.note += note; + if(Scholar.getOption("exportNotes")) { + for(var j in item.notes) { + // Add note tag + var note = <note type="content">{item.notes[j].note}</note>; + mods.note += note; + } } /** TAGS **/ @@ -3335,6 +3336,9 @@ function doExport() { type = "Document"; } else if(item.itemType == "note") { type = "Memo"; + if(!Scholar.getOption("exportNotes")) { + continue; + } } if(type) { Scholar.RDF.addStatement(resource, rdf+"type", n.bib+type, false); @@ -3530,22 +3534,24 @@ function doExport() { /** NOTES **/ - for(var j in item.notes) { - var noteResource = itemResources[item.notes[j].itemID]; - - // add note tag - Scholar.RDF.addStatement(noteResource, rdf+"type", n.bib+"Memo", false); - // add note value - Scholar.RDF.addStatement(noteResource, rdf+"value", item.notes[j].note, true); - // add relationship between resource and note - Scholar.RDF.addStatement(resource, n.dcterms+"isReferencedBy", noteResource, false); + if(Scholar.getOption("exportNotes")) { + for(var j in item.notes) { + var noteResource = itemResources[item.notes[j].itemID]; + + // add note tag + Scholar.RDF.addStatement(noteResource, rdf+"type", n.bib+"Memo", false); + // add note value + Scholar.RDF.addStatement(noteResource, rdf+"value", item.notes[j].note, true); + // add relationship between resource and note + Scholar.RDF.addStatement(resource, n.dcterms+"isReferencedBy", noteResource, false); + + // Add see also info to RDF + generateSeeAlso(resource, item.notes[j].seeAlso); + } - // Add see also info to RDF - generateSeeAlso(resource, item.notes[j].seeAlso); - } - - if(item.note) { - Scholar.RDF.addStatement(resource, rdf+"value", item.note, true); + if(item.note) { + Scholar.RDF.addStatement(resource, rdf+"value", item.note, true); + } } /** TAGS **/ @@ -4326,8 +4332,10 @@ function doExport() { } // notes - for(var j in item.notes) { - addTag("N1", item.notes[j].note); + if(Scholar.getOption("exportNotes")) { + for(var j in item.notes) { + addTag("N1", item.notes[j].note.replace(/[\r\n]/g, " ")); + } } // tags