Search in sources :

Example 6 with QueryException

use of org.apache.jena.query.QueryException in project jena by apache.

the class ParserSPARQL11Update method _parse.

private void _parse(UpdateSink sink, Reader r) {
    SPARQLParser11 parser = null;
    try {
        parser = new SPARQLParser11(r);
        parser.setUpdateSink(sink);
        parser.UpdateUnit();
    } catch (org.apache.jena.sparql.lang.sparql_11.ParseException ex) {
        throw new QueryParseException(ex.getMessage(), ex.currentToken.beginLine, ex.currentToken.beginColumn);
    } catch (org.apache.jena.sparql.lang.sparql_11.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 (UpdateException 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);
    }
}
Also used : JenaException(org.apache.jena.shared.JenaException) QueryException(org.apache.jena.query.QueryException) SPARQLParser11(org.apache.jena.sparql.lang.sparql_11.SPARQLParser11) UpdateException(org.apache.jena.update.UpdateException) QueryParseException(org.apache.jena.query.QueryParseException)

Example 7 with QueryException

use of org.apache.jena.query.QueryException in project jena by apache.

the class ParserARQ method perform.

// All throwable handling.
private static void perform(Query query, String string, Action action) {
    Reader in = new StringReader(string);
    ARQParser parser = new ARQParser(in);
    try {
        query.setStrict(true);
        parser.setQuery(query);
        action.exec(parser);
    } 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(ParserSPARQL11.class, "Unexpected throwable: ", th);
        throw new QueryException(th.getMessage(), th);
    }
}
Also used : 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 8 with QueryException

use of org.apache.jena.query.QueryException in project jena by apache.

the class CSVInputIterator method parseLine.

private BindingMap parseLine(List<Var> vars, String line) {
    BindingMap binding = BindingFactory.create();
    List<String> terms = new ArrayList<>();
    int idx = 0;
    while (idx < line.length()) {
        char ch = line.charAt(idx);
        StringBuilder s = new StringBuilder();
        if (ch == '\"' || ch == '\'') {
            char qCh = ch;
            idx++;
            while (idx < line.length()) {
                ch = line.charAt(idx);
                idx++;
                if (ch == qCh)
                    break;
                // escapes??
                s.append(ch);
            }
            if (ch != qCh)
                throw new QueryException(String.format("Error Parsing CSV results at Line %d  - Unterminated quoted string", this.lineNum));
            if (idx < line.length()) {
                ch = line.charAt(idx);
                if (ch != ',')
                    throw new QueryException(String.format("Error Parsing CSV results at Line %d - Expected comma after quote", this.lineNum));
            }
        } else {
            while (idx < line.length()) {
                ch = line.charAt(idx);
                if (ch == ',')
                    break;
                idx++;
                // escapes
                s.append(ch);
            }
        }
        terms.add(s.toString());
        // Looking at , or EOL.
        if (ch == ',' && idx == line.length() - 1) {
            //EOL
            terms.add("");
            break;
        }
        // Skip ","
        idx++;
    }
    if (terms.size() != vars.size())
        throw new QueryException(String.format("Error Parsing CSV results at Line %d - The result row '%s' has %d items when %d was expected", this.lineNum, line, terms.size(), vars.size()));
    for (int i = 0; i < vars.size(); i++) binding.add(vars.get(i), NodeFactory.createLiteral(terms.get(i)));
    return binding;
}
Also used : QueryException(org.apache.jena.query.QueryException) ArrayList(java.util.ArrayList) BindingMap(org.apache.jena.sparql.engine.binding.BindingMap)

Example 9 with QueryException

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);
    }
}
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)

Aggregations

QueryException (org.apache.jena.query.QueryException)9 QueryParseException (org.apache.jena.query.QueryParseException)6 JenaException (org.apache.jena.shared.JenaException)6 Reader (java.io.Reader)4 StringReader (java.io.StringReader)4 ARQParser (org.apache.jena.sparql.lang.arq.ARQParser)3 Query (org.apache.jena.query.Query)2 SPARQLParser11 (org.apache.jena.sparql.lang.sparql_11.SPARQLParser11)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 IndentedLineBuffer (org.apache.jena.atlas.io.IndentedLineBuffer)1 QueryCheckException (org.apache.jena.sparql.core.QueryCheckException)1 BindingMap (org.apache.jena.sparql.engine.binding.BindingMap)1 SPARQLParser10 (org.apache.jena.sparql.lang.sparql_10.SPARQLParser10)1 UpdateException (org.apache.jena.update.UpdateException)1