2007-10-23 07:11:59 +00:00
|
|
|
const ZOTERO_CONTRACTID = '@zotero.org/Zotero;1';
|
2006-10-02 23:15:27 +00:00
|
|
|
const ZOTERO_CLASSNAME = 'Zotero';
|
|
|
|
const ZOTERO_CID = Components.ID('{e4c61080-ec2d-11da-8ad9-0800200c9a66}');
|
2007-10-23 07:11:59 +00:00
|
|
|
const ZOTERO_IID = Components.interfaces.chnmIZoteroService; //unused
|
2006-05-27 00:20:27 +00:00
|
|
|
|
|
|
|
const Cc = Components.classes;
|
|
|
|
const Ci = Components.interfaces;
|
|
|
|
|
|
|
|
// Assign the global scope to a variable to passed via wrappedJSObject
|
2006-10-02 23:15:27 +00:00
|
|
|
var ZoteroWrapped = this;
|
2006-05-27 00:20:27 +00:00
|
|
|
|
|
|
|
|
|
|
|
/********************************************************************
|
|
|
|
* Include the core objects to be stored within XPCOM
|
|
|
|
*********************************************************************/
|
|
|
|
|
2008-06-16 05:46:10 +00:00
|
|
|
var xpcomFiles = ['zotero',
|
2008-07-23 05:05:03 +00:00
|
|
|
'annotate', 'attachments', 'cite', 'collectionTreeView',
|
2008-06-16 05:46:10 +00:00
|
|
|
'dataServer', 'data_access', 'data/item', 'data/items', 'data/collection',
|
|
|
|
'data/collections', 'data/cachedTypes', 'data/creator', 'data/creators',
|
2008-06-20 06:40:05 +00:00
|
|
|
'data/itemFields', 'data/notes', 'data/tag', 'data/tags', 'db', 'enstyle',
|
|
|
|
'file', 'fulltext', 'id', 'ingester', 'integration', 'itemTreeView', 'mime',
|
2008-06-16 05:46:10 +00:00
|
|
|
'notifier', 'progressWindow', 'quickCopy', 'report', 'schema', 'search',
|
|
|
|
'sync', 'timeline', 'translate', 'utilities', 'zeroconf'];
|
Initial Zotero 1.5 Megacommit
Apologies for the massive (and, due to data_access.js splitting, difficult-to-follow) commit. Please note that external code that accesses the data layer may need to be tweaked for compatibility. Here's a comprehensive-as-possible changelog:
- Added server sync functionality (incomplete)
- Overhaul of data layer
- Split data_access.js into separate files (item.js, items.js, creator.js, etc.)
- Made creators and collections first-class objects, similar to items
- Constructors now take id as first parameter, e.g. new Zotero.Item(1234, 'book'), to allow explicit id setting and id changing
- Made various data layer operations (including attachment fields) require a save() rather than making direct DB changes
- Better handling of unsaved objects
- Item.setCreator() now takes creator objects instead of creator ids, and Item.save() will auto-save unsaved creators
- clone() now works on unsaved objects
- Newly created object instances are now disabled after save() to force refetch of globally accessible instance using Zotero.(Items|Creators|etc.).get()
- Added secondary lookup key to data objects
- Deprecated getID() and getItemType() methods in favor of .id and .itemTypeID properties
- toArray() deprecated in favor of serialize(), which has a somewhat modified format
- Added support for multiple creators with identical data -- currently unimplemented in interface and most of data layer
- Added Item.diff() for comparing item metadata
- Database changes
- Added SQLite triggers to enforce foreign key constraints
- Added Zotero.DB.transactionVacuum flag to run a VACUUM after a transaction
- Added Zotero.DB.transactionDate, .transactionDateTime, and transactionTimestamp to retrieve consistent timestamps for entire transaction
- Properly store 64-bit integers
- Set PRAGMA locking_mode=EXCLUSIVE on database
- Set SQLite page size to 4096 on new databases
- Set SQLite page cache to 8MB
- Do some database cleanup and integrity checking on migration from 1.0 branch
- Removed IF NOT EXISTS from userdata.sql CREATE statements -- userdata.sql is now processed only on DB initialization
- Removed itemNoteTitles table and moved titles into itemNotes
- Abstracted metadata edit box and note box into flexible XBL bindings with various modes, including read-only states
- Massive speed-up of item tree view
- Several fixes from 1.0 branch for Fx3 compatibility
- Added Notifier observer to log delete events for syncing
- Zotero.Utilities changes
- New methods getSQLDataType() and md5()
- Removed onError from Zotero.Utilities.HTTP.doGet()
- Don't display more than 1024 characters in doPost() debug output
- Don't display passwords in doPost() debug output
- Added Zotero.Notifier.untrigger() -- currently unused
- Added Zotero.reloadDataObjects() to reset all in-memory objects
- Added |chars| parameter to Zotero.randomString(len, chars)
- Added Zotero.Date.getUnixTimestamp() and Date.toUnixTimestamp(JSDate)
- Adjusted zotero-service.js to simplify file inclusion
Various things (such as tags) are temporarily broken.
2008-05-04 08:32:48 +00:00
|
|
|
|
|
|
|
for (var i=0; i<xpcomFiles.length; i++) {
|
|
|
|
Cc["@mozilla.org/moz/jssubscript-loader;1"]
|
|
|
|
.getService(Ci.mozIJSSubScriptLoader)
|
|
|
|
.loadSubScript("chrome://zotero/content/xpcom/" + xpcomFiles[i] + ".js");
|
|
|
|
}
|
2007-10-23 07:11:59 +00:00
|
|
|
|
2006-08-25 19:15:03 +00:00
|
|
|
Cc["@mozilla.org/moz/jssubscript-loader;1"]
|
|
|
|
.getService(Ci.mozIJSSubScriptLoader)
|
|
|
|
.loadSubScript("chrome://global/content/nsTransferable.js");
|
|
|
|
|
|
|
|
Cc["@mozilla.org/moz/jssubscript-loader;1"]
|
|
|
|
.getService(Ci.mozIJSSubScriptLoader)
|
|
|
|
.loadSubScript("chrome://global/content/nsDragAndDrop.js");
|
|
|
|
|
2006-05-27 00:20:27 +00:00
|
|
|
/********************************************************************/
|
|
|
|
|
|
|
|
|
2006-10-02 23:15:27 +00:00
|
|
|
// Initialize the Zotero service
|
2006-05-27 00:20:27 +00:00
|
|
|
//
|
2006-10-02 23:15:27 +00:00
|
|
|
// This runs when ZoteroService is first requested.
|
2006-05-27 00:20:27 +00:00
|
|
|
// 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(){
|
2008-07-03 16:44:52 +00:00
|
|
|
try {
|
|
|
|
Zotero.init();
|
|
|
|
}
|
|
|
|
catch (e) {
|
|
|
|
var msg = typeof e == 'string' ? e : e.name;
|
|
|
|
dump(e + "\n\n");
|
|
|
|
Components.utils.reportError(e);
|
|
|
|
throw (e);
|
|
|
|
}
|
2006-05-27 00:20:27 +00:00
|
|
|
}
|
|
|
|
|
2006-10-02 23:15:27 +00:00
|
|
|
function ZoteroService(){
|
|
|
|
this.wrappedJSObject = ZoteroWrapped.Zotero;
|
2006-05-27 00:20:27 +00:00
|
|
|
setupService();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Convenience method to replicate window.alert()
|
|
|
|
**/
|
|
|
|
function alert(msg){
|
|
|
|
Cc["@mozilla.org/embedcomp/prompt-service;1"]
|
|
|
|
.getService(Ci.nsIPromptService)
|
|
|
|
.alert(null, "", msg);
|
|
|
|
}
|
|
|
|
|
2006-06-01 21:57:12 +00:00
|
|
|
/**
|
|
|
|
* Convenience method to replicate window.confirm()
|
|
|
|
**/
|
|
|
|
function confirm(msg){
|
|
|
|
return Cc["@mozilla.org/embedcomp/prompt-service;1"]
|
|
|
|
.getService(Ci.nsIPromptService)
|
|
|
|
.confirm(null, "", msg);
|
|
|
|
}
|
2006-05-27 00:20:27 +00:00
|
|
|
|
Fulltext search support
There are currently two types of fulltext searching: an SQL-based word index and a file scanner. They each have their advantages and drawbacks.
The word index is very fast to search and is currently used for the find-as-you-type quicksearch. However, indexing files takes some time, so we should probably offer a preference to turn it off ("Index attachment content for quicksearch" or something). There's also an issue with Chinese characters (which are indexed by character rather than word, since there are no spaces to go by, so a search for a word with common characters could produce erroneous results). The quicksearch doesn't use a left-bound index (since that would probably upset German speakers searching for "musik" in "nachtmusik," though I don't know for sure how they think of words) but still seems pretty fast.
* Note: There will be a potentially long delay when you start Firefox with this revision as it builds a fulltext word index of your existing items. We obviously need a notification/option for this. *
The file scanner, used in the Attachment Content condition of the search dialog, offers phrase searching as well as regex support (both case-sensitive and not, and defaulting to multiline). It doesn't require an index, though it should probably be optimized to use the word index, if available, for narrowing the results when not in regex mode. (It does only scan files that pass all the other search conditions, which speeds it up considerably for multi-condition searches, and skips non-text files unless instructed otherwise, but it's still relatively slow.)
Both convert HTML to text before searching (with the exception of the binary file scanning mode).
There are some issues with which files get indexed and which don't that we can't do much about and that will probably confuse users immensely. Dan C. suggested some sort of indicator (say, a green dot) to show which files are indexed.
Also added (very ugly) charset detection (anybody want to figure out getCharsetFromString(str)?), a setTimeout() replacement in the XPCOM service, an arrayToHash() method, and a new header to timedtextarea.xml, since it's really not copyright CHNM (it's really just a few lines off from the toolkit timed-textbox binding--I tried to change it to extend timed-textbox and just ignore Return keypress events so that we didn't need to duplicate the Mozilla code, but timed-textbox's reliance on html:input instead of html:textarea made things rather difficult).
To do:
- Pref/buttons to disable/clear/rebuild fulltext index
- Hidden prefs to set maximum file size to index/scan
- Don't index words of fewer than 3 non-Asian characters
- MRU cache for saved searches
- Use word index if available to narrow search scope of fulltext scanner
- Cache attachment info methods
- Show content excerpt in search results (at least in advanced search window, when it exists)
- Notification window (a la scraping) to show when indexing
- Indicator of indexed status
- Context menu option to index
- Indicator that a file scanning search is in progress, if possible
- Find other ways to make it index the NYT front page in under 10 seconds
- Probably fix lots of bugs, which you will likely start telling me about...now.
2006-09-21 00:10:29 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Convenience method to replicate window.setTimeout()
|
|
|
|
**/
|
|
|
|
function setTimeout(func, ms){
|
|
|
|
var timer = Components.classes["@mozilla.org/timer;1"].
|
|
|
|
createInstance(Components.interfaces.nsITimer);
|
|
|
|
// {} implements nsITimerCallback
|
|
|
|
timer.initWithCallback({notify:func}, ms,
|
|
|
|
Components.interfaces.nsITimer.TYPE_ONE_SHOT);
|
2008-06-30 01:01:53 +00:00
|
|
|
return timer;
|
Fulltext search support
There are currently two types of fulltext searching: an SQL-based word index and a file scanner. They each have their advantages and drawbacks.
The word index is very fast to search and is currently used for the find-as-you-type quicksearch. However, indexing files takes some time, so we should probably offer a preference to turn it off ("Index attachment content for quicksearch" or something). There's also an issue with Chinese characters (which are indexed by character rather than word, since there are no spaces to go by, so a search for a word with common characters could produce erroneous results). The quicksearch doesn't use a left-bound index (since that would probably upset German speakers searching for "musik" in "nachtmusik," though I don't know for sure how they think of words) but still seems pretty fast.
* Note: There will be a potentially long delay when you start Firefox with this revision as it builds a fulltext word index of your existing items. We obviously need a notification/option for this. *
The file scanner, used in the Attachment Content condition of the search dialog, offers phrase searching as well as regex support (both case-sensitive and not, and defaulting to multiline). It doesn't require an index, though it should probably be optimized to use the word index, if available, for narrowing the results when not in regex mode. (It does only scan files that pass all the other search conditions, which speeds it up considerably for multi-condition searches, and skips non-text files unless instructed otherwise, but it's still relatively slow.)
Both convert HTML to text before searching (with the exception of the binary file scanning mode).
There are some issues with which files get indexed and which don't that we can't do much about and that will probably confuse users immensely. Dan C. suggested some sort of indicator (say, a green dot) to show which files are indexed.
Also added (very ugly) charset detection (anybody want to figure out getCharsetFromString(str)?), a setTimeout() replacement in the XPCOM service, an arrayToHash() method, and a new header to timedtextarea.xml, since it's really not copyright CHNM (it's really just a few lines off from the toolkit timed-textbox binding--I tried to change it to extend timed-textbox and just ignore Return keypress events so that we didn't need to duplicate the Mozilla code, but timed-textbox's reliance on html:input instead of html:textarea made things rather difficult).
To do:
- Pref/buttons to disable/clear/rebuild fulltext index
- Hidden prefs to set maximum file size to index/scan
- Don't index words of fewer than 3 non-Asian characters
- MRU cache for saved searches
- Use word index if available to narrow search scope of fulltext scanner
- Cache attachment info methods
- Show content excerpt in search results (at least in advanced search window, when it exists)
- Notification window (a la scraping) to show when indexing
- Indicator of indexed status
- Context menu option to index
- Indicator that a file scanning search is in progress, if possible
- Find other ways to make it index the NYT front page in under 10 seconds
- Probably fix lots of bugs, which you will likely start telling me about...now.
2006-09-21 00:10:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-05-27 00:20:27 +00:00
|
|
|
//
|
|
|
|
// XPCOM goop
|
|
|
|
//
|
2006-10-02 23:15:27 +00:00
|
|
|
ZoteroService.prototype = {
|
2006-05-27 00:20:27 +00:00
|
|
|
QueryInterface: function(iid){
|
|
|
|
if (!iid.equals(Components.interfaces.nsISupports) &&
|
2007-10-23 07:11:59 +00:00
|
|
|
!iid.equals(ZOTERO_IID)){ // interface unused
|
2006-05-27 00:20:27 +00:00
|
|
|
throw Components.results.NS_ERROR_NO_INTERFACE;
|
|
|
|
}
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2006-10-02 23:15:27 +00:00
|
|
|
var ZoteroFactory = {
|
2006-05-27 00:20:27 +00:00
|
|
|
createInstance: function(outer, iid){
|
|
|
|
if (outer != null){
|
|
|
|
throw Components.results.NS_ERROR_NO_AGGREGATION;
|
|
|
|
}
|
2006-10-02 23:15:27 +00:00
|
|
|
return new ZoteroService().QueryInterface(iid);
|
2006-05-27 00:20:27 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2006-10-02 23:15:27 +00:00
|
|
|
var ZoteroModule = {
|
2006-05-27 00:20:27 +00:00
|
|
|
_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);
|
|
|
|
|
2006-10-02 23:15:27 +00:00
|
|
|
compMgr.registerFactoryLocation(ZOTERO_CID,
|
|
|
|
ZOTERO_CLASSNAME,
|
|
|
|
ZOTERO_CONTRACTID,
|
2006-05-27 00:20:27 +00:00
|
|
|
fileSpec,
|
|
|
|
location,
|
|
|
|
type);
|
|
|
|
},
|
|
|
|
|
|
|
|
unregisterSelf: function(compMgr, location, type){
|
|
|
|
compMgr =
|
|
|
|
compMgr.QueryInterface(Components.interfaces.nsIComponentRegistrar);
|
2006-10-02 23:15:27 +00:00
|
|
|
compMgr.unregisterFactoryLocation(ZOTERO_CID, location);
|
2006-05-27 00:20:27 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
getClassObject: function(compMgr, cid, iid){
|
2006-10-02 23:15:27 +00:00
|
|
|
if (!cid.equals(ZOTERO_CID)){
|
2006-05-27 00:20:27 +00:00
|
|
|
throw Components.results.NS_ERROR_NO_INTERFACE;
|
|
|
|
}
|
|
|
|
if (!iid.equals(Components.interfaces.nsIFactory)){
|
|
|
|
throw Components.results.NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
2006-10-02 23:15:27 +00:00
|
|
|
return ZoteroFactory;
|
2006-05-27 00:20:27 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
canUnload: function(compMgr){ return true; }
|
|
|
|
};
|
|
|
|
|
2006-10-02 23:15:27 +00:00
|
|
|
function NSGetModule(comMgr, fileSpec){ return ZoteroModule; }
|