commit ea5a94e860a890dbf7b4844d0921b9c17c91277b
parent 178eda0c9daa3f1022209988304d77520d87781b
Author: Simon Kornblith <simon@simonster.com>
Date: Mon, 4 Jul 2011 05:03:06 +0000
- Support RDF in connector
- getTranslatorObject() now exports the "Export" object if one exists. In Firefox, it continues to export other objects otherwise. In Chrome/Safari, it will only export do* and detect*.
Diffstat:
2 files changed, 28 insertions(+), 8 deletions(-)
diff --git a/chrome/content/zotero/xpcom/translation/translate.js b/chrome/content/zotero/xpcom/translation/translate.js
@@ -253,6 +253,7 @@ Zotero.Translate.Sandbox = {
translate._debug("COMPAT WARNING: Translator must pass a callback to getTranslatorObject() to operate in connector");
}
+ var sandbox;
var haveTranslatorFunction = function(translator) {
translation.translator[0] = translator;
if(!translation._loadTranslator(translator)) throw new Error("Translator could not be loaded");
@@ -269,6 +270,9 @@ Zotero.Translate.Sandbox = {
var innerSandboxURI = ioService.newURI(typeof translation._sandboxLocation === "object" ?
translation._sandboxLocation.location : translation._sandboxLocation, null, null);
+ Zotero.debug(outerSandboxURI.spec);
+ Zotero.debug(innerSandboxURI.spec);
+
try {
secMan.checkSameOriginURI(outerSandboxURI, innerSandboxURI, false);
} catch(e) {
@@ -279,9 +283,19 @@ Zotero.Translate.Sandbox = {
translation._prepareTranslation();
setDefaultHandlers(translate, translation);
+ sandbox = translation._sandboxManager.sandbox;
+ if(sandbox.Export) {
+ sandbox.Export.Zotero = sandbox.Zotero;
+ sandbox = sandbox.Export;
+ } else {
+ translate._debug("COMPAT WARNING: "+translate.translator[0].label+" does "+
+ "not export any properties. Only detect"+translate._entryFunctionSuffix+
+ " and do"+translate._entryFunctionSuffix+" will be available in "+
+ "connectors.");
+ }
if(callback) {
- callback(translation._sandboxManager.sandbox);
+ callback(sandbox);
translate.decrementAsyncProcesses();
}
};
@@ -296,7 +310,7 @@ Zotero.Translate.Sandbox = {
}
Zotero.Translators.get(translation.translator[0], haveTranslatorFunction);
- if(!Zotero.isConnector) return translation._sandboxManager.sandbox;
+ if(!Zotero.isConnector) return sandbox;
}
};
@@ -1073,7 +1087,7 @@ Zotero.Translate.Base.prototype = {
try {
this._sandboxManager.eval("var translatorInfo = "+translator.code,
- ["detect"+this._entryFunctionSuffix, "do"+this._entryFunctionSuffix]);
+ ["detect"+this._entryFunctionSuffix, "do"+this._entryFunctionSuffix, "Export"]);
} catch(e) {
if(translator.logError) {
translator.logError(e.toString());
diff --git a/translators/RDF.js b/translators/RDF.js
@@ -40,8 +40,6 @@ var n = {
var callNumberTypes = [n.dcterms+"LCC", n.dcterms+"DDC", n.dcterms+"UDC"];
-var defaultUnknownType = "book";
-
// gets the first result set for a property that can be encoded in multiple
// ontologies
function getFirstResults(node, properties, onlyOneString) {
@@ -301,7 +299,7 @@ function importItem(newItem, node, type) {
}
if(!newItem.itemType) {
- newItem.itemType = defaultUnknownType;
+ newItem.itemType = Export.defaultUnknownType;
}
// regular author-type creators
@@ -633,4 +631,12 @@ function doImport() {
newCollection.complete();
}
}
-}
-\ No newline at end of file
+}
+
+/*
+ * Export doImport and defaultUnknownType to other translators
+ */
+var Export = {
+ "doImport":doImport,
+ "defaultUnknownType":"book"
+};
+\ No newline at end of file