summaryrefslogtreecommitdiff
path: root/LIbrary Catalog (SLIMS).js
blob: 979b00b957b6bb0ae76950ef6eaf0537004870e6 (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
{
	"translatorID": "fc3ac6f7-b461-49fe-879c-dd234f9c101c",
	"label": "LIbrary Catalog (SLIMS)",
	"creator": "Sebastian Karcher",
	"target": "(^https?://makassarlib\\.net|^https?://kit\\.ft\\.ugm\\.ac\\.id/ucs|/libsenayan)/index\\.php",
	"minVersion": "2.1",
	"maxVersion": "",
	"priority": 250,
	"inRepository": true,
	"translatorType": 4,
	"browserSupport": "gcv",
	"lastUpdated": "2014-08-26 04:10:09"
}

/*
	***** BEGIN LICENSE BLOCK *****
	
	Copyright © 2013 Sebastian Karcher
	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.match(/show_detail&id=/)) return "book";
	else if (ZU.xpathText(doc, '//div[contains(@class, "item alterList")]/a')) return "multiple"
	
}
	

function doWeb(doc, url){

	var articles = new Array();
	if(detectWeb(doc, url) == "multiple") { 
		var items = {};
		var titles = doc.evaluate('//div[contains(@class, "item alterList")]/a', doc, null, XPathResult.ANY_TYPE, null);
		var title;
		while (title = titles.iterateNext()) {
			items[title.href] = title.textContent;
		}
		Zotero.selectItems(items, function (items) {
			if (!items) {
				return true;
			}
			for (var i in items) {
				articles.push(i.replace(/(&id=[^&^\?]+)/, "&inXML=true$1"));
			}
			scrape(articles);	
		});
	} else {
		var modsurl = url.replace(/(&id=[^&^\?]+)/, "&inXML=true$1");
		scrape([modsurl]);
	}
}

// help function
function scrape(articles){
	for(i in articles){
	var modsurl = articles[i];
	//Z.debug(modsurl)
	Zotero.Utilities.HTTP.doGet(modsurl, function (text) {	
		//they seem to be handling marctype bibliography as the main genre for books we handle this hear to not lose info in MODS import
		text = text.replace(/bibliography\<\/genre\>/, "book</genre>")
		var translator = Zotero.loadTranslator("import");
		translator.setTranslator("0e2235e7-babf-413c-9acf-f27cce5f059c");
		translator.setString(text);
		translator.setHandler("itemDone", function(obj, item) {
			//creators are entered poorly
			for (j in item.creators){
				if (item.creators[j].lastName && item.creators[j].lastName.indexOf(",")!=-1){
					item.creators[j] = ZU.cleanAuthor(item.creators[j].lastName, item.creators[j].creatorType, true)
				}
			}
			//add catalog entry as permalink
			item.attachments.push({url: modsurl.replace(/&inXML=true/, ""), title: "SLIMS Library Catalog Permalink", mimeType: "text/html", snapshot: false})
			item.complete();
		});	
		translator.translate();
	});
	}
}/** BEGIN TEST CASES **/
var testCases = [
	{
		"type": "web",
		"url": "http://perpustakaan.kemdikbud.go.id/libsenayan/index.php?p=show_detail&id=28002",
		"items": [
			{
				"itemType": "book",
				"creators": [
					{
						"firstName": "John W.",
						"lastName": "Budd",
						"creatorType": "author"
					}
				],
				"notes": [
					{
						"note": "Includes bibliographical references and indexes.;"
					}
				],
				"tags": [
					"Industrial relations"
				],
				"seeAlso": [],
				"attachments": [
					{
						"title": "SLIMS Library Catalog Permalink",
						"mimeType": "text/html",
						"snapshot": false
					}
				],
				"title": "Labor relations : striking a balance",
				"numPages": "553",
				"ISBN": "9780072842",
				"place": "Boston, Mass. :",
				"publisher": "McGraw-Hill,",
				"date": "2005",
				"callNumber": "331.880973",
				"archiveLocation": "Perpustakaan Kemendikbud Pusat Informasi dan Humas, Kemendikbud",
				"language": "English",
				"libraryCatalog": "LIbrary Catalog (SLIMS)",
				"shortTitle": "Labor relations"
			}
		]
	},
	{
		"type": "web",
		"url": "http://perpustakaan.kemdikbud.go.id/libsenayan/index.php?keywords=labor&search=Search",
		"items": "multiple"
	}
]
/** END TEST CASES **/