This repository has been archived by the owner on Jan 3, 2020. It is now read-only.
forked from zotero/translators
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNational Library of Belarus.js
171 lines (146 loc) · 4.95 KB
/
National Library of Belarus.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
{
"translatorID": "89592f50-6ae8-491e-8988-969002012b1b",
"label": "National Library of Belarus",
"creator": "Philipp Zumstein",
"target": "https?://www\\.nlb\\.by/portal/page/portal/index/resources/(basicsearch|expandedsearch|anothersearch|authoritet|newdoc|top100)",
"minVersion": "3.0",
"maxVersion": "",
"priority": 100,
"inRepository": true,
"translatorType": 4,
"browserSupport": "gcsibv",
"lastUpdated": "2014-09-25 20:54:14"
}
/*
***** BEGIN LICENSE BLOCK *****
Copyright © 2014 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 *****
*/
function detectWeb(doc, url) {
if (url.indexOf('strutsAction=biblinfoaction.do') != -1 && getMarcNode(doc).length>0 ) {//single item
return "book";
} else if (getSearchResults(doc, true)) {
return "multiple";
}
}
//for testing in detectWeb use true for checkOnly
//for the items in doWeb use false for checkOnly
//then the items will be an object containing the href/title pairs
function getSearchResults(doc, checkOnly) {
var items = {};
var found = false;
var rows = ZU.xpath(doc, '//div[@id="search_result" or @id="expandedsearchView"]//td[contains(@class, "link")]//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 (title != "") {
if (checkOnly) return true;
found = true;
items[href] = title;
}
}
return found ? items : false;
}
function getMarcNode(doc) {//the node in the DOM contains the BELMARC data
return ZU.xpath(doc, '//div[contains(@id, "belmarc")]//td[not(contains(@class, "fon_gray"))]/font[contains(@class, "tekst")]');
}
function doWeb(doc, url) {
if (detectWeb(doc, url) == "multiple") {
Zotero.selectItems(getSearchResults(doc, false), function (items) {
if (!items) {
return true;
}
var articles = new Array();
for (var i in items) {
articles.push(i);
}
ZU.processDocuments(articles, scrape);
});
} else {
scrape(doc, url);
}
}
function scrape(doc, url) {
var children = getMarcNode(doc)[0].childNodes;
var lines = [];
for (var i=0; i<children.length; i++) {
if (children[i].nodeType == 3) {//ignore <br> nodes, only textNodes
var text = ZU.trimInternal(children[i].textContent) ;
if (text.length>0) {
lines.push(text);
}
}
}
//Z.debug(lines);
//call MARC translator
var translator = Zotero.loadTranslator("import");
translator.setTranslator("a6ee60df-1ddc-4aae-bb25-45e0537be973");
translator.getTranslatorObject(function (marc) {
var record = new marc.record();
var newItem = new Zotero.Item();
record.leader = lines[0];
for (var j=1; j<lines.length; j++) {
var currentLine = lines[j];
var fieldTag = currentLine.substr(0,3);
var indicators;
var fieldContent;
if (fieldTag.substr(0,2) == "00") {
indicators = "";
fieldContent = currentLine.substr(4);
} else {
indicators = currentLine.substr(4,2);
fieldContent = currentLine.substr(7).replace(/\$(\w)\s*/g, marc.subfieldDelimiter+"$1");
}
record.addField( fieldTag, indicators, fieldContent);
}
record.translate(newItem);
record._associateDBField(newItem, 899, "p", "callNumber");
record._associateDBField(newItem, 215, "a", "numPages");//this field may contain more information about the extent of a book, therefore we do here on porpuse no more cleaning of the number only (has to be done manually)
record._associateTags(newItem, 606, "a");
newItem.complete();
});
}/** BEGIN TEST CASES **/
var testCases = [
{
"type": "web",
"url": "http://www.nlb.by/portal/page/portal/index/resources/expandedsearch?classId=B33E739B22884D82AACAC24EBFB1DA89&submitR=empty&_piref73_180746_73_34794_34794.biId=386521&_piref73_180746_73_34794_34794.strutsAction=biblinfoaction.do&lang=en",
"items": [
{
"itemType": "book",
"title": "Vibrational states in deformed nuclei.Chaos,order and individual nature of nuclei",
"creators": [
{
"firstName": "V. G. V. G.",
"lastName": "Soloviev ",
"creatorType": "author"
}
],
"date": "1993",
"callNumber": "1Ок25736(ДХ)",
"language": "eng",
"libraryCatalog": "National Library of Belarus",
"numPages": "20p",
"place": "Dubna",
"series": "Prepr",
"seriesNumber": "E4-93-223--",
"attachments": [],
"tags": [],
"notes": [],
"seeAlso": []
}
]
}
]
/** END TEST CASES **/