forked from zotero/translators
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsbn.it.js
186 lines (173 loc) · 5.72 KB
/
sbn.it.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
{
"translatorID": "4c272290-7ac4-433e-862d-244884ed285a",
"label": "sbn.it",
"creator": "Philipp Zumstein",
"target": "^https?://(www|opac)\\.sbn\\.it/opacsbn/opaclib",
"minVersion": "3.0",
"maxVersion": "",
"priority": 100,
"inRepository": true,
"translatorType": 4,
"browserSupport": "gcsibv",
"lastUpdated": "2019-12-27 16:51:43"
}
/*
***** BEGIN LICENSE BLOCK *****
Copyright © 2015 Philipp Zumstein
This file is part of Zotero.
Zotero is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Zotero is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with Zotero. If not, see <http://www.gnu.org/licenses/>.
***** END LICENSE BLOCK *****
*/
var typeMapping = {
"testo a stampa": "book",
// "musica a stampa" ,
"documento da proiettare o video": "videoRecording",
"registrazione sonora": "audioRecording",
// "musica manoscritta",
"documento grafico": "artwork",
// "risorsa elettronica",
"documento cartografico a stampa": "map",
"registrazione sonora non musicale": "audioRecording",
// "documento multimediale",
// "testo manoscritto",
// "oggetto tridimensionale",
// "documento cartografico manoscritto"
};
function detectWeb(doc, url) {
if (url.includes("full.jsp")) {
var type = ZU.xpathText(doc, '//tr[ td[contains(text(), "Tipo documento")] ]/td[contains(@class,"detail_value")]');
// Z.debug(type.trim());
return typeMapping[type.trim().toLowerCase()] || "book";
}
else if (getSearchResults(doc, true)) {
return "multiple";
}
return false;
}
function getSearchResults(doc, checkOnly) {
var items = {};
var found = false;
var rows = ZU.xpath(doc, '//li[contains(@class, "element")]//div[contains(@class, "content")]/strong/a');
for (var i = 0; i < rows.length; i++) {
var href = rows[i].href;
var title = ZU.trimInternal(rows[i].textContent);
if (!href || !title) continue;
if (checkOnly) return true;
found = true;
items[href] = title;
}
return found ? items : false;
}
function doWeb(doc, url) {
if (detectWeb(doc, url) == "multiple") {
Zotero.selectItems(getSearchResults(doc, false), function (items) {
if (!items) {
return;
}
var articles = [];
for (var i in items) {
articles.push(i);
}
ZU.processDocuments(articles, scrape);
});
}
else {
scrape(doc, url);
}
}
function scrape(doc, _url) {
var urlMarc = ZU.xpathText(doc, '(//a[contains(@title, "Scarico Marc21 del record") or contains(@title, "Download Marc21 record")]/@href)[1]');
// Z.debug(urlMarc);
ZU.doGet(urlMarc, function (text) {
// call MARC translator
var translator = Zotero.loadTranslator("import");
translator.setTranslator("a6ee60df-1ddc-4aae-bb25-45e0537be973");
translator.setString(text);
translator.translate();
});
}/** BEGIN TEST CASES **/
var testCases = [
{
"type": "web",
"url": "http://www.sbn.it/opacsbn/opaclib?db=solr_iccu&select_db=solr_iccu&saveparams=false&resultForward=opac%2Ficcu%2Ffull.jsp&searchForm=opac%2Ficcu%2Ffree.jsp&y=0&do_cmd=search_show_cmd&x=0&nentries=1&rpnlabel=+Tutti+i+campi+%3D+zotero+%28parole+in+AND%29+&rpnquery=%2540attrset%2Bbib-1%2B%2B%2540attr%2B1%253D1016%2B%2540attr%2B4%253D6%2B%2522zotero%2522&&fname=none&from=1",
"items": [
{
"itemType": "book",
"title": "Zotero: a guide for librarians, researchers and educators",
"creators": [
{
"firstName": "Jason",
"lastName": "Puckett",
"creatorType": "author"
}
],
"date": "2011",
"ISBN": "9780838985892",
"language": "eng",
"libraryCatalog": "sbn.it",
"numPages": "159",
"place": "Chicago (Ill.)",
"publisher": "Association of college and research libraries",
"shortTitle": "Zotero",
"attachments": [],
"tags": [],
"notes": [],
"seeAlso": []
}
]
},
{
"type": "web",
"url": "http://opac.sbn.it/opacsbn/opaclib?db=solr_iccu&rpnquery=%2540attrset%2Bbib-1%2B%2B%2540attr%2B1%253D1032%2B%2540attr%2B4%253D2%2B%2522VEA0102960%2522&totalResult=1&select_db=solr_iccu&nentries=1&rpnlabel=BID%3DVEA0102960&resultForward=opac%2Ficcu%2Ffull.jsp&searchForm=opac%2Ficcu%2Ferror.jsp&do_cmd=show_cmd&saveparams=false&&fname=none&from=1",
"items": [
{
"itemType": "book",
"title": "La qualità: un impegno per le biblioteche: atti delle quarte giornate di studio del Cnba, Torino 22-24 maggio 1997",
"creators": [
{
"lastName": "Coordinamento nazionale delle biblioteche di architettura",
"creatorType": "author",
"fieldMode": true
},
{
"firstName": "Ezio",
"lastName": "Tarantino",
"creatorType": "editor"
},
{
"firstName": "Giovanna",
"lastName": "Terranova",
"creatorType": "editor"
}
],
"date": "1998",
"callNumber": "026.72",
"language": "ita",
"libraryCatalog": "sbn.it",
"numPages": "158",
"place": "Roma",
"publisher": "CNBA Coordinamento nazionale biblioteche di architettura",
"shortTitle": "La qualità",
"attachments": [],
"tags": [],
"notes": [],
"seeAlso": []
}
]
},
{
"type": "web",
"url": "http://www.sbn.it/opacsbn/opaclib?db=solr_iccu&select_db=solr_iccu&nentries=10&from=1&searchForm=opac/iccu/error.jsp&resultForward=opac/iccu/brief.jsp&do_cmd=show_cmd&rpnlabel=+Any+%3D+google+%28words+in+AND%29+&rpnquery=%40attrset+bib-1++%40attr+1%3D1016+%40attr+4%3D6+%22google%22&totalResult=186",
"items": "multiple"
}
]
/** END TEST CASES **/