use of org.apache.jena.query.QueryException in project jena by apache.
the class CSVInputIterator method parseNextBinding.
private boolean parseNextBinding() {
String line;
try {
line = this.reader.readLine();
//Once EOF has been reached we'll see null for this call so we can return false because there are no further bindings
if (line == null)
return false;
this.lineNum++;
} catch (IOException e) {
throw new QueryException("Error parsing CSV results - " + e.getMessage());
}
if (line.isEmpty()) {
// which means a non-empty string which we handle normally
if (expectedItems > 1)
throw new QueryException(String.format("Error Parsing CSV results at Line %d - The result row had 0/1 values when %d were expected", this.lineNum, expectedItems));
binding = BindingFactory.create();
if (expectedItems == 1)
binding.add(vars.get(0), NodeConst.emptyString);
return true;
}
binding = parseLine(vars, line);
return true;
}
use of org.apache.jena.query.QueryException in project jena by apache.
the class ParserSPARQL10 method perform.
// All throwable handling.
private static void perform(Query query, String string, Action action) {
Reader in = new StringReader(string);
SPARQLParser10 parser = new SPARQLParser10(in);
try {
query.setStrict(true);
parser.setQuery(query);
action.exec(parser);
} catch (org.apache.jena.sparql.lang.sparql_10.ParseException ex) {
throw new QueryParseException(ex.getMessage(), ex.currentToken.beginLine, ex.currentToken.beginColumn);
} catch (org.apache.jena.sparql.lang.sparql_10.TokenMgrError tErr) {
// Last valid token : not the same as token error message - but this should not happen
int col = parser.token.endColumn;
int line = parser.token.endLine;
throw new QueryParseException(tErr.getMessage(), line, col);
} catch (QueryException ex) {
throw ex;
} catch (JenaException ex) {
throw new QueryException(ex.getMessage(), ex);
} catch (Error err) {
// The token stream can throw errors.
throw new QueryParseException(err.getMessage(), err, -1, -1);
} catch (Throwable th) {
Log.warn(ParserSPARQL10.class, "Unexpected throwable: ", th);
throw new QueryException(th.getMessage(), th);
}
}
use of org.apache.jena.query.QueryException in project jena by apache.
the class QueryUtils method checkParse.
public static void checkParse(Query query) {
if (!SPARQLParserRegistry.get().containsFactory(query.getSyntax()))
return;
IndentedLineBuffer buff = new IndentedLineBuffer();
query.serialize(buff, query.getSyntax());
String tmp = buff.toString();
Query query2 = null;
try {
String baseURI = null;
if (!query.explicitlySetBaseURI())
// Not in query - use the same one (e.g. file read from) .
baseURI = query.getBaseURI();
query2 = QueryFactory.create(tmp, baseURI, query.getSyntax());
if (query2 == null)
return;
} catch (UnsupportedOperationException ex) {
// No parser after all.
return;
} catch (QueryException ex) {
System.err.println(tmp);
throw new QueryCheckException("could not parse output query", ex);
}
if (query.hashCode() != query2.hashCode())
throw new QueryCheckException("reparsed query hashCode does not equal parsed input query \nQuery (hashCode: " + query.hashCode() + ")=\n" + query + "\n\nQuery2 (hashCode: " + query2.hashCode() + ")=\n" + query2);
if (!query.equals(query2))
throw new QueryCheckException("reparsed output does not equal parsed input");
}
use of org.apache.jena.query.QueryException in project jena by apache.
the class PathParser method parse.
public static Path parse(String str, Prologue prologue) {
Query query = new Query(prologue);
Reader in = new StringReader(str);
ARQParser parser = new ARQParser(in);
try {
query.setStrict(true);
parser.setQuery(query);
return parser.PathUnit();
} catch (org.apache.jena.sparql.lang.arq.ParseException ex) {
throw new QueryParseException(ex.getMessage(), ex.currentToken.beginLine, ex.currentToken.beginColumn);
} catch (org.apache.jena.sparql.lang.arq.TokenMgrError tErr) {
// Last valid token : not the same as token error message - but this should not happen
int col = parser.token.endColumn;
int line = parser.token.endLine;
throw new QueryParseException(tErr.getMessage(), line, col);
} catch (QueryException ex) {
throw ex;
} catch (JenaException ex) {
throw new QueryException(ex.getMessage(), ex);
} catch (Error err) {
// The token stream can throw errors.
throw new QueryParseException(err.getMessage(), err, -1, -1);
} catch (Throwable th) {
Log.warn(PathParser.class, "Unexpected throwable: ", th);
throw new QueryException(th.getMessage(), th);
}
}
use of org.apache.jena.query.QueryException in project jena by apache.
the class ParserARQUpdate method _parse.
private void _parse(UpdateSink sink, Reader r) {
ARQParser parser = null;
try {
parser = new ARQParser(r);
parser.setUpdateSink(sink);
parser.UpdateUnit();
} catch (org.apache.jena.sparql.lang.arq.ParseException ex) {
throw new QueryParseException(ex.getMessage(), ex.currentToken.beginLine, ex.currentToken.beginColumn);
} catch (org.apache.jena.sparql.lang.arq.TokenMgrError tErr) {
// Last valid token : not the same as token error message - but this should not happen
int col = parser.token.endColumn;
int line = parser.token.endLine;
throw new QueryParseException(tErr.getMessage(), line, col);
} catch (QueryException ex) {
throw ex;
} catch (JenaException ex) {
throw new QueryException(ex.getMessage(), ex);
} catch (Error err) {
// The token stream can throw errors.
throw new QueryParseException(err.getMessage(), err, -1, -1);
} catch (Throwable th) {
Log.error(this, "Unexpected throwable: ", th);
throw new QueryException(th.getMessage(), th);
}
}
Aggregations