Skip to content

Commit 17766be

Browse files
committed
Add translator for DigiZeitschriften
1 parent e181672 commit 17766be

File tree

1 file changed

+292
-0
lines changed

1 file changed

+292
-0
lines changed

DigiZeitschriften.js

+292
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,292 @@
1+
{
2+
"translatorID": "e46830a2-1b19-4b6b-9f1a-e5e9760a0f80",
3+
"label": "DigiZeitschriften",
4+
"creator": "Philipp Zumstein",
5+
"target": "^https?://www\\.digizeitschriften\\.de/((en/)?dms/|index\\.php\\?id=27[24])",
6+
"minVersion": "3.0",
7+
"maxVersion": "",
8+
"priority": 100,
9+
"inRepository": true,
10+
"translatorType": 4,
11+
"browserSupport": "gcsv",
12+
"lastUpdated": "2014-05-08 23:06:53"
13+
}
14+
15+
/*
16+
***** BEGIN LICENSE BLOCK *****
17+
18+
DigiZeitschriften Translator, Copyright © 2014 Philipp Zumstein
19+
This file is part of Zotero.
20+
21+
Zotero is free software: you can redistribute it and/or modify
22+
it under the terms of the GNU Affero General Public License as published by
23+
the Free Software Foundation, either version 3 of the License, or
24+
(at your option) any later version.
25+
26+
Zotero is distributed in the hope that it will be useful,
27+
but WITHOUT ANY WARRANTY; without even the implied warranty of
28+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29+
GNU Affero General Public License for more details.
30+
31+
You should have received a copy of the GNU Affero General Public License
32+
along with Zotero. If not, see <http://www.gnu.org/licenses/>.
33+
34+
***** END LICENSE BLOCK *****
35+
*/
36+
37+
function detectWeb(doc, url) {
38+
if (url.indexOf("/img/") != -1 || url.indexOf("index.php?id=274") != -1 ) {//e.g. http://www.digizeitschriften.de/index.php?id=274&PPN=PPN342672002_0020&DMDID=dmdlog84&L=2
39+
return "journalArticle";
40+
} else if ( (url.indexOf("/toc/") != -1 || url.indexOf("index.php?id=272")) && getSearchResults(doc).length>0) {
41+
return "multiple";
42+
}
43+
}
44+
45+
46+
function getSearchResults(doc) {
47+
return ZU.xpath(doc, '//span[contains(@class, "sitetitle") and ./parent::a/following-sibling::div]');
48+
}
49+
50+
function doWeb(doc, url) {
51+
var articles = new Array();
52+
if (detectWeb(doc, url) == "multiple") {
53+
var items = {};
54+
var titles = getSearchResults(doc);
55+
for (var i=0; i<titles.length; i++) {
56+
items[titles[i].parentNode.href] = titles[i].textContent;
57+
}
58+
Zotero.selectItems(items, function (items) {
59+
if (!items) {
60+
return true;
61+
}
62+
for (var i in items) {
63+
articles.push(i);
64+
}
65+
ZU.processDocuments(articles, scrape);
66+
});
67+
} else {
68+
scrape(doc, url);
69+
}
70+
}
71+
72+
73+
function extractField(fieldName, text) {
74+
//extracts the value of the field with the name 'fieldName'
75+
//in the text 'text' and returns it
76+
var expression = new RegExp("<span>\\s*<strong>\\s*"+fieldName+":?\\s*</strong>\\s*</span>\\s*<span>([^<]*)</span>");
77+
var extraction = text.match(expression);
78+
if (extraction) {
79+
return extraction[1];
80+
} else {
81+
return false;
82+
}
83+
}
84+
85+
86+
function scrape(doc, url) {
87+
var metadataUrl = ZU.xpath(doc, '//ul[@id="submenu"]/li[2]/a')[0].href.replace("/en/", "/");
88+
var item = new Zotero.Item("journalArticle");
89+
ZU.doGet(metadataUrl, function(text) {
90+
var structure = {};
91+
var type;
92+
var posBefore = text.indexOf('<ul xmlns:mods="http://www.loc.gov/mods/v3">');
93+
var posAfter = text.indexOf('<ul xmlns:mods="http://www.loc.gov/mods/v3">', posBefore+1);
94+
while (posAfter>-1) {
95+
type = extractField("Strukturtyp", text.substring(posBefore, posAfter) );
96+
structure[type] = [posBefore, posAfter];
97+
posBefore = posAfter;
98+
posAfter = text.indexOf('<ul xmlns:mods="http://www.loc.gov/mods/v3">', posBefore+1);
99+
}
100+
type = extractField("Strukturtyp", text.substring(posBefore) );
101+
structure[type] = [posBefore, text.length];
102+
//Z.debug(structure);
103+
104+
var articleData;
105+
//check whether last type was article or something similar
106+
if (type != "Zeitschrift" && type != "Zeitschriftenband" && type != "Zeitschriftheft" && type != "Zeitschriftenteil") {
107+
articleData = text.substring(structure[type][0], structure[type][1]);
108+
} else {
109+
Z.debug(structure);
110+
throw new Error('Unsupported item type.');
111+
}
112+
113+
item.title = extractField("Titel", articleData );
114+
115+
var author = extractField("Autor", articleData );
116+
if (author) {
117+
item.creators.push( ZU.cleanAuthor( author, "author") );
118+
}
119+
120+
if (structure["Zeitschriftenheft"]) {
121+
var issueData = text.substring(structure["Zeitschriftenheft"][0], structure["Zeitschriftenheft"][1]);
122+
item.issue = extractField("Titel", issueData);
123+
}
124+
125+
if (structure["Zeitschriftenband"]) {
126+
var volumeData = text.substring(structure["Zeitschriftenband"][0], structure["Zeitschriftenband"][1]);
127+
item.publication = extractField("Titel", volumeData );
128+
item.volume = extractField("Band", volumeData );
129+
item.date = extractField("Erscheinungsjahr", volumeData );
130+
item.publisher = extractField("Verlag", volumeData );
131+
}
132+
133+
if (structure["Zeitschrift"]) {
134+
var journalData = text.substring(structure["Zeitschrift"][0], structure["Zeitschrift"][1]);
135+
item.place = extractField("Erscheinungsort", journalData );
136+
item.issn = extractField("ISSN", journalData );
137+
}
138+
139+
var pages = ZU.xpathText(doc, '(//span[contains(@class, "struct")])[last()]');
140+
pages = pages.match(/(?:\d+\s*-\s*)?\d+\s*$/);
141+
if (pages) item.pages = pages[0].replace(/\s+/g, '');
142+
143+
item.attachments = [{
144+
title: "Snapshot",
145+
document:doc
146+
}];
147+
148+
item.complete();
149+
});
150+
151+
}
152+
/** BEGIN TEST CASES **/
153+
var testCases = [
154+
{
155+
"type": "web",
156+
"url": "http://www.digizeitschriften.de/dms/img/?PPN=PPN356261603_0054&DMDID=dmdlog15",
157+
"items": [
158+
{
159+
"itemType": "journalArticle",
160+
"creators": [
161+
{
162+
"firstName": "Wolfgang",
163+
"lastName": "Schuster",
164+
"creatorType": "author"
165+
}
166+
],
167+
"notes": [],
168+
"tags": [],
169+
"seeAlso": [],
170+
"attachments": [
171+
{
172+
"title": "Snapshot"
173+
}
174+
],
175+
"title": "Quadratische Identitäten bei Polygonen.",
176+
"publication": "Aequationes Mathematicae",
177+
"volume": "54",
178+
"date": "1997",
179+
"publisher": "Birkhäuser",
180+
"place": "Basel",
181+
"issn": "0001-9054",
182+
"pages": "117-143",
183+
"libraryCatalog": "DigiZeitschriften"
184+
}
185+
]
186+
},
187+
{
188+
"type": "web",
189+
"url": "http://www.digizeitschriften.de/en/dms/img/?PPN=GDZPPN002612097",
190+
"items": [
191+
{
192+
"itemType": "journalArticle",
193+
"creators": [
194+
{
195+
"firstName": "Wolfgang",
196+
"lastName": "Schuster",
197+
"creatorType": "author"
198+
}
199+
],
200+
"notes": [],
201+
"tags": [],
202+
"seeAlso": [],
203+
"attachments": [
204+
{
205+
"title": "Snapshot"
206+
}
207+
],
208+
"title": "Quadratische Identitäten bei Polygonen.",
209+
"publication": "Aequationes Mathematicae",
210+
"volume": "54",
211+
"date": "1997",
212+
"publisher": "Birkhäuser",
213+
"place": "Basel",
214+
"issn": "0001-9054",
215+
"pages": "117-143",
216+
"libraryCatalog": "DigiZeitschriften"
217+
}
218+
]
219+
},
220+
{
221+
"type": "web",
222+
"url": "http://www.digizeitschriften.de/dms/img/?PPN=PPN379931524_0002&DMDID=dmdlog10",
223+
"items": [
224+
{
225+
"itemType": "journalArticle",
226+
"creators": [
227+
{
228+
"firstName": "Hans",
229+
"lastName": "Hermes",
230+
"creatorType": "author"
231+
}
232+
],
233+
"notes": [],
234+
"tags": [],
235+
"seeAlso": [],
236+
"attachments": [
237+
{
238+
"title": "Snapshot"
239+
}
240+
],
241+
"title": "Die Soundness des Prädikatenkalküls auf der Basis der Quineschen Regeln.",
242+
"publication": "Archiv für mathematische Logik und Grundlagenforschung",
243+
"volume": "2",
244+
"date": "1954/56",
245+
"publisher": "Kohlhammer",
246+
"place": "Berlin",
247+
"issn": "0003-9268",
248+
"pages": "68-77",
249+
"libraryCatalog": "DigiZeitschriften"
250+
}
251+
]
252+
},
253+
{
254+
"type": "web",
255+
"url": "http://www.digizeitschriften.de/dms/img/?PPN=GDZPPN002612097",
256+
"items": [
257+
{
258+
"itemType": "journalArticle",
259+
"creators": [
260+
{
261+
"firstName": "Wolfgang",
262+
"lastName": "Schuster",
263+
"creatorType": "author"
264+
}
265+
],
266+
"notes": [],
267+
"tags": [],
268+
"seeAlso": [],
269+
"attachments": [
270+
{
271+
"title": "Snapshot"
272+
}
273+
],
274+
"title": "Quadratische Identitäten bei Polygonen.",
275+
"publication": "Aequationes Mathematicae",
276+
"volume": "54",
277+
"date": "1997",
278+
"publisher": "Birkhäuser",
279+
"place": "Basel",
280+
"issn": "0001-9054",
281+
"pages": "117-143",
282+
"libraryCatalog": "DigiZeitschriften"
283+
}
284+
]
285+
},
286+
{
287+
"type": "web",
288+
"url": "http://www.digizeitschriften.de/dms/toc/?PPN=GDZPPN002612089",
289+
"items": "multiple"
290+
}
291+
]
292+
/** END TEST CASES **/

0 commit comments

Comments
 (0)