summaryrefslogtreecommitdiff
path: root/Musee du Louvre.js
blob: 0ed1d20b5fdaf4f015200c9528d16a99f838001f (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
{
	"translatorID": "22d17fb9-ae32-412e-bcc4-7650ed3359bc",
	"label": "Musee du Louvre",
	"creator": "Adam Crymble",
	"target": "^https?://www\\.louvre\\.fr/llv",
	"minVersion": "1.0.0b4.r5",
	"maxVersion": "",
	"priority": 100,
	"inRepository": true,
	"translatorType": 4,
	"browserSupport": "g",
	"lastUpdated": "2011-11-09 00:13:03"
}

function detectWeb(doc, url) {
	if (doc.location.href.match("recherche")) {
		return "multiple";
	} else if (doc.evaluate('//div[@class="alignRight"]/a/img', doc, null, XPathResult.ANY_TYPE, null).iterateNext()) {
		return "artwork";
	}
	
}

//Translator Musee du Louvre. Code by Adam Crymble

function scrape(doc, url) {

	var namespace = doc.documentElement.namespaceURI;
	var nsResolver = namespace ? function(prefix) {
		if (prefix == 'x') return namespace; else return null;
	} : null;	
	
	var dataTags = new Object();
	var tagsContent = new Array();
	
	var newItem = new Zotero.Item("artwork");

	//tags	
		var metaTagHTML = doc.getElementsByTagName("meta");
		for (var i = 0 ; i < metaTagHTML.length ; i++) {
			dataTags[metaTagHTML[i].getAttribute("name")] = Zotero.Utilities.cleanTags(metaTagHTML[i].getAttribute("content"));
		}
		
		newItem.abstractNote = dataTags["description"];
		
		if (dataTags["keywords"]) {
			if (dataTags["keywords"].match(", ")) {
				tagsContent = tagsContent = dataTags["keywords"].split(", ");
			} else if (dataTags["keywords"].split("、")) {
				tagsContent = dataTags["keywords"].split("、");
			}
		}
		
		for (var i = 0; i < tagsContent.length; i++) {
			newItem.tags[i] = tagsContent[i];
		}
		
	//date	
		var xPathDate = '//td[@class="txtContent"]/span[@class="txtContentSmall"]';
		
		if (doc.evaluate(xPathDate, doc, nsResolver, XPathResult.ANY_TYPE, null).iterateNext()) {
			
			newItem.date = doc.evaluate(xPathDate, doc, nsResolver, XPathResult.ANY_TYPE, null).iterateNext().textContent;
		}
	
	//creator	
		var xPathCreator = '//td[@class="txtContent"]/strong';
		if (doc.evaluate(xPathCreator, doc, nsResolver, XPathResult.ANY_TYPE, null).iterateNext()) {
			var creator = doc.evaluate(xPathCreator, doc, nsResolver, XPathResult.ANY_TYPE, null).iterateNext().textContent.toLowerCase();
		
			var comma = 0;
			var parenthesis = 0;
			var commaSpot;
			var parenthesisSpot;
			
			if (creator.match(", ")) {
				comma = 1;
				commaSpot = creator.indexOf(",");
			}
			
			if (creator.match(/\(/)) {
				parenthesis = 1;
				parenthesisSpot = creator.indexOf(" (");
			} 
			
			if (comma == 1 && parenthesis == 1) {
				if (commaSpot < parenthesisSpot) {
					creator = creator.substr(0, commaSpot);
				} else {
					creator = creator.substr(0, parenthesisSpot);
				}
			} else if (comma == 1 && parenthesis == 0) {
				creator = creator.substr(0, commaSpot);	
			} else if (comma == 0 && parenthesis == 1) {
				creator = creator.substr(0, parenthesisSpot);
			}
		
			var words = creator.split(" ");
			
			for (var j in words) {
				if (words[j] != "" && words[j] != ' ') {
					if (words[j].match("-")) {
						Zotero.debug(words[j]);
						var hyphen = words[j].split("-");
						hyphen[0] = hyphen[0][0].toUpperCase() + hyphen[0].substr(1).toLowerCase() + "-";
						hyphen[1] = hyphen[1][0].toUpperCase() + hyphen[1].substr(1).toLowerCase();
						words[j] = hyphen[0] + hyphen[1];
					} else {
						words[j] = words[j][0].toUpperCase() + words[j].substr(1).toLowerCase();
					}
				}
			}
			creator = words.join(" ");
			newItem.creators.push(Zotero.Utilities.cleanAuthor(creator, "artist"));
		}
		
	
	//title
		var title1 = doc.title.split(" |");
		Zotero.debug(title1[0]);
		newItem.title = title1[0];	
		
	//extra
		if (doc.evaluate('//h1', doc, nsResolver, XPathResult.ANY_TYPE, null).iterateNext()) {
		
			var collection1 = doc.evaluate('//h1', doc, nsResolver, XPathResult.ANY_TYPE, null).iterateNext().textContent;
			newItem.extra = collection1.replace(/^\s*|\s*$/g, '');
		}
		
		newItem.repository = "Musée du Louvre";
		newItem.url = doc.location.href;
	
		newItem.complete();
}

function doWeb(doc, url) {
	var namespace = doc.documentElement.namespaceURI;
	var nsResolver = namespace ? function(prefix) {
		if (prefix == 'x') return namespace; else return null;
	} : null;
	
	var articles = new Array();
	
	if (detectWeb(doc, url) == "multiple") {
		var items = new Object();

		var links = doc.evaluate('//h4/a[@class="lien"]', doc, nsResolver, XPathResult.ANY_TYPE, null);
		var titles = doc.evaluate('//h4/a/@title', doc, nsResolver, XPathResult.ANY_TYPE, null);
		
		var next_title;
		while (next_title = titles.iterateNext()) {
			items[links.iterateNext().href] = next_title.textContent;
		}
		items = Zotero.selectItems(items);
		for (var i in items) {
			articles.push(i);
		}
	} else {
		articles = [url];
	}
	Zotero.Utilities.processDocuments(articles, scrape, function() {Zotero.done();});
	Zotero.wait();	
}/** BEGIN TEST CASES **/
var testCases = [
	{
		"type": "web",
		"url": "http://www.louvre.fr/llv/activite/detail_evenement.jsp?CONTENT%3C%3Ecnt_id=10134198673390879&CURRENT_LLV_ACTIVITE%3C%3Ecnt_id=10134198673390879&FOLDER%3C%3Efolder_id=9852723696500927",
		"items": [
			{
				"itemType": "artwork",
				"creators": [],
				"notes": [],
				"tags": [
					",Activité ",
					"Musée du Louvre",
					"Musée",
					"Louvre "
				],
				"seeAlso": [],
				"attachments": [],
				"abstractNote": "Présentation centrée sur l'étude d'une oeuvre",
				"title": "Détails des activités <i>La Dentellière</i> de Vermeer",
				"extra": "Visites guidées",
				"url": "http://www.louvre.fr/llv/activite/detail_evenement.jsp?CONTENT%3C%3Ecnt_id=10134198673390879&CURRENT_LLV_ACTIVITE%3C%3Ecnt_id=10134198673390879&FOLDER%3C%3Efolder_id=9852723696500927",
				"libraryCatalog": "Musée du Louvre",
				"accessDate": "CURRENT_TIMESTAMP"
			}
		]
	},
	{
		"type": "web",
		"url": "http://www.louvre.fr/llv/oeuvres/detail_notice.jsp?CONTENT%3C%3Ecnt_id=10134198673225228&CURRENT_LLV_NOTICE%3C%3Ecnt_id=10134198673225228&FOLDER%3C%3Efolder_id=9852723696500800&fromDept=true&baseIndex=4",
		"items": [
			{
				"itemType": "artwork",
				"creators": [
					{
						"firstName": "",
						"lastName": "",
						"creatorType": "artist"
					}
				],
				"notes": [],
				"tags": [
					"stèle ",
					"monument",
					"Ishtar",
					"déesse",
					"déesse de l'amour",
					"amour",
					"guerrière",
					"guerre",
					"lion",
					"animal",
					"épée",
					"carquois",
					"tiare",
					"astral",
					"reliefs",
					"inscription",
					"Assyriens",
					"Tell Ahmar",
					"Til Barsip",
					"Bît Adini",
					"Syrie",
					"Assyrie",
					"Euphrate",
					"VIIIe siècle avant J.-C.,Oeuvres ",
					"Musée du Louvre",
					"Musée",
					"Louvre "
				],
				"seeAlso": [],
				"attachments": [],
				"abstractNote": "Stèle : déesse Ishtar . Provenance : Tell Ahmar, antique Til Barsip. Epoque néo-assyrienne, VIIIe siècle av. J.-C. - Département des Antiquités orientales",
				"date": "Epoque néo-assyrienne, VIIIe siècle av. J.-C.",
				"title": "Stèle figurant la déesse Ishtar – <br /> – Antiquités orientales",
				"extra": "Antiquités orientales : Mésopotamie",
				"url": "http://www.louvre.fr/llv/oeuvres/detail_notice.jsp?CONTENT%3C%3Ecnt_id=10134198673225228&CURRENT_LLV_NOTICE%3C%3Ecnt_id=10134198673225228&FOLDER%3C%3Efolder_id=9852723696500800&fromDept=true&baseIndex=4",
				"libraryCatalog": "Musée du Louvre",
				"accessDate": "CURRENT_TIMESTAMP"
			}
		]
	}
]
/** END TEST CASES **/