summaryrefslogtreecommitdiff
path: root/DART-Europe.js
blob: b1d4d328a8a6bf99b1319b48aebefefd30b35716 (plain)
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
{
	"translatorID": "658f2707-bb46-44eb-af0a-e73a5387fc90",
	"label": "DART-Europe",
	"creator": "Sebastian Karcher",
	"target": "^https?://www\\.dart-europe\\.eu",
	"minVersion": "3.0",
	"maxVersion": "",
	"priority": 100,
	"inRepository": true,
	"translatorType": 4,
	"browserSupport": "gcsibv",
	"lastUpdated": "2013-04-17 03:09:28"
}

/**
	Copyright (c) 2013 Sebastian Karcher

	This program 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.

	This program 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 this program.  If not, see
	<http://www.gnu.org/licenses/>.
*/




function detectWeb(doc, url) {
	if (url.indexOf("full.php?") != -1) return "thesis";
	if (url.indexOf("results.php?") != -1) return "multiple";
	
}


function scrape(doc, url) {
	var newItem = new Zotero.Item("thesis");
	var title = ZU.xpathText(doc, '//tr[contains(@class, "result")]/th[@class="field-name" and contains(text(), "Title")]/following-sibling::td');
	var thesisType = ZU.xpathText(doc, '//tr[contains(@class, "result")]/th[@class="field-name" and contains(text(), "Type")]/following-sibling::td');
	var date = ZU.xpathText(doc, '//tr[contains(@class, "result")]/th[@class="field-name" and contains(text(), "Date")]/following-sibling::td');
	var language = ZU.xpathText(doc, '//tr[contains(@class, "result")]/th[@class="field-name" and contains(text(), "Language")]/following-sibling::td');
	var abstract = ZU.xpathText(doc, '//tr[contains(@class, "result")]/th[@class="field-name" and contains(text(), "Abstract")]/following-sibling::td');
	var publisherinfo = ZU.xpathText(doc, '//tr[contains(@class, "result")]/th[@class="field-name" and contains(text(), "Publisher")]/following-sibling::td');
	var fulltext = ZU.xpathText(doc, '//tr[th[@class="field-name" and contains(text(), "Identifier")]][1]/th[@class="field-name" and contains(text(), "Identifier")]/following-sibling::td');

	//Publisher field may have place
	var place;
	if (publisherinfo && publisherinfo.indexOf(":") !=-1){
		var publisher = publisherinfo.match(/:\s*(.+)/)[1]
		var place =publisherinfo.match(/(.+):/)[1]
	}
	else var publisher = publisherinfo;

	//Authors and Tags can have multiple rows. In that case the td[1] remains empty we loop through them until that's no longer the case

	var author = ZU.xpathText(doc, '//tr[contains(@class, "result")]/th[@class="field-name" and contains(text(), "Author")]/following-sibling::td');
	if (author) newItem.creators.push(ZU.cleanAuthor(author, "author", true))


	var tags = ZU.xpathText(doc, '//tr[contains(@class, "result")]/th[@class="field-name" and contains(text(), "Subject(s)")]/following-sibling::td');
	if (tags) {
	tags = tags.split(/\s*,\s*/);
		for (var i in tags) {
			newItem.tags.push(tags[i])
		}
	}

	if (fulltext) {
		fulltext = fulltext.trim();
		if (fulltext.search(/\.pdf/) != -1) {
			newItem.attachments.push({
				url: fulltext,
				title: "Dart-Europe Full Text PDF",
				mimeType: "application/pdf"
			})
		} else if (fulltext.search(/http\:\/\//) != -1){
			newItem.attachments.push({
				url: fulltext,
				title: "DART-Europe Thesis Page",
				mimeType: "text/html"
			})
		}
	}
	newItem.attachments.push({
		document: doc,
		title: "DART-Europe Record Snapshot",
		mimeType: "text/html"
	})
	newItem.title = title;
	newItem.thesisType = thesisType;
	newItem.date = date;
	newItem.abstractNote = abstract;
	newItem.language = language;
	newItem.publisher = publisher;
	newItem.place = place;
	newItem.complete();
}


function doWeb(doc, url) {

	var articles = new Array();
	var items = {};
	if (detectWeb(doc, url) == "multiple") {
		//this currently doesn't do anything as multiple detect is disabled
		var titles = doc.evaluate('//table[@id="search-results"]//a[contains(@href, "full.php?")]', doc, null, XPathResult.ANY_TYPE, null);
		var next_title;
		while (next_title = titles.iterateNext()) {
			items[next_title.href] = next_title.textContent;
		}

		Zotero.selectItems(items, function (items) {
			if (!items) {
				return true;
			}
			for (var i in items) {
				articles.push(i);
			}
			Z.debug(articles)
			Zotero.Utilities.processDocuments(articles, scrape);
		})
	} else {
		scrape(doc, url);
	}
}
/** BEGIN TEST CASES **/
var testCases = [
	{
		"type": "web",
		"url": "http://www.dart-europe.eu/basic-results.php?kw[]=labor&f=n&hist=y",
		"items": "multiple"
	},
	{
		"type": "web",
		"url": "http://www.dart-europe.eu/full.php?id=284332",
		"items": [
			{
				"itemType": "thesis",
				"creators": [
					{
						"firstName": "Charles Edmund Richard",
						"lastName": "Pennell",
						"creatorType": "author"
					}
				],
				"notes": [],
				"tags": [],
				"seeAlso": [],
				"attachments": [
					{
						"title": "Dart-Europe Full Text PDF",
						"mimeType": "application/pdf"
					},
					{
						"title": "DART-Europe Record Snapshot",
						"mimeType": "text/html"
					}
				],
				"title": "A critical investigation of the opposition of the Rifi confederation led by Muhammed bin 'Abd al-Karim al-Khattabi to Spanish colonial expansion in northern Morocco, 1920-1925, and its political and social background",
				"thesisType": "Thesis, NonPeerReviewed",
				"date": "1979",
				"abstractNote": "This thesis examines the course and political\naction of the war in the Rif mountains in northern Morocco\nbetween 1921 and 1926.\n\nAfter the declaration of a joint Franco-Spanish\nProtectorate over Morocco in 1912, the Spanish army\nattempted to impose its authority over the part of north\nMorocco which was included in its zone. After the end of\nthe First World War the Spanish were opposed in their\nefforts by a slowly growing coalition of tribes in the\ncentral Rif mountains. After the emergence of Mubammad\nbin 'Abd al-Karim al-Khattdbl as leader of the coalition,\nit was able to inflict a series of military defeats on the\nSpanish in the summer of 1921, a success which led to the'\nexpansion of the coalition and, in 1923, to the announcement\nof an independent state in the Rif under the leadership of\nbin 'Abd al-Karim.\n\nThis state was able to defeat another Spanish army\nin 1924 and, in 1925, to inflict a series of defeats upon\nthe French army in that, country's zone of Protectorate,\nbefore an alliance between France and Spain crushed the new\nstate in 1926.\n\nPrevious work has concentrated more on the\nmilitary aspects of the conflict from a European point of\nview, and examination of the Moroccan side has dwelt almost\nexclusively on the personality of the Rifi leader, bin 'Abd\nal-Karim. This thesis, however, is concerned with the\npolitical and social aspects of the war from the Moroccan\npoint of view. While it recognises the importance of bin\n'Abd al-Karim, it tries to explain his role in terms of his\npolitical position in Rifi society as'a whole. It examines\nhis political, social. and religious reforms'l not only from\nthe point of view of their importance in the overall--\nmovement for Islamic reform, but also from that of their\npractical necessity and effects.",
				"publisher": "University of Leeds",
				"libraryCatalog": "DART-Europe"
			}
		]
	}
]
/** END TEST CASES **/