Search in sources :

Example 31 with RDFParseException

use of org.eclipse.rdf4j.rio.RDFParseException in project rdf4j by eclipse.

the class CustomTurtleParserTest method testSES1887NoLangTagFailure.

@Test
public void testSES1887NoLangTagFailure() throws Exception {
    try {
        Rio.parse(new StringReader("<urn:a> <http://www.example.net/test> \"Foo\"@."), "", RDFFormat.TURTLE);
        fail("Did not receive an exception");
    } catch (RDFParseException e) {
        assertTrue(e.getMessage().contains("Expected a letter, found '.'"));
    }
}
Also used : StringReader(java.io.StringReader) RDFParseException(org.eclipse.rdf4j.rio.RDFParseException) Test(org.junit.Test)

Example 32 with RDFParseException

use of org.eclipse.rdf4j.rio.RDFParseException in project rdf4j by eclipse.

the class CustomTurtleParserTest method testSES1887NoLangTagFailure2.

@Test
public void testSES1887NoLangTagFailure2() throws Exception {
    try {
        // NOTE: Bad things may happen when VERIFY_LANGUAGE_TAGS is turned off
        // on a file of this structure
        Rio.parse(new StringReader("<urn:a> <http://www.example.net/test> \"Foo\"@."), "", RDFFormat.TURTLE, settingsNoVerifyLangTag, vf, errors);
        fail("Did not receive an exception");
    } catch (RDFParseException e) {
        assertTrue(e.getMessage().contains("Unexpected end of file"));
    }
}
Also used : StringReader(java.io.StringReader) RDFParseException(org.eclipse.rdf4j.rio.RDFParseException) Test(org.junit.Test)

Example 33 with RDFParseException

use of org.eclipse.rdf4j.rio.RDFParseException in project rdf4j by eclipse.

the class CustomTurtleParserTest method testSES2086PeriodEndingLocalNamesFailure1.

@Test
public void testSES2086PeriodEndingLocalNamesFailure1() throws Exception {
    try {
        Rio.parse(new StringReader("@prefix : <http://example.org> .\n <urn:a> <http://www.example.net/test> :test. ."), "", RDFFormat.TURTLE);
        fail("Did not receive an exception");
    } catch (RDFParseException e) {
        System.out.println(e.getMessage());
        assertTrue(e.getMessage().contains("Object for statement missing"));
    }
}
Also used : StringReader(java.io.StringReader) RDFParseException(org.eclipse.rdf4j.rio.RDFParseException) Test(org.junit.Test)

Example 34 with RDFParseException

use of org.eclipse.rdf4j.rio.RDFParseException in project rdf4j by eclipse.

the class SPARQLConnection method add.

@Override
public void add(URL url, String baseURI, RDFFormat dataFormat, Resource... contexts) throws IOException, RDFParseException, RepositoryException {
    OpenRDFUtil.verifyContextNotNull(contexts);
    // to preserve bnode identity, we need to make sure all statements are
    // processed in a single INSERT DATA command
    StatementCollector collector = new StatementCollector();
    boolean localTransaction = startLocalTransaction();
    try {
        RDFLoader loader = new RDFLoader(getParserConfig(), getValueFactory());
        loader.load(url, baseURI, dataFormat, collector);
        add(collector.getStatements(), contexts);
        conditionalCommit(localTransaction);
    } catch (RDFHandlerException e) {
        conditionalRollback(localTransaction);
        // RDFInserter only throws wrapped RepositoryExceptions
        throw (RepositoryException) e.getCause();
    } catch (RDFParseException e) {
        conditionalRollback(localTransaction);
        throw e;
    } catch (IOException e) {
        conditionalRollback(localTransaction);
        throw e;
    } catch (RuntimeException e) {
        conditionalRollback(localTransaction);
        throw e;
    }
}
Also used : RDFHandlerException(org.eclipse.rdf4j.rio.RDFHandlerException) StatementCollector(org.eclipse.rdf4j.rio.helpers.StatementCollector) IOException(java.io.IOException) RDFLoader(org.eclipse.rdf4j.repository.util.RDFLoader) RDFParseException(org.eclipse.rdf4j.rio.RDFParseException)

Example 35 with RDFParseException

use of org.eclipse.rdf4j.rio.RDFParseException in project rdf4j by eclipse.

the class RDFLoader method loadZip.

private void loadZip(InputStream in, String baseURI, RDFFormat dataFormat, RDFHandler rdfHandler) throws IOException, RDFParseException, RDFHandlerException {
    try (ZipInputStream zipIn = new ZipInputStream(in)) {
        for (ZipEntry entry = zipIn.getNextEntry(); entry != null; entry = zipIn.getNextEntry()) {
            if (entry.isDirectory()) {
                continue;
            }
            try {
                RDFFormat format = Rio.getParserFormatForFileName(entry.getName()).orElse(dataFormat);
                // Prevent parser (Xerces) from closing the input stream
                UncloseableInputStream wrapper = new UncloseableInputStream(zipIn);
                load(wrapper, baseURI, format, rdfHandler);
            } catch (RDFParseException e) {
                String msg = e.getMessage() + " in " + entry.getName();
                RDFParseException pe = new RDFParseException(msg, e.getLineNumber(), e.getColumnNumber());
                pe.initCause(e);
                throw pe;
            } finally {
                zipIn.closeEntry();
            }
        }
    // end for
    }
}
Also used : ZipInputStream(java.util.zip.ZipInputStream) ZipEntry(java.util.zip.ZipEntry) UncloseableInputStream(org.eclipse.rdf4j.common.io.UncloseableInputStream) RDFFormat(org.eclipse.rdf4j.rio.RDFFormat) RDFParseException(org.eclipse.rdf4j.rio.RDFParseException)

Aggregations

RDFParseException (org.eclipse.rdf4j.rio.RDFParseException)50 Test (org.junit.Test)22 RDFHandlerException (org.eclipse.rdf4j.rio.RDFHandlerException)19 IOException (java.io.IOException)16 StringReader (java.io.StringReader)13 StatementCollector (org.eclipse.rdf4j.rio.helpers.StatementCollector)9 RDFLoader (org.eclipse.rdf4j.repository.util.RDFLoader)8 Model (org.eclipse.rdf4j.model.Model)7 RDFParser (org.eclipse.rdf4j.rio.RDFParser)7 Statement (org.eclipse.rdf4j.model.Statement)6 LinkedHashModel (org.eclipse.rdf4j.model.impl.LinkedHashModel)6 RepositoryException (org.eclipse.rdf4j.repository.RepositoryException)5 RDFFormat (org.eclipse.rdf4j.rio.RDFFormat)5 ByteArrayOutputStream (java.io.ByteArrayOutputStream)4 InputStream (java.io.InputStream)4 Reader (java.io.Reader)4 RDFInserter (org.eclipse.rdf4j.repository.util.RDFInserter)4 SAXException (org.xml.sax.SAXException)4 IRI (org.eclipse.rdf4j.model.IRI)3 Literal (org.eclipse.rdf4j.model.Literal)3