1
|
/*
|
2
|
* To change this license header, choose License Headers in Project Properties.
|
3
|
* To change this template file, choose Tools | Templates
|
4
|
* and open the template in the editor.
|
5
|
*/
|
6
|
package eu.dnetlib.usagestats.export;
|
7
|
|
8
|
/**
|
9
|
*
|
10
|
* @author dpie
|
11
|
*/
|
12
|
import java.io.BufferedReader;
|
13
|
import java.io.IOException;
|
14
|
import java.io.InputStream;
|
15
|
import java.io.InputStreamReader;
|
16
|
import java.net.MalformedURLException;
|
17
|
import java.net.URL;
|
18
|
import java.nio.charset.Charset;
|
19
|
import java.util.ArrayList;
|
20
|
import org.json.JSONException;
|
21
|
import org.json.simple.JSONArray;
|
22
|
import org.json.simple.parser.JSONParser;
|
23
|
import org.json.simple.parser.ParseException;
|
24
|
|
25
|
public class ReadCounterRobotsList {
|
26
|
|
27
|
private ArrayList robotsPatterns = new ArrayList();
|
28
|
private String COUNTER_ROBOTS_URL;
|
29
|
|
30
|
public ReadCounterRobotsList(String url) throws IOException, JSONException, ParseException {
|
31
|
COUNTER_ROBOTS_URL = url;
|
32
|
robotsPatterns = readRobotsPartners(COUNTER_ROBOTS_URL);
|
33
|
}
|
34
|
|
35
|
private ArrayList readRobotsPartners(String url) throws MalformedURLException, IOException, ParseException {
|
36
|
InputStream is = new URL(url).openStream();
|
37
|
JSONParser parser = new JSONParser();
|
38
|
BufferedReader reader = new BufferedReader(new InputStreamReader(is, Charset.forName("ISO-8859-1")));
|
39
|
JSONArray jsonArray = (JSONArray) parser.parse(reader);
|
40
|
for (Object aJsonArray : jsonArray) {
|
41
|
org.json.simple.JSONObject jsonObjectRow = (org.json.simple.JSONObject) aJsonArray;
|
42
|
robotsPatterns.add(jsonObjectRow.get("pattern").toString().replace("\\", "\\\\"));
|
43
|
}
|
44
|
return robotsPatterns;
|
45
|
}
|
46
|
|
47
|
public ArrayList getRobotsPatterns(){
|
48
|
return robotsPatterns;
|
49
|
}
|
50
|
}
|