Merged revisions 3306,3309 from 1.0 branch via svnmerge

This commit is contained in:
Dan Stillman 2008-09-01 06:09:56 +00:00
parent a2e1a83de7
commit d662466ff6
3 changed files with 21 additions and 88 deletions

View file

@ -43,8 +43,6 @@ var Zotero = new function(){
this.getStorageDirectory = getStorageDirectory;
this.getZoteroDatabase = getZoteroDatabase;
this.getTempDirectory = getTempDirectory;
this.convertChromeURLToFile = convertChromeURLToFile;
this.convertChromeURLToFileURL = convertChromeURLToFileURL;
this.chooseZoteroDirectory = chooseZoteroDirectory;
this.debug = debug;
this.log = log;
@ -397,72 +395,6 @@ var Zotero = new function(){
}
/**
* Get a file from a chrome://zotero URL
*
* Currently only works for skin URLs
*
* @param {String} chromeURI
* @return {nsIFile}
*/
function convertChromeURLToFile(chromeURL) {
var ios = Components.classes["@mozilla.org/network/io-service;1"].
getService(Components.interfaces.nsIIOService);
var uri = ios.newURI(chromeURL, null, null);
uri.QueryInterface(Components.interfaces.nsIStandardURL);
if (uri.scheme != 'chrome') {
throw ("URI " + uri.spec +
" not a chrome URI in Zotero.convertChromeURLToFileURL()");
}
if (uri.host != 'zotero') {
throw ("URI " + uri.spec +
" not a Zotero chrome URI in Zotero.convertChromeURLToFileURL()");
}
var parts = uri.path.substr(1).split('/');
// Auto-expand URL if necessary
var chromeReg = Components.classes["@mozilla.org/chrome/chrome-registry;1"]
.getService(Components.interfaces.nsIChromeRegistry);
uri = chromeReg.convertChromeURL(uri);
var file = this.getInstallDirectory();
file.append('chrome');
switch (parts[0]) {
case 'skin':
file.append('skin');
file.append('default');
file.append('zotero');
for (var i=1; i<parts.length; i++) {
file.append(parts[i]);
}
break;
default:
throw ("Chrome URI part '" + parts[0]
+ "' not implemented in Zotero.convertChromeURLToFileURL()")
}
return file;
}
/**
* @param {String} chromeURI
* @return {nsIURL} file:// nsIURL
*/
function convertChromeURLToFileURL(chromeURL) {
var ios = Components.classes["@mozilla.org/network/io-service;1"].
getService(Components.interfaces.nsIIOService);
var file = this.convertChromeURLToFile(chromeURL);
return ios.newFileURI(file).spec;
}
function chooseZoteroDirectory(forceRestartNow, useProfileDir) {
var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"]
.getService(Components.interfaces.nsIWindowMediator);

View file

@ -647,41 +647,41 @@ function ChromeExtensionHandler() {
// Proxy annotation icons
if (id.match(/^annotation.*\.(png|html|css|gif)$/)) {
var chromeURL = 'chrome://zotero/skin/' + id;
var file = Zotero.convertChromeURLToFile(chromeURL);
if (!file.exists()) {
Zotero.debug(file.path + " not found");
Components.utils.reportError(file.path + " not found");
return _errorChannel("File not found");
}
var ios = Components.classes["@mozilla.org/network/io-service;1"].
getService(Components.interfaces.nsIIOService);
var uri = ios.newURI(chromeURL, null, null);
var chromeReg = Components.classes["@mozilla.org/chrome/chrome-registry;1"]
.getService(Components.interfaces.nsIChromeRegistry);
var fileURI = chromeReg.convertChromeURL(uri);
}
else {
return _errorChannel("Attachment id not an integer");
}
}
if (!file) {
if (!fileURI) {
var item = Zotero.Items.get(id);
if (!item) {
return _errorChannel("Item not found");
}
var file = item.getFile();
}
if (!file) {
return _errorChannel("File not found");
}
if (fileName) {
file = file.parent;
file.append(fileName);
if (!file.exists()) {
if (!file) {
return _errorChannel("File not found");
}
if (fileName) {
file = file.parent;
file.append(fileName);
if (!file.exists()) {
return _errorChannel("File not found");
}
}
}
var ph = Components.classes["@mozilla.org/network/protocol;1?name=file"].
createInstance(Components.interfaces.nsIFileProtocolHandler);
var fileURI = ph.newFileURI(file);
if (!fileURI) {
var fileURI = ph.newFileURI(file);
}
var channel = ioService.newChannelFromURI(fileURI);
return channel;
}

View file

@ -22,7 +22,7 @@
-- Set the following timestamp to the most recent scraper update date
REPLACE INTO version VALUES ('repository', STRFTIME('%s', '2008-08-29 04:10:00'));
REPLACE INTO version VALUES ('repository', STRFTIME('%s', '2008-09-01 06:00:00'));
REPLACE INTO translators VALUES ('96b9f483-c44d-5784-cdad-ce21b984fe01', '1.0.0b4.r1', '', '2008-08-22 20:30:00', '1', '100', '4', 'Amazon.com', 'Sean Takats and Michael Berkowitz', '^https?://(?:www\.)?amazon',
'function detectWeb(doc, url) {
@ -220,7 +220,7 @@ REPLACE INTO translators VALUES ('96b9f483-c44d-5784-cdad-ce21b984fe01', '1.0.0b
Zotero.wait();
}');
REPLACE INTO translators VALUES ('aee2323e-ce00-4fcc-a949-06eb1becc98f', '1.0.0b4.r1', '', '2007-08-27 05:00:00', '0', '100', '4', 'Epicurious', 'Sean Takats', '^https?://www\.epicurious\.com/(?:tools/searchresults|recipes/food/views)',
REPLACE INTO translators VALUES ('aee2323e-ce00-4fcc-a949-06eb1becc98f', '1.0.0', '', '2008-09-01 06:00:00', '0', '100', '4', 'Epicurious', 'Sean Takats', '^https?://www\.epicurious\.com/(?:tools/searchresults|recipes/food/views)',
'function detectWeb(doc, url){
var namespace = doc.documentElement.namespaceURI;
var nsResolver = namespace ? function(prefix) {
@ -255,6 +255,7 @@ function scrape(doc){
var xpath = ''//title'';
var title = doc.evaluate(xpath, doc, nsResolver, XPathResult.ANY_TYPE, null).iterateNext().textContent;
title = Zotero.Utilities.trimInternal(title);
title = title.substring(0, title.indexOf(" Recipe at Epicurious.com"));
newItem.title = title;