Search in sources :

Example 21 with RiotException

use of org.apache.jena.riot.RiotException in project jena by apache.

the class UnitTestBadSyntax method run4.

private void run4() {
    Dataset ds = DatasetFactory.createGeneral();
    try {
        RDFDataMgr.read(ds, uri, uri, lang);
    } catch (RiotException ex) {
        return;
    } catch (RuntimeException ex) {
        ex.printStackTrace(System.err);
        fail("Unexpected exception");
    }
    fail("Bad syntax test succeed in parsing the file");
}
Also used : RiotException(org.apache.jena.riot.RiotException) Dataset(org.apache.jena.query.Dataset)

Example 22 with RiotException

use of org.apache.jena.riot.RiotException in project jena by apache.

the class UnitTestEval method run4.

private void run4() {
    DatasetGraph dsg = DatasetGraphFactory.create();
    try {
        if (baseIRI != null)
            RDFDataMgr.read(dsg, input, baseIRI, lang);
        else
            RDFDataMgr.read(dsg, input, lang);
        Lang outLang = RDFLanguages.filenameToLang(output, Lang.NQUADS);
        DatasetGraph results = DatasetGraphFactory.create();
        try {
            RDFDataMgr.read(results, output, outLang);
        } catch (RiotException ex) {
            fail("Failed to read results: " + ex.getMessage());
        }
        boolean b = isomorphic(dsg, results);
        if (!b) {
            System.out.println("**** Test: " + getName());
            System.out.println("---- Parsed");
            RDFDataMgr.write(System.out, dsg, Lang.TRIG);
            System.out.println("---- Expected");
            RDFDataMgr.write(System.out, results, Lang.TRIG);
            System.out.println("--------");
        }
        assertTrue("Datasets not isomorphic", b);
    } catch (RiotException ex) {
        // Catch and rethrow - debugging.
        throw ex;
    } catch (RuntimeException ex) {
        ex.printStackTrace(System.err);
        throw ex;
    }
}
Also used : RiotException(org.apache.jena.riot.RiotException) Lang(org.apache.jena.riot.Lang) DatasetGraph(org.apache.jena.sparql.core.DatasetGraph)

Example 23 with RiotException

use of org.apache.jena.riot.RiotException in project jena by apache.

the class UnitTestEval method run3.

// Triples test.
private void run3() {
    Model model = ModelFactory.createDefaultModel();
    try {
        if (baseIRI != null)
            RDFDataMgr.read(model, input, baseIRI, lang);
        else
            RDFDataMgr.read(model, input, lang);
        Lang outLang = RDFLanguages.filenameToLang(output, Lang.NQUADS);
        Model results = ModelFactory.createDefaultModel();
        try {
            RDFDataMgr.read(results, output, outLang);
        } catch (RiotException ex) {
            fail("Failed to read results: " + ex.getMessage());
        }
        boolean b = model.isIsomorphicWith(results);
        if (!b) {
            //model.isIsomorphicWith(results) ;
            System.out.println("---- Parsed");
            model.write(System.out, "TTL");
            System.out.println("---- Expected");
            results.write(System.out, "TTL");
            System.out.println("--------");
        }
        assertTrue("Models not isomorphic", b);
    } catch (RiotException ex) {
        // Catch and rethrow - debugging.
        throw ex;
    } catch (RuntimeException ex) {
        ex.printStackTrace(System.err);
        throw ex;
    }
}
Also used : RiotException(org.apache.jena.riot.RiotException) Model(org.apache.jena.rdf.model.Model) Lang(org.apache.jena.riot.Lang)

Example 24 with RiotException

use of org.apache.jena.riot.RiotException in project jena by apache.

the class REST_Quads_RW method doPutPostTxn.

private void doPutPostTxn(HttpAction action, boolean clearFirst) {
    UploadDetails details = null;
    action.beginWrite();
    try {
        DatasetGraph dsg = action.getActiveDSG();
        if (clearFirst)
            dsg.clear();
        StreamRDF dest = StreamRDFLib.dataset(dsg);
        details = Upload.incomingData(action, dest);
        action.commit();
        ServletOps.success(action);
    } catch (RiotException ex) {
        // Parse error
        action.abort();
        ServletOps.errorBadRequest(ex.getMessage());
    } catch (ActionErrorException ex) {
        action.abort();
        throw ex;
    } catch (Exception ex) {
        // Something else went wrong. Backout.
        action.abort();
        ServletOps.errorOccurred(ex.getMessage());
    } finally {
        action.endWrite();
    }
    ServletOps.uploadResponse(action, details);
}
Also used : RiotException(org.apache.jena.riot.RiotException) StreamRDF(org.apache.jena.riot.system.StreamRDF) RiotException(org.apache.jena.riot.RiotException) DatasetGraph(org.apache.jena.sparql.core.DatasetGraph)

Example 25 with RiotException

use of org.apache.jena.riot.RiotException in project jena by apache.

the class REST_Quads_RW method doPutPostNonTxn.

private void doPutPostNonTxn(HttpAction action, boolean clearFirst) {
    DatasetGraph dsgTmp = DatasetGraphFactory.create();
    StreamRDF dest = StreamRDFLib.dataset(dsgTmp);
    UploadDetails details;
    try {
        details = Upload.incomingData(action, dest);
    } catch (RiotException ex) {
        ServletOps.errorBadRequest(ex.getMessage());
        return;
    }
    // Now insert into dataset
    action.beginWrite();
    try {
        DatasetGraph dsg = action.getActiveDSG();
        if (clearFirst)
            dsg.clear();
        FusekiLib.addDataInto(dsgTmp, dsg);
        action.commit();
        ServletOps.success(action);
    } catch (Exception ex) {
        // but it might and there is no harm safely trying.
        try {
            action.abort();
        } catch (Exception ex2) {
        }
        ServletOps.errorOccurred(ex.getMessage());
    } finally {
        action.endWrite();
    }
    ServletOps.uploadResponse(action, details);
}
Also used : RiotException(org.apache.jena.riot.RiotException) StreamRDF(org.apache.jena.riot.system.StreamRDF) RiotException(org.apache.jena.riot.RiotException) DatasetGraph(org.apache.jena.sparql.core.DatasetGraph)

Aggregations

RiotException (org.apache.jena.riot.RiotException)33 Node (org.apache.jena.graph.Node)10 IOException (java.io.IOException)7 StreamRDF (org.apache.jena.riot.system.StreamRDF)7 Graph (org.apache.jena.graph.Graph)4 Model (org.apache.jena.rdf.model.Model)4 Lang (org.apache.jena.riot.Lang)4 Token (org.apache.jena.riot.tokens.Token)4 DatasetGraph (org.apache.jena.sparql.core.DatasetGraph)4 Dataset (org.apache.jena.query.Dataset)3 InternalErrorException (org.apache.jena.atlas.lib.InternalErrorException)2 IRI (org.apache.jena.iri.IRI)2 Tokenizer (org.apache.jena.riot.tokens.Tokenizer)2 Var (org.apache.jena.sparql.core.Var)2 JsonGenerationException (com.fasterxml.jackson.core.JsonGenerationException)1 JsonMappingException (com.fasterxml.jackson.databind.JsonMappingException)1 JsonLdError (com.github.jsonldjava.core.JsonLdError)1 RDFDataset (com.github.jsonldjava.core.RDFDataset)1 BufferedReader (java.io.BufferedReader)1 InputStream (java.io.InputStream)1