/* ***** BEGIN LICENSE BLOCK ***** Copyright (c) 2006 Center for History and New Media George Mason University, Fairfax, Virginia, USA http://chnm.gmu.edu Licensed under the Educational Community License, Version 1.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.opensource.org/licenses/ecl1.php Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. Based on nsChromeExtensionHandler example code by Ed Anuff at http://kb.mozillazine.org/Dev_:_Extending_the_Chrome_Protocol ***** END LICENSE BLOCK ***** */ const ZOTERO_SCHEME = "zotero"; const ZOTERO_PROTOCOL_CID = Components.ID("{9BC3D762-9038-486A-9D70-C997AF848A7C}"); const ZOTERO_PROTOCOL_CONTRACTID = "@mozilla.org/network/protocol;1?name=" + ZOTERO_SCHEME; const ZOTERO_PROTOCOL_NAME = "Zotero Chrome Extension Protocol"; // Dummy chrome URL used to obtain a valid chrome channel // This one was chosen at random and should be able to be substituted // for any other well known chrome URL in the browser installation const DUMMY_CHROME_URL = "chrome://mozapps/content/xpinstall/xpinstallConfirm.xul"; function ChromeExtensionHandler() { this.wrappedJSObject = this; this._systemPrincipal = null; this._extensions = {}; /* * Report generation extension for Zotero protocol * * Example URLs: * * zotero://report/ -- library * zotero://report/collection/12345 * zotero://report/search/12345 * zotero://report/items/12345-23456-34567 * zotero://report/item/12345 * * Optional format can be specified after ids * * - 'html', 'rtf', 'csv' * - defaults to 'html' if not specified * * e.g. zotero://report/collection/12345/rtf * * * Sorting: * * - 'sort' query string variable * - format is field[/order] [, field[/order], ...] * - order can be 'asc', 'a', 'desc' or 'd'; defaults to ascending order * * zotero://report/collection/13245?sort=itemType/d,title */ var ReportExtension = new function(){ this.newChannel = newChannel; function newChannel(uri){ var ioService = Components.classes["@mozilla.org/network/io-service;1"] .getService(Components.interfaces.nsIIOService); var Zotero = Components.classes["@zotero.org/Zotero;1"] .getService(Components.interfaces.nsISupports) .wrappedJSObject; generateContent:try { var mimeType, content = ''; var [path, queryString] = uri.path.substr(1).split('?'); var [type, ids, format] = path.split('/'); // Get query string variables if (queryString) { var queryVars = queryString.split('&'); for (var i in queryVars) { var [key, val] = queryVars[i].split('='); switch (key) { case 'sort': var sortBy = val; break; } } } switch (type){ case 'collection': var results = Zotero.getItems(ids); break; case 'search': var s = new Zotero.Search(ids); var ids = s.search(); break; case 'items': case 'item': var ids = ids.split('-'); break; default: var type = 'library'; var s = new Zotero.Search(); s.addCondition('noChildren', 'true'); var ids = s.search(); } if (!results) { var results = Zotero.Items.get(ids); } var items = []; // Only include parent items for (var i=0; icreates html for timeline zotero://timeline/ ------> minimum needed (defaults: intervals = month, year, decade | timelineDate = today's date | dateType = date | type = library) zotero://timeline/data/dateType/type/ids ----->creates XML */ function newChannel(uri) { var ioService = Components.classes["@mozilla.org/network/io-service;1"] .getService(Components.interfaces.nsIIOService); var Zotero = Components.classes["@zotero.org/Zotero;1"] .getService(Components.interfaces.nsISupports) .wrappedJSObject; generateContent:try { var mimeType, content = ''; var [path, queryString] = uri.path.substr(1).split('?'); var pathParts = path.split('/'); if (pathParts[0] != 'data') { //creates HTML file var intervals = pathParts[0]; var timelineDate = pathParts[1]; content = Zotero.File.getContentsFromURL('chrome://zotero/skin/timeline/timeline.html'); mimeType = 'text/html'; var theTemp = 'Timeline.loadXML("zotero://timeline/data/'; if(!timelineDate){ timelineDate=Date(); var dateParts=timelineDate.toString().split(' '); timelineDate=dateParts[1]+'.'+dateParts[2]+'.'+dateParts[3]; } else { //passes information (dateType,type,ids) for when the XML is created content = content.replace(theTemp, theTemp + pathParts.slice(2).join('/')); } //sets the intervals of the timeline bands theTemp = '