use of org.apache.jena.sparql.ARQException in project jena by apache.
the class ResultSetUtils method resultSetToStringList.
/**
* Extracts a List filled with the binding of selectElement variable for each
* query solution, turned into a string (URIs or lexical forms).
* Exhausts the result set. Create a rewindable one to use multiple times.
* @see org.apache.jena.query.ResultSetFactory
*/
public static List<String> resultSetToStringList(ResultSet rs, String selectElement, String literalOrResource) {
// feature suggested by James Howison
List<String> items = new ArrayList<>();
while (rs.hasNext()) {
QuerySolution qs = rs.nextSolution();
RDFNode rn = qs.get(selectElement);
if (rn.isLiteral())
items.add(((Literal) rn).getLexicalForm());
else if (rn.isURIResource())
items.add(((Resource) rn).getURI());
else if (rn.isAnon()) {
items.add(((Resource) rn).getId().getLabelString());
} else
throw new ARQException("Unknow thing in results : " + rn);
}
return items;
}
use of org.apache.jena.sparql.ARQException in project jena by apache.
the class RowSetReaderCSV method vars.
private static List<Var> vars(CSVParser parser) {
final List<Var> vars = new ArrayList<>();
List<String> varNames = parser.parse1();
if (varNames == null)
throw new ARQException("SPARQL CSV Results malformed, input is empty");
for (String vn : varNames) {
vars.add(Var.alloc(vn));
}
return vars;
}
use of org.apache.jena.sparql.ARQException in project jena by apache.
the class RowSetReaderTSV method booleanFromTSV.
/**
* Reads SPARQL Boolean result from TSV
* @param in Input Stream
* @return boolean
*/
public static boolean booleanFromTSV(InputStream in) {
BufferedReader reader = IO.asBufferedUTF8(in);
String str = null;
try {
// First try to parse the header
str = reader.readLine();
if (str == null)
throw new ARQException("TSV Boolean Results malformed, input is empty");
// Remove extraneous white space
str = str.trim();
// Expect a header row with single ?_askResult variable
if (!str.equals("?_askResult"))
throw new ARQException("TSV Boolean Results malformed, did not get expected ?_askResult header row");
// end header.
// Then try to parse the boolean result
str = reader.readLine();
if (str == null)
throw new ARQException("TSV Boolean Results malformed, unexpected end of input after header row");
str = str.trim();
if (str.equalsIgnoreCase("true") || str.equalsIgnoreCase("yes")) {
return true;
} else if (str.equalsIgnoreCase("false") || str.equalsIgnoreCase("no")) {
return false;
} else {
throw new ARQException("TSV Boolean Results malformed, expected one of - true yes false no - but got " + str);
}
} catch (IOException ex) {
throw new ARQException(ex);
}
}
use of org.apache.jena.sparql.ARQException in project jena by apache.
the class ARQMgt_X method register.
private static void register(ObjectName objName, Object bean) {
try {
// (Does not cope with multiple loads running in parallel.)
if (mbs.isRegistered(objName)) {
try {
mbs.unregisterMBean(objName);
} catch (InstanceNotFoundException ex) {
}
}
log.debug("Register MBean: " + objName);
mbs.registerMBean(bean, objName);
// remember ...
mgtObjects.put(objName, bean);
} catch (NotCompliantMBeanException ex) {
log.warn("Failed to register (NotCompliantMBeanException)'" + objName.getCanonicalName() + "': " + ex.getMessage());
throw new ARQException("Failed to register '" + objName.getCanonicalName() + "': " + ex.getMessage(), ex);
} catch (InstanceAlreadyExistsException ex) {
log.warn("Failed to register (InstanceAlreadyExistsException)'" + objName.getCanonicalName() + "': " + ex.getMessage());
throw new ARQException("Failed to register '" + objName.getCanonicalName() + "': " + ex.getMessage(), ex);
} catch (MBeanRegistrationException ex) {
log.warn("Failed to register (MBeanRegistrationException)'" + objName.getCanonicalName() + "': " + ex.getMessage());
throw new ARQException("Failed to register '" + objName.getCanonicalName() + "': " + ex.getMessage(), ex);
}
}
use of org.apache.jena.sparql.ARQException in project jena by apache.
the class GSP method uploadTriples.
/**
* Send a file of triples to a URL.
*/
private static void uploadTriples(HttpClient httpClient, String gspUrl, String file, String fileExtContentType, Map<String, String> headers, Push mode) {
Lang lang = RDFLanguages.contentTypeToLang(fileExtContentType);
if (lang == null)
throw new ARQException("Not a recognized as an RDF format: " + fileExtContentType);
if (RDFLanguages.isQuads(lang) && !RDFLanguages.isTriples(lang))
throw new ARQException("Can't load quads into a graph");
if (!RDFLanguages.isTriples(lang))
throw new ARQException("Not an RDF format: " + file + " (lang=" + lang + ")");
pushFile(httpClient, gspUrl, file, fileExtContentType, headers, mode);
}
Aggregations