summaryrefslogtreecommitdiff
path: root/Intellixir.js
blob: 406ea95b7bcde64e50a16074326609c1c85c4f02 (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
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
{
	"translatorID": "20e87da1-e1c9-410d-b400-a1c27272ae19",
	"label": "Intellixir",
	"creator": "Maxime Escourbiac",
	"target": "/intellixir/(afficheliste.aspx|liste_articles.aspx)",
	"minVersion": "3.0",
	"maxVersion": "",
	"priority": 100,
	"inRepository": true,
	"translatorType": 4,
	"browserSupport": "gcsb",
	"lastUpdated": "2013-05-24 09:49:43"
}


/**
 * Licensed to Intellixir under one
 * or more contributor license agreements. Intellixir licenses this
 * file to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */

var debug = 0;

/**
 * Determine the type of documents imported
 */
function detectWeb(doc,url) {
	return "document";
}

/**
 * Collect the data from Intellixir web pages
 *
 */
function doWeb(doc, url) {
  if(detectWeb(doc,url) == "document"){
  	/* Collect columns name */ 
  	var columnNames = collectColumnTitle(doc);
  	/* Collect all the documents */
  	var lines = collectDocuments(doc,"tdoff").concat(collectDocuments(doc,"tdoff2"));
  	/* Treatment of the lines */
  	var documents = documentsTreatment(columnNames,lines,doc);
  	/* Save the document */
  	saveDocuments(documents);
  }
}

/**
 * Collect the name of the column for an automatic treatment
 * 
 */
function collectColumnTitle(doc){
	var columnNames = new Array();
	var titles = doc.evaluate('//table[@id="TAB_PAGE"]//tbody//tr[1]//th', doc, null, XPathResult.ANY_TYPE, null);
	var title;
	while (title = titles.iterateNext()) {
		columnNames.push(title.textContent.trim());
	}
	if(debug == 1){
		Zotero.debug("------collectColumnTitle------")
		for(var i = 0; i < columnNames.length;++i){
			Zotero.debug("Column[" + i + "] : " + columnNames[i]);
		}
	}
	return columnNames;
}

/**
 * Collect documents
 * 
 */
function collectDocuments(doc,className){
	var linesCollected = new Array();
	var lines = doc.evaluate('//table[@id="TAB_PAGE"]//tbody//tr[@class="' + className + '"]', doc, null, XPathResult.ANY_TYPE, null);
	var line;
	while (line = lines.iterateNext()) {
		linesCollected.push(line);
	}
	if(debug == 1){
		Zotero.debug("------collectDocuments class='" + className + "' ------")
		for(var i = 0; i < linesCollected.length;++i){
			Zotero.debug("Line[" + i + "] : " + linesCollected[i]);
		}
	}
	return linesCollected;
}

/**
 * Parse all the document
 * 
 */
function documentsTreatment(titles,lines,doc){
	var documents = new Array();
	var typeColumn = titles.indexOf("Type");
	if(typeColumn != -1){
		for(var i = 0; i < lines.length ; ++i){
			documents.push(documentTreatment(lines[i],titles,typeColumn,doc));
		}
	}
	if(debug == 1){
		Zotero.debug("------ Documents Treatment ------")
		for(var i = 0; i < documents.length;++i){
			Zotero.debug("documents [" + i + "] : " + documents[i].title);
		}
	}
	return documents;
}

/**
 * Parse a document
 * 
 */
function documentTreatment(line,titles,typeColumn,doc){
	var document;
 	var elements = doc.evaluate('.//td', line, null, XPathResult.ANY_TYPE, null);
 	
 	/* Convert XPathResult into an array */
 	var values = new Array()
 	var element;
 	while (element = elements.iterateNext()) {
		values.push(element);
	}
	
	/* Parsing values*/
 	if(values[typeColumn].textContent == "Article"){
 		document = new Zotero.Item("journalArticle");
 		for(var i=0; i<titles.length; ++i ){
 			switch(titles[i]){
 				case "Titre":
 				case "Title":
 					/*Collecting the authors*/
 					var authors = doc.evaluate('.//i', values[i], null, XPathResult.ANY_TYPE, null).iterateNext();
 					if(authors){
 						var authorslist = authors.textContent.split(",");
 						for (var elt in authorslist) {
							document.creators.push(Zotero.Utilities.cleanAuthor(authorslist[elt], "author"));
						}
 					}
 					/*Collecting the title*/
 					var title = doc.evaluate('.//b', values[i], null, XPathResult.ANY_TYPE, null).iterateNext();
 					if(title){ /* If the title is contained in a <b> balise ==> Abstract is include in the web-page */
 						document.title = title.textContent;
 						/*Collecting the abstract*/
 						document.abstractNote = values[i].textContent.replace(title.textContent,"");
 						if(authors){
 							document.abstractNote = document.abstractNote.replace(authors.textContent,"");
 						}
 					}else{
 						document.title = values[i].textContent;
 						if(authors){
 							document.title = document.title.replace(authors.textContent,"");
 						}
 					}
 				break;
 				case "Date":
 					document.date = values[i].textContent;
 				break;
 				case "Source":
 					document.publicationTitle = values[i].textContent;
 				break;
 				case "ISSN":
 					document.ISSN = values[i].textContent;
 				break;
 				case "DOI":
 					document.DOI = values[i].textContent;
 				break;
 			}
 		}
 		if(debug == 1){
			Zotero.debug("------ Display Article ------");
			Zotero.debug("Titre : " + document.title);
			Zotero.debug("Auteurs : " + document.creators);
			Zotero.debug("Date : " + document.date);
			Zotero.debug("Source : " + document.publicationTitle);
			Zotero.debug("ISSN : " + document.ISSN);
			Zotero.debug("DOI : " + document.DOI);
			Zotero.debug("Abstract : " + document.abstractNote);
			
		}
 	} else{
 		document = new Zotero.Item("patent");
 		var i;
 		for(i=0; i<titles.length; ++i ){
 			switch(titles[i]){
 				case "Titre":
 				case "Title":
 					/*Collecting the authors*/
 					var authors = doc.evaluate('.//i', values[i], null, XPathResult.ANY_TYPE, null).iterateNext();
 					if(authors){
 						var authorslist = authors.textContent.split(",");
 						for (var elt in authorslist) {
							document.creators.push(Zotero.Utilities.cleanAuthor(authorslist[elt], "author"));
						}
 					}
 					/*Collecting the title*/
 					var title = doc.evaluate('.//b', values[i], null, XPathResult.ANY_TYPE, null).iterateNext();
 					if(title){ /* If the title is contained in a <b> balise ==> Abstract is include in the web-page */
 						document.title = title.textContent;
 						/*Collecting the abstract*/
 						document.abstractNote = values[i].textContent.replace(title.textContent,"");
 						if(authors){
 							document.abstractNote = document.abstractNote.replace(authors.textContent,"");
 						}
 					}else{
 						document.title = values[i].textContent;
 						if(authors){
 							document.title = document.title.replace(authors.textContent,"");
 						}
 					}
 					/*Split the patent number from the title*/
 					if(document.title[document.title.length - 1] == ')'){
 						var titleElmnts = document.title.split("(");
 						var patentNumber = titleElmnts[titleElmnts.length - 1]
 						/* Deleting patent Number information from the title. */
 						document.title = document.title.replace("(" + patentNumber,"");
 						/* Insert Patent number */
 						document.patentNumber = patentNumber.replace(")","").split(",")[0];
 					}
 				break;
 				case "Date":
 					document.date = values[i].textContent;
 				break;
 				case "Affiliations Courtes":
 				case "Short Affiliations":
 					document.assignee = values[i].textContent;
 				break;
 				case "Numéro de priorité":
 				case "Priority number":
 					document.priorityNumbers = values[i].textContent;
 				break;
 			}
 		}
 		if(debug == 1){
			Zotero.debug("------ Display Patent ------");
			Zotero.debug("Titre : " + document.title);
			Zotero.debug("Numéro de brevet : " + document.patentNumber);
			Zotero.debug("Auteurs : " + document.creators);
			Zotero.debug("Date : " + document.date);
			Zotero.debug("Affiliations Courtes : " + document.assignee);
			Zotero.debug("Numéro de priorité : " + document.priorityNumbers);
		}
 	}
 	return document;
 }
 
 /**
  * Save the documents
  * 
  */
 function saveDocuments(documents){
 	for (var i = 0; i < documents.length; ++i) {	
		documents[i].complete();
	}
 }