@Override public Response toResponse(final QueryParseException e) { LOGGER.error("Captured a query parse exception {}", e.getMessage()); debugException(this, e, LOGGER); if (e.getMessage().matches(".* Unresolved prefixed name: .*")) { final Pattern namespacePattern = Pattern.compile("Unresolved prefixed name: (\\w+:\\w+)"); final Matcher namespaceMatch = namespacePattern.matcher(e.getMessage()); if (namespaceMatch.find()) { final String msg = String.format( "There are one or more undefined namespace(s) in your request [ %s ], " + "please define them before retrying", namespaceMatch.group(1)); return status(BAD_REQUEST).entity(msg).type(TEXT_PLAIN_WITH_CHARSET).build(); } } return status(BAD_REQUEST).entity(e.getMessage()).type(TEXT_PLAIN_WITH_CHARSET).build(); }
/** * Execute a SPARQL SELECT query on a dataset and return a result set. * * @param dataset the Dataset to query over * @param query the SPARQL query string * @return the result set * @throws IOException on query parse error */ public static ResultSet execQuery(Dataset dataset, String query) throws IOException { QueryExecution qExec; try { qExec = QueryExecutionFactory.create(query, dataset); } catch (QueryParseException e) { throw new IOException(String.format(queryParseError, e.getMessage())); } return qExec.execSelect(); }
public static void expr(String exprStr, Binding binding) { try { Expr expr = ExprUtils.parse(exprStr, ARQConstants.getGlobalPrefixMap()) ; evalPrint(expr, binding) ; } catch (QueryParseException ex) { System.err.println("Parse error: "+ex.getMessage()) ; return ; } }
/** * Given a dataset, a query string, a format name, and an output stream, run the SPARQL query over * the named graphs and write the output to the stream. * * @param dataset Dataset to query over * @param queryString query to run * @param formatName format of output * @param output output stream to write to * @return true if successful * @throws IOException on issue parsing query */ public static boolean runSparqlQuery( Dataset dataset, String queryString, String formatName, OutputStream output) throws IOException { dataset.begin(ReadWrite.READ); boolean result; try (QueryExecution qExec = QueryExecutionFactory.create(queryString, dataset)) { result = runSparqlQuery(qExec, formatName, output); } catch (QueryParseException e) { throw new IOException(String.format(queryParseError, e.getMessage())); } finally { dataset.end(); } return result; }
System.err.println(ex.getMessage()) ; return ;
@Override protected SparqlStmt computeNext() { if (isEmptyString(str)) { return endOfData(); } SparqlStmt result = parser.apply(str); // Get the string up to the point where a parse error was encountered QueryParseException ex = result.getParseException(); if (ex != null) { int[] exPos = parsePos(ex.getMessage()); int pos = toCharPos(str, exPos[0], exPos[1]); line = line + Math.max(0, exPos[0] - 1); column = column + Math.max(0, exPos[1] - 1); String retryStr = str.substring(0, pos); // Note: Jena parses an empty string as a sparql update statement without errors if (isEmptyString(retryStr)) { throw new RuntimeException("Error near line " + line + ", column " + column + ".", ex); } result = parser.apply(retryStr); QueryParseException retryEx = result.getParseException(); if (retryEx != null) { throw new RuntimeException("Error near line " + line + ", column " + column + ".", ex); } str = str.substring(pos); } else { // TODO Move position to last char in the string str = ""; } return result; }
System.err.println(ex.getMessage()) ; return ;
} catch (QueryParseException qpe) { String errorMsg = "<p>Unable to parse query:</p>"; if (qpe.getMessage() != null) { errorMsg += "<p>" + qpe.getMessage() + "</p>";
@Override public void read(Reader reader, String baseURI, ContentType ct, StreamRDF output, Context context) { TurtleJavacc parser = new TurtleJavacc(reader); parser.setDest(output); parser.setProfile(profile); try { output.start(); parser.parse(); output.finish(); } catch (QueryParseException ex) { throw new RiotParseException(ex.getMessage(), ex.getLine(), ex.getColumn()); } catch (ParseException ex) { throw new RiotParseException(ex.getMessage(), ex.currentToken.beginLine, ex.currentToken.beginColumn); } catch (TokenMgrError ex) { throw new RiotParseException(ex.getMessage(), -1 , -1); } }
@Override public void read(InputStream in, String baseURI, ContentType ct, StreamRDF output, Context context) { TurtleJavacc parser = new TurtleJavacc(in); parser.setDest(output); parser.setProfile(profile); try { output.start(); parser.parse(); output.finish(); } catch (QueryParseException ex) { // We reused some SPARQL machinery throw new RiotParseException(ex.getMessage(), ex.getLine(), ex.getColumn()); } catch (ParseException ex) { // Logger log = LoggerFactory.getLogger("TurtleJavaCC"); // ErrorHandler errorHandler = ErrorHandlerFactory.errorHandlerStd(log); // errorHandler.error(ex.getMessage(), ex.currentToken.beginLine, ex.currentToken.beginColumn); throw new RiotParseException(ex.getMessage(), ex.currentToken.beginLine, ex.currentToken.beginColumn); } catch (TokenMgrError ex) { throw new RiotParseException(ex.getMessage(), -1 , -1); } }
System.err.println("Parse error: "+ex.getMessage()) ; throw new TerminationException(2) ;
System.err.println("Parse error: "+ex.getMessage()) ; throw new TerminationException(2) ;
obj.key(jParseError).value(ex.getMessage()) ; obj.key(jParseErrorLine).value(ex.getLine()) ; obj.key(jParseErrorCol).value(ex.getColumn()) ;
obj.key(jParseError).value(ex.getMessage()) ; obj.key(jParseErrorLine).value(ex.getLine()) ; obj.key(jParseErrorCol).value(ex.getColumn()) ;
private void parse(String string, boolean expectLegal) { Prologue prologue = new Prologue(pmap) ; Path p = null ; try { p = PathParser.parse(string, prologue) ; // System.out.println(string+" ==> "+p.toString(new Prologue(pmap))) ; // 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) ; }
obj.key(jParseError).value(ex.getMessage()) ; obj.key(jParseErrorLine).value(ex.getLine()) ; obj.key(jParseErrorCol).value(ex.getColumn()) ;
obj.key(jParseError).value(ex.getMessage()) ; obj.key(jParseErrorLine).value(ex.getLine()) ; obj.key(jParseErrorCol).value(ex.getColumn()) ;