summaryrefslogtreecommitdiff
path: root/HLAS (historical).js
blob: 0340187bdc452ebfbd5b0ed68267b8f3bef6b9aa (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
{
	"translatorID": "9f52911f-e1b5-41f8-be66-b16982269e6a",
	"label": "HLAS (historical)",
	"creator": "Sebastian Karcher",
	"target": "^https?://lcweb2\\.loc\\.gov/cgi-bin/query",
	"minVersion": "3.0",
	"maxVersion": "",
	"priority": 100,
	"inRepository": true,
	"translatorType": 4,
	"browserSupport": "gcsv",
	"lastUpdated": "2013-06-01 14:47:30"
}

/*
	***** 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 *****
*/

function detectWeb(doc, url) {
	//Z.debug(doc.title)
	if (doc.title.indexOf("Search Results")!=-1 && ZU.xpathText(doc, '//p/table/tbody/tr[td/a[contains(@href, "/cgi-bin/query/D?hlasbib")]]')) return "multiple";
	if (doc.title.indexOf("Bibliographic Display")!=-1) return "book";
}
	

function doWeb(doc, url){

	var articles = new Array();
	if(detectWeb(doc, url) == "multiple") { 
		var items = {};
		var titlerows = doc.evaluate('//p/table/tbody/tr[td/a[contains(@href, "/cgi-bin/query/D?hlasbib")]]', doc, null, XPathResult.ANY_TYPE, null);
		while (titlerow = titlerows.iterateNext()) {
			var url = ZU.xpathText(titlerow, './td/a[contains(@href, "/cgi-bin/query/D")]/@href');
			var title = ZU.xpathText(titlerow, './td[2]')
			items[url] = title;
		}
		Zotero.selectItems(items, function (items) {
			if (!items) {
				return true;
			}
			for (var i in items) {
				articles.push(i);
			}
			Zotero.Utilities.processDocuments(articles, scrape);	
		});
	} else {
		scrape(doc, url);
	}
}


function scrape(doc, url){
	//scrape the LC control number from the page and get LoC catalog data for it via SRU
	var idnumbers = ZU.xpathText(doc, '//body/p[b[contains(text(), "LC Control No")]]');
	if (idnumbers) var LCcontrol = idnumbers.match(/LC Control No\:\s*(\d+)/)[1]
	Z.debug(LCcontrol)
	ZU.doGet("http://lx2.loc.gov:210/LCDB?operation=searchRetrieve&version=1.1&query=bath.LCCN=" + LCcontrol + "&maximumRecords=1", function (text) {
		//Z.debug(text);
		var translator = Zotero.loadTranslator("import");
		translator.setTranslator("edd87d07-9194-42f8-b2ad-997c4c7deefd");
		translator.setString(text);
		translator.translate();
	});
}/** BEGIN TEST CASES **/
var testCases = [
	{
		"type": "web",
		"url": "http://lcweb2.loc.gov/cgi-bin/query/r?hlas/hlasbib,hlasretro,:@FIELD(FLD001+@od1(bi%2090010102))",
		"items": [
			{
				"itemType": "book",
				"creators": [
					{
						"firstName": "Laszlo",
						"lastName": "Horvath",
						"creatorType": "author"
					},
					{
						"lastName": "Hoover Institution on War, Revolution, and Peace",
						"fieldMode": true
					},
					{
						"lastName": "Stanford University",
						"fieldMode": true
					}
				],
				"notes": [],
				"tags": [
					"Perón, Juan Domingo",
					"Bibliography Catalogs",
					"Perón, Eva",
					"Bibliography Catalogs",
					"Perón, Isabel",
					"Bibliography Catalogs",
					"Peronism",
					"Bibliography Catalogs",
					"Peronism",
					"Manuscripts Catalogs",
					"Peronism",
					"Sources Bibliography Catalogs",
					"Argentina",
					"History Bibliography Catalogs",
					"1943-"
				],
				"seeAlso": [],
				"attachments": [],
				"ISBN": "0817927123",
				"title": "Peronism and the three Perons: a checklist of material on peronism and on Juan Domingo, Eva, and Isabel Peron, and their writings, in the Hoover Institution library and archives and in the Stanford University Libraries",
				"place": "Stanford, CA",
				"publisher": "Hoover Institution, Stanford University",
				"date": "1988",
				"numPages": "170",
				"series": "Hoover Press bibliography",
				"seriesNumber": "71",
				"callNumber": "Z1630.3 F2849 .H67 1988",
				"libraryCatalog": "HLAS (historical)",
				"shortTitle": "Peronism and the three Perons"
			}
		]
	}
]
/** END TEST CASES **/