summaryrefslogtreecommitdiff
path: root/zotero-import/ISI Web of Knowledge.js
blob: eb487496209ee95281088566beb870f10f66a6d3 (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
{
	"translatorID":"594ebe3c-90a0-4830-83bc-9502825a6810",
	"translatorType":4,
	"label":"ISI Web of Knowledge",
	"creator":"Michael Berkowitz",
	"target":"(WOS_GeneralSearch|product=WOS)",
	"minVersion":"1.0.0b4.r5",
	"maxVersion":"",
	"priority":100,
	"inRepository":true,
	"lastUpdated":"2009-02-25 07:10:00"
}

function detectWeb(doc, url) {
	if (doc.title.indexOf("Web of Science Results") != -1) {
		return "multiple";
	} else if (url.indexOf("full_record.do") != -1) {
		return "journalArticle";
	}
}

function doWeb(doc, url) {
	var ids = new Array();
	if (detectWeb(doc, url) == "multiple") {
		var items = new Object;
		var xpath = '//a[@class="smallV110"]';
		var titles = doc.evaluate(xpath, doc, null, XPathResult.ANY_TYPE, null);
		var next_title;
		while (next_title = titles.iterateNext()) {
			items[next_title.href.match(/\?(.*)/)[1]] = next_title.textContent;
		}
		items = Zotero.selectItems(items);
		for (var i in items) {
			ids.push(i);
		} 
	} else {
		ids.push(url.match(/\?(.*)/)[1]);
	}
	var hostRegexp = new RegExp("^(https?://[^/]+)/");
	var m = hostRegexp.exec(url);
	var host = m[1];
	for (var i in ids) {
		ids[i] = host+"/full_record.do?" + ids[i];
	}
	Zotero.Utilities.processDocuments(ids, function(newDoc) {
		var url = newDoc.location.href;
		var sid = newDoc.evaluate('//input[@name="selectedIds"]', newDoc, null, XPathResult.ANY_TYPE, null).iterateNext().value;
		var nid = newDoc.evaluate('//input[@name="SID"]', newDoc, null, XPathResult.ANY_TYPE, null).iterateNext().value;
		var post2 = 'product=WOS&product_sid=' + nid + '&plugin=&product_st_thomas=http://esti.isiknowledge.com:8360/esti/xrpc&export_ref.x=0&export_ref.y=0';
		var post = 'action=go&mode=quickOutput&product=WOS&SID=' + nid + '&format=ref&fields=BibAbs&mark_id=WOS&count_new_items_marked=0&selectedIds=' + sid + '&qo_fields=bib&endnote.x=95&endnote.y=12&save_options=default';
		Zotero.Utilities.HTTP.doPost('http://apps.isiknowledge.com/OutboundService.do', post, function() {
			Zotero.Utilities.HTTP.doPost('http://pcs.isiknowledge.com/uml/uml_view.cgi', post2, function(text) {
				var lines = text.split("\n");
				var field = " ";
				var content = " ";
				var item = new Zotero.Item("journalArticle");
				item.url = url;
				var authors;
				var fieldRe = /^[A-Z0-9]{2}(?: |$)/;

				for each(var line in lines) {
					if(line.match(fieldRe)) {
						field = line.match(fieldRe)[0].substr(0,2);
						content = line.substr(3);
						if ((field == "AF" || field == "AU")) {
							if (!item.creators[0]) {
								var author = content.split(",");
								item.creators.push({firstName:author[1], lastName:author[0], creatorType:"author"});
							} else {
								field = "";
							}
						} else if (field == "TI") {
							item.title = content;
						} else if (field == "SO") {
							item.publicationTitle = content;
						} else if (field == "SN") {
							item.ISSN = content;
						} else if (field == "PD" || field == "PY") {
							if (item.date) {
								item.date += " " + content;
							} else {
								item.date = content;
							}
						} else if (field == "VL") {
							item.volume = content;
						} else if (field == "IS") {
							item.issue = content;
						} else if (field == "BP") {
							item.pages = content;
						} else if (field == "EP") {
							item.pages += "-" + content;
						} else if (field == "AB") {
							item.abstractNote = content;
						} else if (field == "DI") {
							item.DOI = content;
						}
					} else {
						content = Zotero.Utilities.trimInternal(line);
						if (field == "AF" || field == "AU") {
							var author = content.split(",");
							item.creators.push({firstName:author[1], lastName:author[0], creatorType:"author"});
						} else if (field == "TI") {
							item.title += " " + content;
						} else if (field == "AB") {
							item.abstractNote += " " + content;
						}
					}
				}
				item.attachments = [{url:item.url, title:"ISI Web of Knowledge Snapshot", mimeType:"text/html"}];
				item.complete();
			});
		});
	}, function() {Zotero.done();});
}