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