Merge branch 'nla'
This commit is contained in:
parent
a22fb4e3d2
commit
2cf9350204
|
@ -2,18 +2,29 @@
|
||||||
"translatorID":"54ac4ec1-9d07-45d3-9d96-48bed3411fb6",
|
"translatorID":"54ac4ec1-9d07-45d3-9d96-48bed3411fb6",
|
||||||
"translatorType":4,
|
"translatorType":4,
|
||||||
"label":"National Library of Australia (new catalog)",
|
"label":"National Library of Australia (new catalog)",
|
||||||
"creator":"Mark Triggs and Steve McPhillips",
|
"creator":"Mark Triggs, Steve McPhillips and Matt Burton",
|
||||||
"target":"catalogue.nla.gov.au",
|
"target":"catalogue.nla.gov.au",
|
||||||
"minVersion":"1.0.0b4.r5",
|
"minVersion":"1.0.0b4.r5",
|
||||||
"maxVersion":"",
|
"maxVersion":"",
|
||||||
"priority":100,
|
"priority":100,
|
||||||
"inRepository":true,
|
"inRepository":true,
|
||||||
"lastUpdated":"2009-02-08 22:10:00"
|
"lastUpdated":"2009-04-12 10:10:00"
|
||||||
}
|
}
|
||||||
|
|
||||||
function detectWeb(doc, url) {
|
function detectWeb(doc, url) {
|
||||||
if (url.match("/Record/[0-9]+")) {
|
if (url.match("/Record/[0-9]+")) {
|
||||||
var format = Zotero.Utilities.cleanString(doc.getElementById("myformat").textContent);
|
var format = doc.getElementById("myformat").textContent;
|
||||||
|
return computeFormat(format);
|
||||||
|
|
||||||
|
} else if (url.match ("/Search/Home") && doc.getElementById ("resultItemLine1")) {
|
||||||
|
return "multiple";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// map the nla formats to zotero formats
|
||||||
|
function computeFormat(format){
|
||||||
|
// clean up whitespace and remove commas from items with multiple formats
|
||||||
|
format = Zotero.Utilities.trimInternal(format.replace(',', ''));
|
||||||
|
|
||||||
if (format == "Audio") {
|
if (format == "Audio") {
|
||||||
return "audioRecording";
|
return "audioRecording";
|
||||||
|
@ -45,24 +56,14 @@ function detectWeb(doc, url) {
|
||||||
else {
|
else {
|
||||||
return "book";
|
return "book";
|
||||||
}
|
}
|
||||||
} else if (url.match ("/Search/Home") &&
|
|
||||||
doc.getElementById ("resultItemLine1")) {
|
|
||||||
return "multiple";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function as_array(obj) {
|
function load_item(responseText, url, format) {
|
||||||
if (obj instanceof Array) {
|
|
||||||
return obj;
|
|
||||||
} else {
|
|
||||||
return [obj];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
var metadata = eval("(" + Zotero.Utilities.trimInternal(responseText) + ")");
|
||||||
function load_item(responseText, requestObject, format) {
|
var bibid = url.match("^.*\/Record/([0-9]+)")[1];
|
||||||
var metadata = JSON.parse(Zotero.Utilities.cleanString(responseText));
|
var newItem = new Zotero.Item(format[bibid]);
|
||||||
var newItem = new Zotero.Item(format);
|
|
||||||
|
|
||||||
/* load in our authors */
|
/* load in our authors */
|
||||||
if (metadata.authors) {
|
if (metadata.authors) {
|
||||||
|
@ -95,35 +96,36 @@ function load_item(responseText, requestObject, format) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function doWeb(doc, url) {
|
function doWeb(doc, url) {
|
||||||
format = detectWeb(doc, url);
|
var format = detectWeb(doc, url);
|
||||||
|
var items = {};
|
||||||
items = [];
|
// does javascript have an easy way to test if object has properties?
|
||||||
|
var itemsHasProperties = false;
|
||||||
if (format == "multiple") {
|
if (format == "multiple") {
|
||||||
for (var url in Zotero.selectItems((Zotero.Utilities.getItemArray
|
for (var url in Zotero.selectItems((Zotero.Utilities.getItemArray
|
||||||
(doc, doc, "/Record/[0-9]+")))) {
|
(doc, doc, "/Record/[0-9]+")))) {
|
||||||
items.push(url);
|
var bibid = url.match("^.*\/Record/([0-9]+)")[1];
|
||||||
|
// grab the item type for that bibid so we don't have to make a processDocuments call for each
|
||||||
|
var xpath = "//div[contains(./div/a/@href, '"+bibid+"')]/div[@id = 'resultItemLine3']/span/text()";
|
||||||
|
var nlaFormat = doc.evaluate(xpath, doc, null, XPathResult.ANY_TYPE, null).iterateNext().textContent;
|
||||||
|
// populate an associative array with bibid -> format for the doGet
|
||||||
|
items[bibid] = computeFormat(nlaFormat);
|
||||||
|
itemsHasProperties = true; // items has stuff
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
items.push(url);
|
var bibid = url.match("^.*\/Record/([0-9]+)")[1];
|
||||||
|
items[bibid] = format;
|
||||||
|
itemsHasProperties = true; // items has stuff
|
||||||
}
|
}
|
||||||
|
// only continue if there are items to create
|
||||||
if (items.length > 0) {
|
if (itemsHasProperties) {
|
||||||
Zotero.Utilities.processDocuments(items, function(onedoc) {
|
var urls = [];
|
||||||
handleDocument(onedoc);
|
for (var bibid in items) {
|
||||||
}, function() { Zotero.done(); });
|
urls.push("http://catalogue.nla.gov.au/Record/" + bibid + "/Export?style=zotero");
|
||||||
|
}
|
||||||
|
// the bibid->format associative array prevents the need for a doGet nested in processDocs
|
||||||
|
Zotero.Utilities.HTTP.doGet(urls,
|
||||||
|
function(text, obj, url) { load_item(text, url, items);},
|
||||||
|
function(){ Zotero.done();});
|
||||||
Zotero.wait();
|
Zotero.wait();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function handleDocument(doc) {
|
|
||||||
bibid = doc.location.href.match("^.*\/Record/([0-9]+)")[1];
|
|
||||||
format = detectWeb(doc, doc.location.href);
|
|
||||||
Zotero.Utilities.HTTP.doGet("http://catalogue.nla.gov.au/Record/" +
|
|
||||||
bibid +
|
|
||||||
"/Export?style=zotero",
|
|
||||||
function(text, obj) {
|
|
||||||
load_item(text, obj, format);
|
|
||||||
});
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user