summaryrefslogtreecommitdiff
path: root/J-Stage.js
blob: 7f635060f3322ebfee5116f85a3c8c0fb6575b9c (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
{
	"translatorID": "e40a27bc-0eef-4c50-b78b-37274808d7d2",
	"label": "J-Stage",
	"creator": "Sebastian Karcher",
	"target": "^https?://www\\.jstage\\.jst\\.go\\.jp/",
	"minVersion": "2.1.9",
	"maxVersion": "",
	"priority": 100,
	"inRepository": true,
	"translatorType": 4,
	"browserSupport": "gcsibv",
	"lastUpdated": "2014-03-19 01:59:25"
}

/*
	***** BEGIN LICENSE BLOCK *****
	
	J-Stage translator - Copyright © 2012 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(/\.jst\.go\.jp\/article\//)) {
		return "journalArticle";
	} else if (url.match(/\.jst\.go\.jp\/result\?/) || url.match(/\.jst\.go\.jp\/browse\//)) {
		return "multiple";
	}
}

function doWeb(doc, url) {
	var articles = new Array();
	if (detectWeb(doc, url) == "multiple") {
		var items = {};
		var titles = doc.evaluate('//div[contains(@class, "contents_detail")]/div/a|//h3[@class="mod-item-heading"]/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);
			}
			Zotero.Utilities.processDocuments(articles, scrape, function () {
				Zotero.done();
			});
			Zotero.wait();
		});
	} else {
		scrape(doc, url);
	}
}

// help function
function scrape(doc, url) {
	//get abstract and tags from article plage
	//the xpaths aren't great , but seem reliable across pages
	var pdfurl = ZU.xpath(doc, '//li[@class="icon-pdf"]/a/@href');
	pdfurl = "https://www.jstage.jst.go.jp" + pdfurl[1].textContent;
	Z.debug(pdfurl)
	var abs = ZU.xpathText(doc, '//div[@class="mod-section"]/p[@class="normal"]') //.replace(/\n/g, "")
	var tags = ZU.xpathText(doc, '//p[contains(@class, "keywords")]')
	if (tags){
	tags = tags.replace(/Keywords:/, "").split(/\s*,\s*/);
	for (i in tags) {
		tags[i] = ZU.trimInternal(tags[i]);
	}
	}
	//get BibTex Link
	var bibtexurl = ZU.xpathText(doc, '//li/a[contains(text(), "BibTeX")]/@href');
	Z.debug(bibtexurl)
	Zotero.Utilities.HTTP.doGet(bibtexurl, function (text) {
		var bibtex = text;
		//Zotero.debug(bibtex)
		var translator = Zotero.loadTranslator("import");
		translator.setTranslator("9cb70025-a888-4a29-a210-93ec52da40d4");
		translator.setString(bibtex);
		translator.setHandler("itemDone", function (obj, item) {
			if (abs) item.abstractNote = abs;
			if (tags) item.tags = tags;
			for (i in item.creators) {
				if (item.creators[i].lastName && item.creators[i].lastName == item.creators[i].lastName.toUpperCase()) {
					item.creators[i].lastName = Zotero.Utilities.capitalizeTitle(item.creators[i].lastName.toLowerCase(), true);
				}
				if (item.creators[i].firstName && item.creators[i].firstName == item.creators[i].firstName.toUpperCase()) {
					item.creators[i].firstName = Zotero.Utilities.capitalizeTitle(item.creators[i].firstName.toLowerCase(), true);
				}
			}
			if (item.title == item.title.toUpperCase()) {
				item.title = Zotero.Utilities.capitalizeTitle(item.title.toLowerCase(), true);
			}
			if (item.publicationTitle == item.publicationTitle.toUpperCase()) {
				item.publicationTitle = Zotero.Utilities.capitalizeTitle(item.publicationTitle.toLowerCase(), true);
			}
			item.attachments = [{
				url: item.url,
				title: "Jstage - Snapshot",
				mimeType: "text/html"
			}, {
				url: pdfurl,
				title: "Jstage - Full Text PDF",
				mimeType: "application/pdf"
			}];
			item.complete();
		});
		translator.translate();
	});
}/** BEGIN TEST CASES **/
var testCases = [
	{
		"type": "web",
		"url": "https://www.jstage.jst.go.jp/article/prohe1990/45/0/45_0_811/_article",
		"items": [
			{
				"itemType": "journalArticle",
				"creators": [
					{
						"firstName": "Thai Nam",
						"lastName": "Pham",
						"creatorType": "author"
					},
					{
						"firstName": "Dawen",
						"lastName": "Yang",
						"creatorType": "author"
					},
					{
						"firstName": "Shinjiro",
						"lastName": "Kanae",
						"creatorType": "author"
					},
					{
						"firstName": "Taikan",
						"lastName": "Oki",
						"creatorType": "author"
					},
					{
						"firstName": "Katumi",
						"lastName": "Musiake",
						"creatorType": "author"
					}
				],
				"notes": [],
				"tags": [
					"soil erosion by water",
					"the RUSLE",
					"global estimation",
					"global data sets"
				],
				"seeAlso": [],
				"attachments": [
					{
						"title": "Jstage - Snapshot",
						"mimeType": "text/html"
					},
					{
						"title": "Jstage - Full Text PDF",
						"mimeType": "application/pdf"
					}
				],
				"itemID": "2001811",
				"title": "Application of RUSLE Model on Global Soil Erosion Estimate",
				"publicationTitle": "Proceedings of Hydraulic Engineering",
				"volume": "45",
				"pages": "811-816",
				"date": "2001",
				"abstractNote": "Soil erosion is one of the most serious environmental problems commonly in over the world, which is caused by both natural and human factors. It is possible to investigate the global issue on soil erosion with the development of global data sets. This research estimated global soil erosion by the RUSLE model with use of a comprehensive global data set. The accuracy of the estimate mostly depends on the available information related to the study area. Present available finest data was used in this study. As the desired objective of estimating soil erosion by water at global scale, the application of RUSLE has shown its positive applicability on large-scale estimates. The study has shown a global view of water soil erosion potential with 0.5-degree grid resolution. Regional validations and examinations have been carried out by different ways. The global mean of annual soil erosion by water was estimated as 1100 ton/ km2, which agrees with several results obtained in different regions.",
				"libraryCatalog": "J-Stage"
			}
		]
	},
	{
		"type": "web",
		"defer": true,
		"url": "https://www.jstage.jst.go.jp/result?item1=4&word1=organic+agriculture+erosion",
		"items": "multiple"
	},
	{
		"type": "web",
		"defer": true,
		"url": "https://www.jstage.jst.go.jp/browse/bpb",
		"items": "multiple"
	}
]
/** END TEST CASES **/