Search in sources :

Example 1 with QueryParseException

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);
    }
}
Also used : StringReader(java.io.StringReader) Reader(java.io.Reader) SPARQLParser10(org.apache.jena.sparql.lang.sparql_10.SPARQLParser10) QueryParseException(org.apache.jena.query.QueryParseException) JenaException(org.apache.jena.shared.JenaException) QueryException(org.apache.jena.query.QueryException) StringReader(java.io.StringReader)

Example 2 with QueryParseException

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);
    }
}
Also used : StringReader(java.io.StringReader) Reader(java.io.Reader) StringReader(java.io.StringReader) QueryParseException(org.apache.jena.query.QueryParseException) SSEParseException(org.apache.jena.sparql.sse.SSEParseException) QueryParseException(org.apache.jena.query.QueryParseException)

Example 3 with QueryParseException

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();
    }
}
Also used : UsingList(org.apache.jena.sparql.modify.UsingList) UpdateRequest(org.apache.jena.update.UpdateRequest) QueryBuildException(org.apache.jena.query.QueryBuildException) UpdateException(org.apache.jena.update.UpdateException) ServletException(javax.servlet.ServletException) QueryParseException(org.apache.jena.query.QueryParseException) QueryBuildException(org.apache.jena.query.QueryBuildException) IOException(java.io.IOException) UpdateException(org.apache.jena.update.UpdateException) QueryParseException(org.apache.jena.query.QueryParseException)

Example 4 with QueryParseException

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);
    }
}
Also used : Query(org.apache.jena.query.Query) StringReader(java.io.StringReader) Reader(java.io.Reader) QueryParseException(org.apache.jena.query.QueryParseException) JenaException(org.apache.jena.shared.JenaException) QueryException(org.apache.jena.query.QueryException) ARQParser(org.apache.jena.sparql.lang.arq.ARQParser) StringReader(java.io.StringReader)

Example 5 with QueryParseException

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);
}
Also used : WriterPath(org.apache.jena.sparql.sse.writers.WriterPath) BuilderPath(org.apache.jena.sparql.sse.builders.BuilderPath) Item(org.apache.jena.sparql.sse.Item) Prologue(org.apache.jena.sparql.core.Prologue) QueryParseException(org.apache.jena.query.QueryParseException)

Aggregations

QueryParseException (org.apache.jena.query.QueryParseException)16 StringReader (java.io.StringReader)6 QueryException (org.apache.jena.query.QueryException)6 JenaException (org.apache.jena.shared.JenaException)6 Reader (java.io.Reader)5 ARQParser (org.apache.jena.sparql.lang.arq.ARQParser)4 Query (org.apache.jena.query.Query)3 VarExprList (org.apache.jena.sparql.core.VarExprList)3 UpdateRequest (org.apache.jena.update.UpdateRequest)3 JsonBuilder (org.apache.jena.atlas.json.JsonBuilder)2 Syntax (org.apache.jena.query.Syntax)2 Prologue (org.apache.jena.sparql.core.Prologue)2 Expr (org.apache.jena.sparql.expr.Expr)2 SPARQLParser11 (org.apache.jena.sparql.lang.sparql_11.SPARQLParser11)2 UpdateException (org.apache.jena.update.UpdateException)2 IOException (java.io.IOException)1 ServletException (javax.servlet.ServletException)1 ArgDecl (jena.cmd.ArgDecl)1 CmdException (jena.cmd.CmdException)1 CmdLineArgs (jena.cmd.CmdLineArgs)1