1
|
/**
|
2
|
* Copyright (C) 2018 EDIT
|
3
|
* European Distributed Institute of Taxonomy
|
4
|
* http://www.e-taxonomy.eu
|
5
|
*
|
6
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
7
|
* See LICENSE.TXT at the top of this package for the full license terms.
|
8
|
*/
|
9
|
package eu.etaxonomy.taxeditor.view.webimport.termimport.parser;
|
10
|
|
11
|
import java.util.ArrayList;
|
12
|
import java.util.Collection;
|
13
|
import java.util.List;
|
14
|
|
15
|
import org.json.JSONArray;
|
16
|
import org.json.JSONException;
|
17
|
import org.json.JSONObject;
|
18
|
|
19
|
import eu.etaxonomy.taxeditor.view.webimport.termimport.wrapper.TerminologyWrapper;
|
20
|
|
21
|
/**
|
22
|
* @author pplitzner
|
23
|
* @since May 9, 2018
|
24
|
*
|
25
|
*/
|
26
|
public class TerminologyParser {
|
27
|
public static Collection<TerminologyWrapper> parse(String response){
|
28
|
List<TerminologyWrapper> wrapperList = new ArrayList<>();
|
29
|
try {
|
30
|
JSONObject jsonResponse = new JSONObject(response);
|
31
|
JSONArray responseArray = jsonResponse.getJSONArray("results");
|
32
|
for(int i=0;i<responseArray.length();i++){
|
33
|
JSONObject terminology = responseArray.getJSONObject(i);
|
34
|
String name = terminology.getString("name");
|
35
|
String acronym = terminology.getString("acronym");
|
36
|
String description = terminology.getString("description");
|
37
|
String uriString = terminology.getString("uri");
|
38
|
wrapperList.add(new TerminologyWrapper(name, acronym, description, uriString));
|
39
|
}
|
40
|
} catch (JSONException e) {
|
41
|
e.printStackTrace();
|
42
|
}
|
43
|
return wrapperList;
|
44
|
}
|
45
|
|
46
|
}
|