summaryrefslogtreecommitdiff
path: root/Library Catalog (Aquabrowser).js
blob: 54e8d1119aecb6bc613892a4c4f839154bb7d875 (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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
{
	"translatorID": "915c326f-06c5-4833-b7b7-54c63f88b135",
	"label": "Library Catalog (Aquabrowser)",
	"creator": "Sebastian Karcher",
	"target": "/fullrecordinnerframe\\.ashx\\?.+id=|/result\\.ashx\\?",
	"minVersion": "3.0",
	"maxVersion": "",
	"priority": 270,
	"inRepository": true,
	"translatorType": 4,
	"browserSupport": "gcsbv",
	"lastUpdated": "2014-08-26 03:51:35"
}

/*
	***** BEGIN LICENSE BLOCK *****
	
	Copyright © 2011 Sebastian Karcher and the Center for History and New Media
					 George Mason University, Fairfax, Virginia, USA
					 http://zotero.org
	
	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 *****
*/

/* other working implementations: 
http://zoeken.oba.nl/
http://aquabrowser.lib.ed.ac.uk
http://boss.library.okstate.edu/

Not working bc export isn't implemented: None of these are academic, so I'm not particularly worried
http://cabrio.bibliotheek.brugge.be/
http://aquabrowser.selco.info/?c_profile=rw
http://kcaqua.kclibrary.org
http://aquabrowser.biboostende.be/
http://abl.courthouselibrary.ca/
http://leocat.saintleo.edu
*/

function detectWeb(doc, url) {
	if (url.match(/\/result\.ashx\?/) && ZU.xpath(doc, '//div[@class="titlenew"]//a[@class="classiclink"]').length>0) return "multiple";
	if (url.match(/\/fullrecordinnerframe\.ashx\?.+id=/)) return "book";
}
	

function doWeb(doc, url){

	var articles = new Array();
	if(detectWeb(doc, url) == "multiple") { 
		var items = {};
		var titles = doc.evaluate('//div[@class="titlenew"]//a[@class="classiclink"]', doc, null, XPathResult.ANY_TYPE, null);
		var title;
		var id;
		while (title = titles.iterateNext()) {
			items[title.href] = ZU.trimInternal(title.textContent);
		}
		Zotero.selectItems(items, function (items) {
			if (!items) {
				return true;
			}
			for (var i in items) {
				//some implementations don't have direct links, just the id in javascript
				if (i.search(/^javascript/)!=-1){
					//remove the javascript escaping
					i=i.replace(/\\/g, "");
					id = "itemid=" + i.match(/\(\'(.+?)\'/)[1];
				}
				else id = i.match(/[^&\?]+id=[^&]+/)[0]
				articles.push(makeURL(id));
			}
			//Z.debug(articles)
			scrape(articles);
		});
	} else {
		var id = url.match(/[^&\?]+id=[^&]+/)[0];
		var risurl = makeURL(id);
		scrape (risurl);
	}
}

function makeURL(id){
	var idnumber = id.match(/=(.+)/)[1];
	var risurl = "/export.ashx?type=export-ris&app=endnote&file=" +idnumber + "&" + id;
	return risurl;
}


function scrape(risurl){
	Zotero.Utilities.HTTP.doGet(risurl, function (text) {
		//I'll leave this debugging in for the time being
		Z.debug("This should be RIS: " + text)
		//fix years - we don't like letters immediately before dates
		text = text.replace(/(Y  - )[A-Za-z]+(\d{4})/, "$1$2");
		//apparently the RIS doesn't do well with item types
		text = text.replace(/TY  - (Boek|GEN)/, "TY  - BOOK");
		
		var translator = Zotero.loadTranslator("import");
		translator.setTranslator("32d59d2d-b65a-4da4-b0a3-bdd3cfb979e7");
		translator.setString(text);
		translator.setHandler("itemDone", function(obj, item) {
			if (item.pages) item.numPages = item.pages;
			//remove space before :
			item.title = item.title.replace(/\s+:/, ":");
			for (i in item.creators){
				//for some reason there's often a period after the first name of authors. Delete this, making sure it's not an initial
				if (item.creators[i].firstName){
					item.creators[i].firstName = item.creators[i].firstName.replace(/([a-z]+)\.\s*$/, "$1");
				}
			}
			item.url = "";
			item.complete();
		});	
		translator.translate();
	});
}/** BEGIN TEST CASES **/
var testCases = [
	{
		"type": "web",
		"url": "http://lens.lib.uchicago.edu/result.ashx?inlibrary=false&noext=false&debug=&lastquery=&lvq=&lsi=&uilang=en&searchmode=assoc&hardsort=&skin=hybrid-uc&rctx=&c_over=1&curpage=1&concept=institutions&branch=&ref=&i_fk=&mxdk=-1&q=institutions&si=user&cs=user&cmd=find#",
		"items": "multiple"
	},
	{
		"type": "web",
		"url": "http://lens.lib.uchicago.edu/fullrecordinnerframe.ashx?skin=hybrid-uc&cmd=frec&cs=url&hreciid=|library%2fmarc%2fuc|4857057",
		"items": [
			{
				"itemType": "book",
				"creators": [
					{
						"lastName": "Turner",
						"firstName": "Jonathan H.",
						"creatorType": "author"
					}
				],
				"notes": [
					{
						"note": "<p>Includes bibliographical references (p. 283-300) and indexes.</p>"
					}
				],
				"tags": [
					"Social institutions.",
					"Social evolution."
				],
				"seeAlso": [],
				"attachments": [],
				"title": "Human institutions: a theory of societal evolution",
				"place": "Lanham",
				"publisher": "Rowman & Littlefield",
				"ISBN": "0742525589 (cloth : alk. paper)",
				"numPages": "xiv, 309 p.",
				"abstractNote": "1. Institutional Analysis -- 2. A Theory of Macrodynamic Forces -- 3. The Institutional Core -- 4. Institutional Systems of Hunter-Gatherer Populations -- 5. Institutional Systems of Horticultural Populations -- 6. Institutional Systems of Agrarian Populations -- 7. Institutional Systems of Industrial and Post-industrial Populations -- 8. Fundamental Interchanges Among Institutions.",
				"callNumber": "HM826 .T87 2003 Regenstein, Bookstacks",
				"date": "2003",
				"libraryCatalog": "Library Catalog (Aquabrowser)",
				"shortTitle": "Human institutions"
			}
		]
	},
	{
		"type": "web",
		"url": "http://hollis.harvard.edu/result.ashx?inlibrary=false&noext=false&debug=&lastquery=&lvq=&lsi=&uilang=en&searchmode=assoc&hardsort=&skin=harvard&c_over=1&curpage=1&concept=thelen&branch=&ref=&i_fk=&mxdk=-1&q=thelen&si=user&cs=url&cmd=find",
		"items": "multiple"
	},
	{
		"type": "web",
		"url": "http://hollis.harvard.edu/fullrecordinnerframe.ashx?skin=harvard&cmd=frec&cs=url&hreciid=%7clibrary%2fm%2faleph%7c001633883&curpage=1&uilang=en&c_over=1&rctx=AAMAAAABAAAAAwAAAKRSAAAHaGFydmFyZAAAAAAAAAAEZnJlYwAafGxpYnJhcnkvbS9hbGVwaHwwMDE2MzM4ODMAAAADdXJsBWFzc29jAQAAAAAAAAACZW4AAP%2f%2f%2f%2f8AAAAAAAAAAAIAAAAGY19vdmVyATEEaV9mawAAAAAA",
		"items": [
			{
				"itemType": "book",
				"creators": [
					{
						"lastName": "Thelen",
						"firstName": "Christian",
						"creatorType": "author"
					}
				],
				"notes": [
					{
						"note": "<p>Includes bibliographical references (p. [703]-726) and index.</p>"
					},
					{
						"note": "<p>HOLLIS no. 001633883</p>"
					}
				],
				"tags": [
					"German literature -- Middle High German, 1050-1500 -- History and criticism.",
					"German literature -- Old High German, 750-1050 -- History and criticism.",
					"Prayer in literature.",
					"Prayers, Medieval."
				],
				"seeAlso": [],
				"attachments": [],
				"title": "Das Dichtergebet in der deutschen Literatur des Mittelalters",
				"place": "Berlin ;New York",
				"publisher": "W. De Gruyter",
				"ISBN": "3110116715",
				"numPages": "x, 726 p.",
				"callNumber": "Widener Harvard Depository PT573.R4 T4 1989x [Consult Circ. Desk for HX45IM]",
				"series": "Arbeiten zur Frühmittelalterforschung ; Bd. 18",
				"volume": "Bd. 18",
				"date": "1989",
				"libraryCatalog": "Library Catalog (Aquabrowser)"
			}
		]
	},
	{
		"type": "web",
		"url": "http://aquabrowser.hhs.nl/fullrecordinnerframe.ashx?skin=hhs&q=institutions&cmd=frec&si=user&cs=resultlist&hreciid=|library%2fhhs|20438",
		"items": [
			{
				"itemType": "book",
				"creators": [
					{
						"lastName": "Erskine",
						"firstName": "Toni",
						"creatorType": "seriesEditor"
					}
				],
				"notes": [],
				"tags": [
					"Internationale organisaties",
					"Ethische aspecten"
				],
				"seeAlso": [],
				"attachments": [],
				"title": "Can institutions have responsibilities?",
				"series": "collective moral agency and international relations",
				"numPages": "XII, 241 p",
				"place": "Basingstoke [etc.]",
				"publisher": "Palgrave Macmillan",
				"ISBN": "0333971299",
				"abstractNote": "Assigning responsibilities to institutional moral agents : the case of states and 'quasi-states' / Toni Erskine -- Moral responsibility and the problem of representing the state / David Runiciman -- Moral agency and international society : reflections on norms, the UN, the Gulf War, and the Kosovo campaign / Chris Brown -- Collective moral agency and the political process / Frances V. Harbour -- Constitutive theory and moral accountability : individuals, institutions, and dispersed practices / Mervyn Frost -- When agents cannot act : international institutions as 'moral patients' / Cornelia Navari -- NATO and the individual soldier as moral agents with reciprocal duties : imbalance in the Kosovo campaign / Paul Cornish, Frances V. Harbour -- The anti-sweatshop movement : constructing corporate moral agency in the global apparel industry / Rebecca DeWinter -- The responsibility of collective external bystanders in cases of genocide : the French in Rwanda / Daniela Kroslak -- The United Nations and the fall of Srebrenica : meaningful responsibility and international society / Anthony Lang, Jr. -- On 'good global governance', institutional design, and the practices of moral agency / Nicholas Rengger -- Global justice: aims, arrangements, and responsibilities / Christian Barry",
				"date": "2003",
				"libraryCatalog": "Library Catalog (Aquabrowser)"
			}
		]
	}
]
/** END TEST CASES **/