c64e5c841f
closes #100, migrate ingester to Scholar.Translate closes #88, migrate scrapers away from RDF closes #9, pull out LC subject heading tags references #87, add fromArray() and toArray() methods to item objects API changes: all translation (import/export/web) now goes through Scholar.Translate all Scholar-specific functions in scrapers start with "Scholar." rather than the jumbled up piggy bank un-namespaced confusion scrapers now longer specify items through RDF (the beginning of an item.fromArray()-like function exists in Scholar.Translate.prototype._itemDone()) scrapers can be any combination of import, export, and web (type is the sum of 1/2/4 respectively) scrapers now contain functions (doImport, doExport, doWeb) rather than loose code scrapers can call functions in other scrapers or just call the function to translate itself export accesses items item-by-item, rather than accepting a huge array of items MARC functions are now in the MARC import translator, and accessed by the web translators new features: import now works rudimentary RDF (unqualified dublin core only), RIS, and MARC import translators are implemented (although they are a little picky with respect to file extensions at the moment) items appear as they are scraped MARC import translator pulls out tags, although this seems to slow things down no icon appears next to a the URL when Scholar hasn't detected metadata, since this seemed somewhat confusing apologizes for the size of this diff. i figured if i was going to re-write the API, i might as well do it all at once and get everything working right.
152 lines
4.2 KiB
JavaScript
152 lines
4.2 KiB
JavaScript
const SCHOLAR_CONTRACTID = '@chnm.gmu.edu/Scholar;1';
|
|
const SCHOLAR_CLASSNAME = 'Scholar for Firefox';
|
|
const SCHOLAR_CID = Components.ID('{e4c61080-ec2d-11da-8ad9-0800200c9a66}');
|
|
const SCHOLAR_IID = Components.interfaces.chnmIScholarService;
|
|
|
|
const Cc = Components.classes;
|
|
const Ci = Components.interfaces;
|
|
|
|
// Assign the global scope to a variable to passed via wrappedJSObject
|
|
var ScholarWrapped = this;
|
|
|
|
|
|
/********************************************************************
|
|
* Include the core objects to be stored within XPCOM
|
|
*********************************************************************/
|
|
|
|
Cc["@mozilla.org/moz/jssubscript-loader;1"]
|
|
.getService(Ci.mozIJSSubScriptLoader)
|
|
.loadSubScript("chrome://scholar/content/xpcom/scholar.js");
|
|
|
|
Cc["@mozilla.org/moz/jssubscript-loader;1"]
|
|
.getService(Ci.mozIJSSubScriptLoader)
|
|
.loadSubScript("chrome://scholar/content/xpcom/db.js");
|
|
|
|
Cc["@mozilla.org/moz/jssubscript-loader;1"]
|
|
.getService(Ci.mozIJSSubScriptLoader)
|
|
.loadSubScript("chrome://scholar/content/xpcom/schema.js");
|
|
|
|
Cc["@mozilla.org/moz/jssubscript-loader;1"]
|
|
.getService(Ci.mozIJSSubScriptLoader)
|
|
.loadSubScript("chrome://scholar/content/xpcom/data_access.js");
|
|
|
|
Cc["@mozilla.org/moz/jssubscript-loader;1"]
|
|
.getService(Ci.mozIJSSubScriptLoader)
|
|
.loadSubScript("chrome://scholar/content/xpcom/notifier.js");
|
|
|
|
Cc["@mozilla.org/moz/jssubscript-loader;1"]
|
|
.getService(Ci.mozIJSSubScriptLoader)
|
|
.loadSubScript("chrome://scholar/content/xpcom/history.js");
|
|
|
|
Cc["@mozilla.org/moz/jssubscript-loader;1"]
|
|
.getService(Ci.mozIJSSubScriptLoader)
|
|
.loadSubScript("chrome://scholar/content/xpcom/ingester.js");
|
|
|
|
Cc["@mozilla.org/moz/jssubscript-loader;1"]
|
|
.getService(Ci.mozIJSSubScriptLoader)
|
|
.loadSubScript("chrome://scholar/content/xpcom/translate.js");
|
|
|
|
Cc["@mozilla.org/moz/jssubscript-loader;1"]
|
|
.getService(Ci.mozIJSSubScriptLoader)
|
|
.loadSubScript("chrome://scholar/content/xpcom/utilities.js");
|
|
|
|
/********************************************************************/
|
|
|
|
|
|
// Initialize the Scholar service
|
|
//
|
|
// This runs when ScholarService is first requested.
|
|
// Calls to other XPCOM components must be in here rather than in top-level
|
|
// code, as other components may not have yet been initialized.
|
|
function setupService(){
|
|
Scholar.init();
|
|
}
|
|
|
|
function ScholarService(){
|
|
this.wrappedJSObject = ScholarWrapped.Scholar;
|
|
setupService();
|
|
}
|
|
|
|
|
|
/**
|
|
* Convenience method to replicate window.alert()
|
|
**/
|
|
function alert(msg){
|
|
Cc["@mozilla.org/embedcomp/prompt-service;1"]
|
|
.getService(Ci.nsIPromptService)
|
|
.alert(null, "", msg);
|
|
}
|
|
|
|
/**
|
|
* Convenience method to replicate window.confirm()
|
|
**/
|
|
function confirm(msg){
|
|
return Cc["@mozilla.org/embedcomp/prompt-service;1"]
|
|
.getService(Ci.nsIPromptService)
|
|
.confirm(null, "", msg);
|
|
}
|
|
|
|
//
|
|
// XPCOM goop
|
|
//
|
|
ScholarService.prototype = {
|
|
QueryInterface: function(iid){
|
|
if (!iid.equals(Components.interfaces.nsISupports) &&
|
|
!iid.equals(SCHOLAR_IID)){
|
|
throw Components.results.NS_ERROR_NO_INTERFACE;
|
|
}
|
|
return this;
|
|
}
|
|
};
|
|
|
|
|
|
var ScholarFactory = {
|
|
createInstance: function(outer, iid){
|
|
if (outer != null){
|
|
throw Components.results.NS_ERROR_NO_AGGREGATION;
|
|
}
|
|
return new ScholarService().QueryInterface(iid);
|
|
}
|
|
};
|
|
|
|
|
|
var ScholarModule = {
|
|
_firstTime: true,
|
|
|
|
registerSelf: function(compMgr, fileSpec, location, type){
|
|
if (!this._firstTime){
|
|
throw Components.results.NS_ERROR_FACTORY_REGISTER_AGAIN;
|
|
}
|
|
this._firstTime = false;
|
|
|
|
compMgr =
|
|
compMgr.QueryInterface(Components.interfaces.nsIComponentRegistrar);
|
|
|
|
compMgr.registerFactoryLocation(SCHOLAR_CID,
|
|
SCHOLAR_CLASSNAME,
|
|
SCHOLAR_CONTRACTID,
|
|
fileSpec,
|
|
location,
|
|
type);
|
|
},
|
|
|
|
unregisterSelf: function(compMgr, location, type){
|
|
compMgr =
|
|
compMgr.QueryInterface(Components.interfaces.nsIComponentRegistrar);
|
|
compMgr.unregisterFactoryLocation(SCHOLAR_CID, location);
|
|
},
|
|
|
|
getClassObject: function(compMgr, cid, iid){
|
|
if (!cid.equals(SCHOLAR_CID)){
|
|
throw Components.results.NS_ERROR_NO_INTERFACE;
|
|
}
|
|
if (!iid.equals(Components.interfaces.nsIFactory)){
|
|
throw Components.results.NS_ERROR_NOT_IMPLEMENTED;
|
|
}
|
|
return ScholarFactory;
|
|
},
|
|
|
|
canUnload: function(compMgr){ return true; }
|
|
};
|
|
|
|
function NSGetModule(comMgr, fileSpec){ return ScholarModule; }
|