use of org.apache.jena.query.QueryParseException 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.QueryParseException in project jena by apache.
the class ExprUtils method parse.
public static Expr parse(Query query, String s, boolean checkAllUsed) {
try {
Reader in = new StringReader(s);
ARQParser parser = new ARQParser(in);
parser.setQuery(query);
Expr expr = parser.Expression();
if (checkAllUsed) {
Token t = parser.getNextToken();
if (t.kind != ARQParserTokenManager.EOF)
throw new QueryParseException("Extra tokens beginning \"" + t.image + "\" starting line " + t.beginLine + ", column " + t.beginColumn, t.beginLine, t.beginColumn);
}
return expr;
} catch (ParseException ex) {
throw new QueryParseException(ex.getMessage(), ex.currentToken.beginLine, ex.currentToken.beginLine);
} catch (TokenMgrError tErr) {
throw new QueryParseException(tErr.getMessage(), -1, -1);
} catch (Error err) {
// The token stream can throw java.lang.Error's
String tmp = err.getMessage();
if (tmp == null)
throw new QueryParseException(err, -1, -1);
throw new QueryParseException(tmp, -1, -1);
}
}
use of org.apache.jena.query.QueryParseException in project jena by apache.
the class SPARQL_Update method execute.
private void execute(HttpAction action, InputStream input) {
// OPTIONS
if (action.request.getMethod().equals(HttpNames.METHOD_OPTIONS)) {
// Share with update via SPARQL_Protocol.
doOptions(action);
return;
}
UsingList usingList = processProtocol(action.request);
// If the dsg is transactional, then we can parse and execute the update in a streaming fashion.
// If it isn't, we need to read the entire update request before performing any updates, because
// we have to attempt to make the request atomic in the face of malformed updates
UpdateRequest req = null;
if (!action.isTransactional()) {
try {
req = UpdateFactory.read(usingList, input, UpdateParseBase, Syntax.syntaxARQ);
} catch (UpdateException ex) {
ServletOps.errorBadRequest(ex.getMessage());
return;
} catch (QueryParseException ex) {
ServletOps.errorBadRequest(messageForQueryException(ex));
return;
}
}
action.beginWrite();
try {
if (req == null)
UpdateAction.parseExecute(usingList, action.getActiveDSG(), input, UpdateParseBase, Syntax.syntaxARQ);
else
UpdateAction.execute(req, action.getActiveDSG());
action.commit();
} catch (UpdateException ex) {
action.abort();
incCounter(action.getEndpoint().getCounters(), UpdateExecErrors);
ServletOps.errorOccurred(ex.getMessage());
} catch (QueryParseException | QueryBuildException ex) {
action.abort();
// Counter inc'ed further out.
ServletOps.errorBadRequest(messageForQueryException(ex));
} catch (Throwable ex) {
if (!(ex instanceof ActionErrorException)) {
try {
action.abort();
} catch (Exception ex2) {
}
ServletOps.errorOccurred(ex.getMessage(), ex);
}
} finally {
action.endWrite();
}
}
use of org.apache.jena.query.QueryParseException 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.QueryParseException in project jena by apache.
the class TestPath method parse.
private void parse(String string, boolean expectLegal) {
Prologue prologue = new Prologue(pmap);
Path p = null;
try {
p = PathParser.parse(string, prologue);
// System.out.println(PathWriterSSE.asString(p, new Prologue(pmap))) ;
if (!expectLegal)
fail("Expected error; " + string);
} catch (QueryParseException ex) {
if (expectLegal)
fail("Expected success: " + string + ": " + ex.getMessage());
return;
}
String x = p.toString(prologue);
Path p2 = PathParser.parse(x, prologue);
assertEquals(p, p2);
String sse = WriterPath.asString(p, prologue);
Item item = SSE.parseItem(sse, pmap);
p2 = BuilderPath.buildPath(item);
assertEquals(p, p2);
}
Aggregations