Skip to content

Commit

Permalink
Merge pull request zotero#936 from zuphilip/gbv-toc
Browse files Browse the repository at this point in the history
[GBV ISBN]: Expand method for ToC attachment
  • Loading branch information
adam3smith committed Aug 15, 2015
2 parents 0ac84b5 + b04a391 commit 605a24f
Showing 1 changed file with 78 additions and 11 deletions.
89 changes: 78 additions & 11 deletions Gemeinsamer Bibliotheksverbund ISBN.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"inRepository": true,
"translatorType": 8,
"browserSupport": "gcsibv",
"lastUpdated": "2015-04-16 18:45:00"
"lastUpdated": "2015-08-14 17:06:00"
}

/*
Expand Down Expand Up @@ -44,24 +44,36 @@ function doSearch(item) {
//search the ISBN over the SRU of the GBV, and take the result it as MARCXML
//documentation: https://www.gbv.de/wikis/cls/SRU
var url = "http://sru.gbv.de/gvk?version=1.1&operation=searchRetrieve&query=pica.isb=" + queryISBN + " AND pica.mat%3DB&maximumRecords=1";
//Z.debug(url);
ZU.doGet(url, function (text) {
Z.debug(text);
//Z.debug(text);
var translator = Zotero.loadTranslator("import");
translator.setTranslator("edd87d07-9194-42f8-b2ad-997c4c7deefd");
translator.setString(text);

translator.setHandler("itemDone", function (obj, item) {
// The url to the table of contents (scanned through DNB)
// can be contained in field 856 $3 and the url schema is unique:
// prefix (http://d-nb.info/) + id + suffix for toc (/04)
var tocURL = text.match(/http:\/\/d-nb\.info\/.*\/04/);
if (tocURL) {
// Table of Contents = Inhaltsverzeichnis
/* e.g.
<datafield tag="856" ind1="4" ind2="2">
<subfield code="u">http://d-nb.info/1054452857/04</subfield>
<subfield code="m">DE-101</subfield>
<subfield code="3">Inhaltsverzeichnis</subfield>
</datafield>
*/
var parser = new DOMParser();
var xml = parser.parseFromString(text);
var ns = {
"marc": "http://www.loc.gov/MARC21/slim"
};
var tocURL = ZU.xpath(xml, '//marc:datafield[@tag="856"][ marc:subfield[text()="Inhaltsverzeichnis"] ]/marc:subfield[@code="u"]', ns);
if (tocURL.length) {
//Z.debug(tocURL[0].textContent);
item.attachments = [{
url: tocURL[0],
url: tocURL[0].textContent,
title: "Table of Contents PDF",
mimeType: "application/pdf"
}];
}

//delete [u.a.] from place
if (item.place) {
item.place = item.place.replace(/\[?u\.[\s\u00A0]?a\.\]?\s*$/, '');
Expand Down Expand Up @@ -124,7 +136,7 @@ var testCases = [
],
"libraryCatalog": "Gemeinsamer Bibliotheksverbund ISBN",
"place": "Münster",
"ISBN": "9783830931492 3830931492 9783830931492",
"ISBN": "9783830931492",
"title": "Evaluation in Deutschland und Österreich: Stand und Entwicklungsperspektiven in den Arbeitsfeldern der DeGEval - Gesellschaft für Evaluation",
"publisher": "Waxmann",
"date": "2014",
Expand Down Expand Up @@ -176,7 +188,7 @@ var testCases = [
"mimeType": "application/pdf"
}
],
"ISBN": "3866882408 9783866882409 9783866882416",
"ISBN": "9783866882409 9783866882416",
"language": "ger",
"place": "München",
"numPages": "387",
Expand All @@ -189,6 +201,61 @@ var testCases = [
"date": "2012"
}
]
},
{
"type": "search",
"input": {
"ISBN": "978-1-4073-0412-0"
},
"items": [
{
"itemType": "book",
"title": "The harbour of Sebastos (Caesarea Maritima) in its Roman Mediterranean context",
"creators": [
{
"firstName": "Avnēr",
"lastName": "Rabbān",
"creatorType": "author"
},
{
"firstName": "Michal",
"lastName": "Artzy",
"creatorType": "author"
}
],
"notes": [],
"tags": [
"Ausgrabung",
"Caesarea (Israel) Antiquities",
"Caesarea Maritima",
"Excavations (Archaeology)",
"Excavations (Archaeology) Israel Caesarea",
"Funde",
"Hafen",
"Harbors",
"Harbors Israel Caesarea",
"Israel Caesarea",
"Underwater archaeology",
"Underwater archaeology Israel Caesarea"
],
"seeAlso": [],
"attachments": [
{
"title": "Table of Contents PDF",
"mimeType": "application/pdf"
}
],
"ISBN": "9781407304120",
"language": "eng",
"place": "Oxford",
"numPages": "222",
"series": "BAR International series",
"seriesNumber": "1930",
"libraryCatalog": "Gemeinsamer Bibliotheksverbund ISBN",
"publisher": "Archaeopress" ,
"date": "2009"
}
]
}
]
/** END TEST CASES **/

0 comments on commit 605a24f

Please sign in to comment.