Search in sources :

Example 36 with RDFParseException

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

the class AbstractRepositoryConnection method add.

@Override
public void add(URL url, String baseURI, RDFFormat dataFormat, Resource... contexts) throws IOException, RDFParseException, RepositoryException {
    OpenRDFUtil.verifyContextNotNull(contexts);
    RDFInserter rdfInserter = new RDFInserter(this);
    rdfInserter.enforceContext(contexts);
    boolean localTransaction = startLocalTransaction();
    try {
        RDFLoader loader = new RDFLoader(getParserConfig(), getValueFactory());
        loader.load(url, baseURI, dataFormat, rdfInserter);
        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) RDFInserter(org.eclipse.rdf4j.repository.util.RDFInserter) IOException(java.io.IOException) RDFLoader(org.eclipse.rdf4j.repository.util.RDFLoader) RDFParseException(org.eclipse.rdf4j.rio.RDFParseException)

Example 37 with RDFParseException

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

the class AbstractRepositoryConnection method add.

@Override
public void add(Reader reader, String baseURI, RDFFormat dataFormat, Resource... contexts) throws IOException, RDFParseException, RepositoryException {
    OpenRDFUtil.verifyContextNotNull(contexts);
    RDFInserter rdfInserter = new RDFInserter(this);
    rdfInserter.enforceContext(contexts);
    boolean localTransaction = startLocalTransaction();
    try {
        RDFLoader loader = new RDFLoader(getParserConfig(), getValueFactory());
        loader.load(reader, baseURI, dataFormat, rdfInserter);
        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) RDFInserter(org.eclipse.rdf4j.repository.util.RDFInserter) IOException(java.io.IOException) RDFLoader(org.eclipse.rdf4j.repository.util.RDFLoader) RDFParseException(org.eclipse.rdf4j.rio.RDFParseException)

Example 38 with RDFParseException

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

the class RDFXMLParserCustomTest method testEntityExpansionDefaultSettings.

/**
 * Test with the default ParserConfig settings. Ie, setParserConfig is not called.
 *
 * @throws Exception
 */
@Test
public void testEntityExpansionDefaultSettings() throws Exception {
    final Model aGraph = new LinkedHashModel();
    ParseErrorCollector errorCollector = new ParseErrorCollector();
    RDFParser aParser = Rio.createParser(RDFFormat.RDFXML).setRDFHandler(new StatementCollector(aGraph)).setParseErrorListener(errorCollector);
    try {
        // this should trigger a SAX parse exception that will blow up at the
        // 64k entity limit rather than OOMing
        aParser.parse(this.getClass().getResourceAsStream("/testcases/rdfxml/openrdf/bad-entity-expansion-limit.rdf"), "http://example.org");
        fail("Parser did not throw an exception");
    } catch (RDFParseException e) {
    // assertTrue(e.getMessage().contains(
    // "The parser has encountered more than \"64,000\" entity expansions in this document; this is the limit imposed by the "));
    }
    assertEquals(0, errorCollector.getWarnings().size());
    assertEquals(0, errorCollector.getErrors().size());
    assertEquals(1, errorCollector.getFatalErrors().size());
}
Also used : StatementCollector(org.eclipse.rdf4j.rio.helpers.StatementCollector) LinkedHashModel(org.eclipse.rdf4j.model.impl.LinkedHashModel) Model(org.eclipse.rdf4j.model.Model) ParseErrorCollector(org.eclipse.rdf4j.rio.helpers.ParseErrorCollector) LinkedHashModel(org.eclipse.rdf4j.model.impl.LinkedHashModel) RDFParser(org.eclipse.rdf4j.rio.RDFParser) RDFParseException(org.eclipse.rdf4j.rio.RDFParseException) Test(org.junit.Test)

Example 39 with RDFParseException

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

the class RDFXMLParserCustomTest method testEntityExpansionUnrelatedSettings.

/**
 * Test with unrelated ParserConfig settings
 *
 * @throws Exception
 */
@Test
public void testEntityExpansionUnrelatedSettings() throws Exception {
    final Model aGraph = new LinkedHashModel();
    ParseErrorCollector errorCollector = new ParseErrorCollector();
    ParserConfig config = new ParserConfig();
    RDFParser aParser = Rio.createParser(RDFFormat.RDFXML).setRDFHandler(new StatementCollector(aGraph)).setParserConfig(config).setParseErrorListener(errorCollector);
    try {
        // this should trigger a SAX parse exception that will blow up at the
        // 64k entity limit rather than OOMing
        aParser.parse(this.getClass().getResourceAsStream("/testcases/rdfxml/openrdf/bad-entity-expansion-limit.rdf"), "http://example.org");
        fail("Parser did not throw an exception");
    } catch (RDFParseException e) {
    // assertTrue(e.getMessage().contains(
    // "The parser has encountered more than \"64,000\" entity expansions in this document; this is the limit imposed by the "));
    }
    assertEquals(0, errorCollector.getWarnings().size());
    assertEquals(0, errorCollector.getErrors().size());
    assertEquals(1, errorCollector.getFatalErrors().size());
}
Also used : StatementCollector(org.eclipse.rdf4j.rio.helpers.StatementCollector) LinkedHashModel(org.eclipse.rdf4j.model.impl.LinkedHashModel) Model(org.eclipse.rdf4j.model.Model) ParseErrorCollector(org.eclipse.rdf4j.rio.helpers.ParseErrorCollector) LinkedHashModel(org.eclipse.rdf4j.model.impl.LinkedHashModel) RDFParser(org.eclipse.rdf4j.rio.RDFParser) ParserConfig(org.eclipse.rdf4j.rio.ParserConfig) RDFParseException(org.eclipse.rdf4j.rio.RDFParseException) Test(org.junit.Test)

Example 40 with RDFParseException

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

the class RDFXMLParserCustomTest method testEntityExpansionSecureProcessing.

/**
 * Test with Secure processing setting on.
 *
 * @throws Exception
 */
@Test
public void testEntityExpansionSecureProcessing() throws Exception {
    final Model aGraph = new LinkedHashModel();
    ParseErrorCollector errorCollector = new ParseErrorCollector();
    RDFParser aParser = Rio.createParser(RDFFormat.RDFXML).setRDFHandler(new StatementCollector(aGraph)).set(XMLParserSettings.SECURE_PROCESSING, true).setParseErrorListener(errorCollector);
    try {
        // this should trigger a SAX parse exception that will blow up at the
        // 64k entity limit rather than OOMing
        aParser.parse(this.getClass().getResourceAsStream("/testcases/rdfxml/openrdf/bad-entity-expansion-limit.rdf"), "http://example.org");
        fail("Parser did not throw an exception");
    } catch (RDFParseException e) {
    // assertTrue(e.getMessage().contains(
    // "The parser has encountered more than \"64,000\" entity expansions in this document; this is the limit imposed by the "));
    }
    assertEquals(0, errorCollector.getWarnings().size());
    assertEquals(0, errorCollector.getErrors().size());
    assertEquals(1, errorCollector.getFatalErrors().size());
}
Also used : StatementCollector(org.eclipse.rdf4j.rio.helpers.StatementCollector) LinkedHashModel(org.eclipse.rdf4j.model.impl.LinkedHashModel) Model(org.eclipse.rdf4j.model.Model) ParseErrorCollector(org.eclipse.rdf4j.rio.helpers.ParseErrorCollector) LinkedHashModel(org.eclipse.rdf4j.model.impl.LinkedHashModel) RDFParser(org.eclipse.rdf4j.rio.RDFParser) RDFParseException(org.eclipse.rdf4j.rio.RDFParseException) Test(org.junit.Test)

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