package datasets.in;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.net.URL;
import javax.xml.stream.XMLStreamException;
import javat.xml.Document;
import javat.xml.Element;
import org.json.JSONException;
import org.json.JSONObject;
import org.xml.sax.SAXException;
import util.GetRequest;
public class VIAF {
public static JSONObject getLinks(String viaf) throws IOException, JSONException{
GetRequest g = new GetRequest("https://viaf.org/viaf/"+viaf+"/justlinks.json");
String s = g.request();
return new JSONObject(s);
}
public static boolean hasEntry(String viaf) throws IOException {
try{
new GetRequest("https://viaf.org/viaf/"+viaf+"/justlinks.json").request();
}catch(FileNotFoundException e){
return false;
}
return true;
}
public static boolean isDeprecated(String viaf) throws IOException, XMLStreamException, SAXException {
Document d = Document.load(new URL("http://viaf.org/viaf/"+viaf+"/rdf.xml").openStream());
for(Element e : d.getRootElement().getChildren("Description")){
if(! e.getAttribute("about").getValue().equals("http://viaf.org/viaf/"+viaf))
continue;
if(e.getChildren("deprecated").size() == 0)
continue;
Element d2 = e.getChildren("deprecated").get(0);
if(d2 == null)
continue;
return Boolean.parseBoolean(d2.getText());
}
return false;
}
}