73 lines
1.7 KiB
Java
73 lines
1.7 KiB
Java
package eu.dnetlib.ariadneplus.reader.json;
|
|
|
|
import java.util.Iterator;
|
|
import java.util.LinkedHashMap;
|
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
import com.jayway.jsonpath.DocumentContext;
|
|
import com.jayway.jsonpath.JsonPath;
|
|
|
|
import net.minidev.json.JSONArray;
|
|
import net.minidev.json.JSONObject;
|
|
import net.minidev.json.parser.JSONParser;
|
|
import net.minidev.json.parser.ParseException;
|
|
|
|
|
|
@Service
|
|
public class ParseRDFJSON {
|
|
|
|
static JSONObject map ;
|
|
|
|
@Value("${catalog.entry.path}")
|
|
private String catalogEntryJsonPath;
|
|
|
|
private String json;
|
|
|
|
private Iterator<Object> it ;
|
|
|
|
public String getJson() {
|
|
return json;
|
|
}
|
|
|
|
|
|
public void setJson(String json) throws ParseException {
|
|
this.json = json;
|
|
}
|
|
|
|
private void fillMap() throws ParseException {
|
|
map = (JSONObject)(new JSONParser(JSONParser.MODE_PERMISSIVE).parse(json));
|
|
|
|
}
|
|
|
|
public void parse(String json) throws ParseException {
|
|
setJson(json);
|
|
fillMap();
|
|
DocumentContext jsonContext = JsonPath.parse(json);
|
|
JSONArray entries = jsonContext.read(getCatalogEntryJsonPath());
|
|
int size = entries.size();
|
|
it = entries.iterator();
|
|
}
|
|
|
|
public boolean hasNextElement(){
|
|
return it.hasNext();
|
|
}
|
|
|
|
public LinkedHashMap getNextElement(){
|
|
return (LinkedHashMap)it.next();
|
|
}
|
|
|
|
public static JSONObject get(String key){
|
|
return (JSONObject) map.get(key);
|
|
}
|
|
|
|
public String getCatalogEntryJsonPath() {
|
|
return catalogEntryJsonPath;
|
|
}
|
|
|
|
public void setCatalogEntryJsonPath(String catalogEntryJsonPath) {
|
|
this.catalogEntryJsonPath = catalogEntryJsonPath;
|
|
}
|
|
}
|