summaryrefslogtreecommitdiff
path: root/Hanrei Watch.js
blob: 0df0cad53c43c2aa77324f32d48a2c61f3e24652 (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
{
	"translatorID": "8e5f8616-05d0-4d33-8554-dad76b20ecbx",
	"label": "Hanrei Watch RSS service",
	"creator": "Frank Bennett",
	"target": "^https?://kanz\\.jp/hanrei/detail/[0-9]+/",
	"minVersion": "1.0.0b3.r1",
	"maxVersion": "",
	"priority": 100,
	"inRepository": true,
	"translatorType": 4,
	"browserSupport": "gcsibv",
	"lastUpdated": "2012-01-30 22:49:15"
}

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

var years = {};
years["明治"] = 1867;
years["大正"] = 1911;
years["昭和"] = 1925;
years["平成"] = 1988;

function doWeb(doc, url) {
	var namespace = doc.documentElement.namespaceURI;
	var nsResolver = namespace ? function(prefix) {
		if (prefix == 'x') return namespace; else return null;
	} : null;

	var item = new Zotero.Item("case");

	//
	// For values that require no special post-processing, get Xpath targets in raw list form.
	// Values to be extracted are for docket number, case nickname, court, and the abstract
	// of the judgment.
	//
	var values = [];
	values.push( doc.evaluate( '//table[@class="detail"]//th[contains(text(),"事件番号")]/following-sibling::td[position()=1]',  doc, null, XPathResult.ANY_TYPE, null) );
	values.push( doc.evaluate( '//table[@class="detail"]//th[contains(text(),"事件名")]/following-sibling::td[position()=1]',  doc, null, XPathResult.ANY_TYPE, null) );
	values.push( doc.evaluate( '//table[@class="detail"]//th[contains(text(),"裁判所")]/following-sibling::td[position()=1]',  doc, null, XPathResult.ANY_TYPE, null) );
	values.push( doc.evaluate( '//table[@class="detail"]//th[contains(text(),"裁判要旨")]/following-sibling::td[position()=1]',  doc, null, XPathResult.ANY_TYPE, null) );
	//
	// For each variable above, extract its string value, if any.
	//
	for (var pos in values){
		values[pos] = values[pos].iterateNext();
		if (values[pos]){
			values[pos] = values[pos].textContent;
		}
	}

	//
	// Get the date, and normalize the format and the year
	//
	var date = doc.evaluate( '//table[@class="detail"]//th[contains(text(),"裁判年月日")]/following-sibling::td[position()=1]',  doc, null, XPathResult.ANY_TYPE, null).iterateNext();
	if (date){
		date = date.textContent;
		date = date.replace(/日$/,"");
		date = date.replace(/(月|年)/g,"-");

		var m = date.match(/^(平成|昭和|大正|明治)([0-9]+)(.*)/);
		if (m && years[m[1]]){
			date = (years[m[1]] + parseInt(m[2],10)) + m[3];
		}
	}

	//
	// Get the URL of the PDF attachment.
	//
	var pdf = doc.evaluate( '//a[contains(text(),"PDF File")]/@href',  doc, null, XPathResult.ANY_TYPE, null).iterateNext();
	if (pdf){
		pdf = pdf.textContent;
	}

	//
	// Assemble the item and declare it complete.
	//
	item.type = "case";
	item.docketNumber = values[0];
	item.title = values[1];
	item.court = values[2];
	item.abstractNote = values[3];
	item.date = date;
	item.url = url;
	item.attachments.push( {
		url:pdf,
		title:"SupCt PDF",
		mimeType:"application/pdf"} );
	item.complete();
}
/** BEGIN TEST CASES **/
var testCases = [
	{
		"type": "web",
		"url": "http://kanz.jp/hanrei/detail/81611/",
		"items": [
			{
				"itemType": "case",
				"creators": [],
				"notes": [],
				"tags": [],
				"seeAlso": [],
				"attachments": [
					{
						"url": "http://www.courts.go.jp/hanrei/pdf/20110912150000.pdf",
						"title": "SupCt PDF",
						"mimeType": "application/pdf"
					}
				],
				"type": "case",
				"docketNumber": "平成22(ワ)503",
				"title": "慰謝料請求事件",
				"court": "仙台地方裁判所 第1民事部",
				"date": "2011-8-30",
				"url": "http://kanz.jp/hanrei/detail/81611/",
				"libraryCatalog": "Hanrei Watch RSS service",
				"accessDate": "CURRENT_TIMESTAMP"
			}
		]
	}
]
/** END TEST CASES **/