form = "html";
}
QueryResult queryResult = new QueryResult();
SPARQLQuery sq = new SPARQLQuery();
sq.setTripleStore(_conn.ts);
sq.setQuery(sparqlQuery);
sq.setIncludeInferred(infer);
boolean useRun = false;
// NOTE about AG bugs:
// 1) SPARQLQuery.run throws an exception! argh!
// 2) the AG serializers are not working (not even in the examples provided by them)
// because of 1), commenting out the following so SPARQLQuery.run() is not called below.
// if ( form.equalsIgnoreCase("owl") || form.equalsIgnoreCase("rdf") ) {
// useRun = true;
// sq.setResultsFormat("sparql-xml");
// // TODO: contentType should be sparql-related
// queryResult.setContentType("Application/rdf+xml");
// }
// // else: TODO what other formats are possible?
if ( useRun ) {
String res = sq.run();
queryResult.setIsEmpty(res.trim().length() == 0);
queryResult.setResult(res);
return queryResult;
}
// use Jena to determine what kind of query this is (AG doesn't seem to provide an operation for this)
// so we call the appropriate execution method:
Query query = QueryFactory.create(sparqlQuery);
// only one of these results is captured
TriplesIterator tripleIter = null;
ValueSetIterator valSetIter = null;
Boolean askResult = null;
queryResult.setContentType("text/plain");
// SELECT
if ( query.isSelectType() ) {
valSetIter = sq.select();
}
// DESCRIBE
else if ( query.isDescribeType() ) {
tripleIter = sq.describe();
}
// CONSTRUCT
else if ( query.isConstructType() ) {
tripleIter = sq.construct();
}
// ASK
else if ( query.isAskType() ) {
askResult = Boolean.valueOf(sq.ask());
}
if ( valSetIter != null ) {
queryResult.setIsEmpty(! valSetIter.hasNext());
String res;