use of org.eclipse.rdf4j.rio.RDFParseException in project rdf4j by eclipse.
the class HTTPRepositoryConnection method removeModel.
private void removeModel(Model m) throws RepositoryException {
RDFFormat format = RDFFormat.BINARY;
try {
ByteArrayOutputStream out = new ByteArrayOutputStream();
Rio.write(m, out, format);
ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
client.removeData(in, null, format);
} catch (RDFHandlerException e) {
throw new RepositoryException("error while writing statement", e);
} catch (RDFParseException e) {
throw new RepositoryException(e);
} catch (IOException e) {
throw new RepositoryException(e);
}
}
use of org.eclipse.rdf4j.rio.RDFParseException in project rdf4j by eclipse.
the class SAXFilter method characters.
@Override
public void characters(char[] ch, int start, int length) throws SAXException {
try {
if (inRDFContext) {
// verify if we need to switch to XMLLiteral processing mode immediately.
if (deferredElement != null && !parseLiteralMode) {
Att parseType = deferredElement.atts.getAtt(RDF.NAMESPACE, "parseType");
if (parseType != null && parseType.getValue().equals("Literal")) {
setParseLiteralMode();
}
}
if (parseLiteralMode) {
if (deferredElement != null) {
reportDeferredStartElement();
}
// Characters like '<', '>', and '&' must be escaped to
// prevent breaking the XML text.
String s = new String(ch, start, length);
s = XMLUtil.escapeCharacterData(s);
charBuf.append(s);
} else {
charBuf.append(ch, start, length);
// we keep the start element deferred for now.
if (deferredElement != null && charBuf.toString().trim().length() > 0) {
reportDeferredStartElement();
}
}
}
} catch (RDFParseException e) {
throw new SAXException(e);
} catch (RDFHandlerException e) {
throw new SAXException(e);
}
}
use of org.eclipse.rdf4j.rio.RDFParseException in project rdf4j by eclipse.
the class RDFXMLParserTest method testFatalErrorPrologContent.
@Test
public void testFatalErrorPrologContent() throws Exception {
// Temporarily override System.err to verify that nothing is being
// printed to it for this test
PrintStream oldErr = System.err;
ByteArrayOutputStream tempErr = new ByteArrayOutputStream();
System.setErr(new PrintStream(tempErr));
PrintStream oldOut = System.out;
ByteArrayOutputStream tempOut = new ByteArrayOutputStream();
System.setOut(new PrintStream(tempOut));
try (final InputStream in = this.getClass().getResourceAsStream("/org/eclipse/rdf4j/rio/rdfxml/not-an-rdfxml-file.rdf")) {
parser.parse(in, "");
} catch (RDFParseException e) {
assertEquals("Content is not allowed in prolog. [line 1, column 1]", e.getMessage());
} finally {
// Reset System Error output to ensure that we don't interfere with
// other tests
System.setErr(oldErr);
// Reset System Out output to ensure that we don't interfere with
// other tests
System.setOut(oldOut);
}
// Verify nothing was printed to System.err during test
assertEquals(0, tempErr.size());
// Verify nothing was printed to System.out during test
assertEquals(0, tempOut.size());
assertEquals(0, el.getWarnings().size());
assertEquals(0, el.getErrors().size());
assertEquals(1, el.getFatalErrors().size());
assertEquals("[Rio fatal] Content is not allowed in prolog. (1, 1)", el.getFatalErrors().get(0));
}
use of org.eclipse.rdf4j.rio.RDFParseException in project rdf4j by eclipse.
the class JSONLDParser method parse.
@Override
public void parse(final InputStream in, final String baseURI) throws IOException, RDFParseException, RDFHandlerException {
clear();
try {
final JSONLDInternalTripleCallback callback = new JSONLDInternalTripleCallback(getRDFHandler(), valueFactory, getParserConfig(), getParseErrorListener(), nodeID -> createNode(nodeID), () -> createNode());
final JsonLdOptions options = new JsonLdOptions(baseURI);
options.useNamespaces = true;
JsonLdProcessor.toRDF(JsonUtils.fromInputStream(in), callback, options);
} catch (final JsonLdError e) {
throw new RDFParseException("Could not parse JSONLD", e);
} catch (final JsonParseException e) {
throw new RDFParseException("Could not parse JSONLD", e);
} catch (final RuntimeException e) {
if (e.getCause() != null && e.getCause() instanceof RDFParseException) {
throw (RDFParseException) e.getCause();
}
throw e;
} finally {
clear();
}
}
use of org.eclipse.rdf4j.rio.RDFParseException in project rdf4j by eclipse.
the class JSONLDParser method parse.
@Override
public void parse(final Reader reader, final String baseURI) throws IOException, RDFParseException, RDFHandlerException {
clear();
try {
final JSONLDInternalTripleCallback callback = new JSONLDInternalTripleCallback(getRDFHandler(), valueFactory, getParserConfig(), getParseErrorListener(), nodeID -> createNode(nodeID), () -> createNode());
final JsonLdOptions options = new JsonLdOptions(baseURI);
options.useNamespaces = true;
JsonLdProcessor.toRDF(JsonUtils.fromReader(reader), callback, options);
} catch (final JsonLdError e) {
throw new RDFParseException("Could not parse JSONLD", e);
} catch (final JsonParseException e) {
throw new RDFParseException("Could not parse JSONLD", e);
} catch (final RuntimeException e) {
if (e.getCause() != null && e.getCause() instanceof RDFParseException) {
throw (RDFParseException) e.getCause();
}
throw e;
} finally {
clear();
}
}
Aggregations