summaryrefslogtreecommitdiff
path: root/Legislative Insight.js
blob: ab59f5431aa70e21ca6e84823a67ea6e4eeb472e (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
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
{
	"translatorID": "2bedae3c-bab5-447f-b127-e9babc0e9cfe",
	"label": "Legislative Insight",
	"creator": "Kari Hemdal",
	"target": "^https?://www\\.(?:conquest-leg-insight-cert|conquest-leg-insight)\\.com/legislativeinsight/LegHistMain\\.jsp",
	"minVersion": "3.0",
	"maxVersion": "",
	"priority": 100,
	"inRepository": true,
	"translatorType": 4,
	"browserSupport": "gcsb",
	"lastUpdated": "2014-04-03 17:41:39"
}

/*
	ProQuest Legislative Insight
	
	Copyright (C) 2012  Kari Hemdal 
	
	ProQuest Legislative Insight is a Federal legislative history service that makes available thoroughly researched compilations of digital full text publications created by Congress during the process leading up to the enactment of U.S. Public Laws

	This program 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.

	This program 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 this program.  If not, see <http://www.gnu.org/licenses/>.

*/



function detectWeb(doc, url) {
	  
		return "multiple";       
}


function getSingleType(doc,url)
{
		var myXPath = '//div[@id="docpageid"]';
		var myXPathObject = doc.evaluate(myXPath, doc, null, XPathResult.ANY_TYPE, null);    
		var type;
		
		if (type = myXPathObject.iterateNext()) 
		{        
			type = type.firstChild.textContent;            
			return type;
		}
		else
		{
			return "";
		}

}

function containsSearchResult(doc, url)
{	
		var myXPath = '//div[@class="results-title"]/a';
		var myXPathObject = doc.evaluate(myXPath, doc, null, XPathResult.ANY_TYPE, null);    
		var headers;
	
	
		if (headers = myXPathObject.iterateNext()) 
		{            
			return true;
		}
		else
		{
			return false;
		}

}

function getType(t)
{
	return t.substring(t.indexOf(":")+1,t.length);
}

function doLDOC(doc, url, st, showTop) {

	var articles = new Array();
	var items = new Object();
	var headers;
	var restype;
	var count = 0;
	
	
	if (showTop)
	{
		var sz = st.split("|");        
		var accNoZ = sz[0];
		var pubLawZ = sz[1];
		var typeZ = sz[2];    
		var typeTextZ = sz[3];        
		var idz = accNoZ+"|"+pubLawZ+"|"+typeZ+"|"+typeTextZ;                                           
		items[idz] = "Legislative History of " + accNoZ;                    
		count++;
		idz = accNoZ+"FT|"+pubLawZ+"|PUBLIC_LAW|"+typeTextZ;
		items[idz] = "Public Law: " + accNoZ;                    
		count++;
	}
		
	
	
		var myXPath = '//a[contains(@onclick, "ldoc(")]';
		var myXPathObject = doc.evaluate(myXPath, doc, null, XPathResult.ANY_TYPE, null);    
				
	
		while (headers = myXPathObject.iterateNext()) 
		{               
			var onclick = headers.getAttribute("onclick")            
			var pos = onclick.indexOf("ldoc('");            
			onclick = onclick.substring(pos+5,onclick.indexOf("')",pos+5)+1);                        
			var s = onclick.split(",");
							
			var pubLaw = s[0].substring(1,s[0].length-1);
			var accNo = s[1].substring(1,s[1].length-1);
			var type = s[2].substring(1,s[2].length-1);
					
			var typeText = headers.getAttribute("title");       
			if (typeText)
			{                
				var id = accNo+"|"+pubLaw+"|"+type+"|"+typeText;                                            
				items[id] = typeText;                    
				count++;
			}
		}
			
		if (count > 0)
		{
			items = Zotero.selectItems(items);
			for (var i in items) 
			{                         
				var s = i.split("|");
				var accNo = s[0];
				var pubLaw = s[1];
				var type = s[2];    
				var typeText = s[3];            
				process(accNo, pubLaw,type,typeText);
			}
		}   
	
	

}


function doWeb(doc, url) {


	var st = getSingleType(doc,url)
	if (st != "")
	{        
		var s = st.split("|");     
		var accNo = s[0];
		var pubLaw = s[1];
		var type = s[2];    
		var typeText = s[3];        
		
		if (type == "LEG_HIST")
			doLDOC(doc,url,st,accNo != null && accNo != "");
		else if (type == "BILL_DOC" || type == "LEG_PROC")
			doLDOC(doc,url,st,false);
		else
			process(accNo, pubLaw,type,typeText);
		return;
	}
		
	var articles = new Array();
	var items = new Object();
	var headers;
	var restype;
	var count = 0;
	
	if (detectWeb(doc, url) == "multiple") 
	{   
		var myXPath = '//div[@class="results-title"]/a';
		var myXPathObject = doc.evaluate(myXPath, doc, null, XPathResult.ANY_TYPE, null);    
		
		var myXPath2 = '//div[@class="results-type"]';
		var myXPathObject2 = doc.evaluate(myXPath2, doc, null, XPathResult.ANY_TYPE, null);    
	
	
		while (headers = myXPathObject.iterateNext()) 
		{            
			var onclick = headers.getAttribute("onclick");                        
			onclick = onclick.substring(onclick.indexOf("('")+1,onclick.indexOf("')")+1);            
			var s = onclick.split(",");
							
			var pubLaw = s[0].substring(1,s[0].length-1);
			var accNo = s[1].substring(1,s[1].length-1);
			var type = s[2].substring(1,s[2].length-1);
			
			restype = myXPathObject2.iterateNext();
			var typeText = getType(restype.firstChild.textContent);            
			var id = accNo+"|"+pubLaw+"|"+type+"|"+typeText;                                    
			items[id] = typeText + ": " + headers.parentNode.textContent;                    
			count++;
		}
		
		if (count > 0)
		{

			Zotero.selectItems(items, function (items) {
				if (!items) {
					return true;
				}
				
				for (var i in items) 
				{            
					Zotero.debug(i);
					var s = i.split("|");
					var accNo = s[0];
					var pubLaw = s[1];
					var type = s[2];    
					var typeText = s[3];            
					process(accNo, pubLaw,type,typeText);
				}
			})
		}   
	}
	

}

function addCommon(newItem, obj, typeText)
{    
	Zotero.debug(obj.pdfURL);
	newItem.title = obj.title;
	newItem.url = obj.url;  
	newItem.language = obj.language;
	newItem.attachments.push({
	title:obj.pdfTitle,
	mimeType:"application/pdf",
	url:obj.pdfURL});        
}

function addLegislativeHistory(obj, typeText)
{
	
	var newItem = new Zotero.Item("document");
	addCommon(newItem,obj,typeText);    
	newItem.date = obj.dateEnacted;
	newItem.title = "Legislative History of Public Law " + obj.publicLawNumber +": " + obj.title;
	newItem.abstractNote = obj.abstractNote;            
		
	newItem.complete();                                                                                        
}


function addStatute(obj, typeText)
{                                       
	var newItem = new Zotero.Item("statute");
	addCommon(newItem,obj,typeText);    
	newItem.publicLawNumber = obj.publicLawNumber;    
	newItem.session = obj.session;    
	newItem.dateEnacted = obj.dateEnacted;
	newItem.nameOfAct = obj.title;
	newItem.abstractNote = obj.abstractNote;    
			
	newItem.complete();                                                                                        
}

function addHearing(obj, typeText)
{    
	var newItem = new Zotero.Item("hearing");    
	addCommon(newItem,obj,typeText);  
	newItem.documentNumber = obj.documentNumber;    
	newItem.legislativeBody = obj.legislativeBody;
	newItem.session = obj.session;
	newItem.date = obj.date;
	newItem.committee = obj.committee;
	newItem.complete();                                                                                        
}

function addBill(obj, typeText)
{    
	var newItem = new Zotero.Item("bill");    
	addCommon(newItem,obj,typeText);    
	newItem.billNumber = obj.billNumber;
	newItem.date = obj.date;
	newItem.legislativeBody = obj.legislativeBody;
	newItem.session = obj.session;
	newItem.complete();                                                                                        
}

function addReport(obj, typeText)
{    
	var newItem = new Zotero.Item("report");    
	addCommon(newItem,obj,typeText);        
	newItem.date = obj.date;
	newItem.reportType = obj.reportType;
	newItem.reportNumber = obj.reportNumber;
	newItem.callNumber = obj.ID;
	newItem.libraryCatalog = "";
	newItem.complete();                                                                                        
}

function addPresidentialSigning(obj, typeText)
{    
	var newItem = new Zotero.Item("document");    
	addCommon(newItem,obj,typeText);        
	newItem.date = obj.date;        
	newItem.creators.push(Zotero.Utilities.cleanAuthor(obj.author, "author"));
	newItem.complete();                                                                                        
}

function addCongressionalRecord(obj, typeText)
{    
	var newItem = new Zotero.Item("document");    
	addCommon(newItem,obj,typeText);                    
	newItem.date = obj.date;    
	newItem.abstractNote = obj.abstract;            
	newItem.complete();                                                                                        
}



function getItemType(type)
{
	if (type == "LEG_HIST")
		return "multiple";
	else if (type == "BILL_DOC")
		return "multiple";
	else if (type == "LEG_PROC")
		return "multiple";
	else if (type == "BILL_VERSION")
		return "bill";
	else if (type == "PUBLIC_LAW")
		return "statute";
	else if (type == "REPORT" || type == "DOCUMENT" || type == "PRINT" || type == "MISC_PUB")
		return "report";
	else if (type == "HEARING")
		return "hearing";
	else if (type == "PRES_SIGN_STMT" || type == "CONGRESSIONAL_RECORD")
		return "document";
	else
		return "";
		
}





function process(accNo, pubLaw, type, typeText) 
{
		
		var url = "Zotero?accNo="+accNo+"&pubLaw="+pubLaw+"&type="+type;          
		
		Zotero.Utilities.HTTP.doGet(url, 
									function(text, response, url){       
										var i;
										var obj;
										
										var objarr = eval('(' + text + ')');                                        
										
										for (i=0; i < objarr.length; i++)
										{
											obj = objarr[i];

											if (obj.item == "legislativehistory")
											{            
												addLegislativeHistory(obj,typeText);                                        
											}                                            
											else if (obj.item == "statute")
											{
												addStatute(obj,typeText);                                        
											}
											else if (obj.item == "hearing")
											{
												addHearing(obj,typeText);
											}
											else if (obj.item == "bill")
											{
												addBill(obj,typeText);
											}                     
											else if (obj.item == "report")
											{
												addReport(obj,typeText);
											}
											else if (obj.item == "presidentialsigning")
											{
												addPresidentialSigning(obj,typeText);
											}
											else if (obj.item == "congressionalrecord")
											{                                             
												addCongressionalRecord(obj,typeText);
											}
										}
									}, 
									function() {Zotero.done(); }, null);
		 

}