Fixes #1400 RHS has updated their XML format, also added support for bookSections
This commit is contained in:
parent
4ac98e19a3
commit
c781705793
|
@ -12,10 +12,10 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
function detectWeb(doc, url) {
|
function detectWeb(doc, url) {
|
||||||
if (doc.evaluate('//tr/td[3][@class="bib_data"]/a[@class="bibref"]', doc, null, XPathResult.ANY_TYPE, null).iterateNext()) {
|
if (doc.evaluate('//div[@class="bib_data"]/a[contains(@title, "view in more detail")]', doc, null, XPathResult.ANY_TYPE, null).iterateNext()) {
|
||||||
return "multiple";
|
return "multiple";
|
||||||
} else if (doc.evaluate('//a[text() = "View records in XML"]', doc, null, XPathResult.ANY_TYPE, null).iterateNext()) {
|
} else if (doc.evaluate('//a[text() = "View records in XML"]', doc, null, XPathResult.ANY_TYPE, null).iterateNext()) {
|
||||||
return "book";
|
return "document";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -23,7 +23,7 @@ function doWeb(doc, url) {
|
||||||
var books = new Array();
|
var books = new Array();
|
||||||
if (detectWeb(doc, url) == "multiple") {
|
if (detectWeb(doc, url) == "multiple") {
|
||||||
var items = new Object();
|
var items = new Object();
|
||||||
var xpath = '//a[@class="bibref"]';
|
var xpath = '//div[@class="bib_data"]/a[contains(@title, "view in more detail")]';
|
||||||
var results = doc.evaluate(xpath, doc, null, XPathResult.ANY_TYPE, null);
|
var results = doc.evaluate(xpath, doc, null, XPathResult.ANY_TYPE, null);
|
||||||
var result;
|
var result;
|
||||||
while (result = results.iterateNext()) {
|
while (result = results.iterateNext()) {
|
||||||
|
@ -41,12 +41,14 @@ function doWeb(doc, url) {
|
||||||
text = text.replace(/<\?[^?]+\?>/, "");
|
text = text.replace(/<\?[^?]+\?>/, "");
|
||||||
var xml = new XML(text);
|
var xml = new XML(text);
|
||||||
xml = xml..recordList;
|
xml = xml..recordList;
|
||||||
|
|
||||||
var itemtype = "book";
|
var itemtype = "book";
|
||||||
if (xml..journal_title.length() != 0) itemtype = "journalArticle";
|
if (xml..journal.length() != 0) itemtype = "journalArticle";
|
||||||
|
if (xml..in.length() != 0) itemtype = "bookSection";
|
||||||
|
|
||||||
var item = new Zotero.Item(itemtype);
|
var item = new Zotero.Item(itemtype);
|
||||||
item.title = Zotero.Utilities.capitalizeTitle(xml..title.toString());
|
item.title = Zotero.Utilities.cleanTags(xml..title.toString());
|
||||||
|
item.date = xml..date.toString().match(/\d+/);
|
||||||
|
item.pages = xml..length.toString();
|
||||||
for (var i = 0; i < xml..author.length(); i++) {
|
for (var i = 0; i < xml..author.length(); i++) {
|
||||||
var name = xml..author[i].toString().match(/^[^,]+,[^,]+/)[0].split(/,\s+/);
|
var name = xml..author[i].toString().match(/^[^,]+,[^,]+/)[0].split(/,\s+/);
|
||||||
item.creators.push({lastName:name[0], firstName:name[1], creatorType:"author"});
|
item.creators.push({lastName:name[0], firstName:name[1], creatorType:"author"});
|
||||||
|
@ -54,20 +56,33 @@ function doWeb(doc, url) {
|
||||||
if (item.itemType == "book") {
|
if (item.itemType == "book") {
|
||||||
item.place = xml..place_of_publication.toString();
|
item.place = xml..place_of_publication.toString();
|
||||||
item.publisher = xml..publisher.toString();
|
item.publisher = xml..publisher.toString();
|
||||||
item.date = xml..publication_year.toString();
|
item.ISBN = xml..ISBN.toString();
|
||||||
} else if (item.itemType == "journalArticle") {
|
} else if (item.itemType == "journalArticle") {
|
||||||
item.publicationTitle = xml..journal_title.toString();
|
item.publicationTitle = xml..journal.toString();
|
||||||
var voliss = xml..journal_number.split(":");
|
item.volume = xml..journal_volume.toString();
|
||||||
Zotero.debug(voliss);
|
item.issue = xml..journal_issue.toString();
|
||||||
item.volume = voliss[0];
|
item.series = xml..series.toString();
|
||||||
item.issue = voliss[1];
|
item.ISSN = xml..ISSN.toString();
|
||||||
item.date = xml..journal_issue_year;
|
} else if (item.itemType == "bookSection") {
|
||||||
item.pages = xml..journal_pages;
|
if (xml..title_interpolation.toString()) {
|
||||||
|
item.bookTitle = xml..title_interpolation.toString();
|
||||||
|
} else {
|
||||||
|
item.bookTitle = xml..in.toString().match(/\),\s(.+)\s\(/)[1];
|
||||||
|
}
|
||||||
|
|
||||||
|
item.ISBN = xml..ISBN.toString();
|
||||||
|
try { // this regex is iffy
|
||||||
|
bookInfo = xml..in.toString().match(/\(([A-Za-z;\s]+:[A-Za-z\s']+),\s\d+\)/)[1];
|
||||||
|
} catch (e) {
|
||||||
|
Zotero.debug("regex didn't work");
|
||||||
|
}
|
||||||
|
item.place = bookInfo.split(": ")[0]
|
||||||
|
item.publisher = bookInfo.split(": ")[1]
|
||||||
}
|
}
|
||||||
|
|
||||||
item.complete();
|
item.complete();
|
||||||
});
|
}, function(){Zotero.done();});
|
||||||
Zotero.done();
|
|
||||||
}
|
}
|
||||||
Zotero.wait();
|
Zotero.wait();
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user