Search in sources :

Example 1 with RDFHandlerException

use of org.openrdf.rio.RDFHandlerException in project qi4j-sdk by Qi4j.

the class EntityResource method representRdfXml.

private Representation representRdfXml(final EntityState entity) throws ResourceException {
    Representation representation = new WriterRepresentation(MediaType.APPLICATION_RDF_XML) {

        @Override
        public void write(Writer writer) throws IOException {
            try {
                Iterable<Statement> statements = entitySerializer.serialize(entity);
                new RdfXmlSerializer().serialize(statements, writer);
            } catch (RDFHandlerException e) {
                throw new IOException(e);
            }
        }
    };
    representation.setCharacterSet(CharacterSet.UTF_8);
    return representation;
}
Also used : RDFHandlerException(org.openrdf.rio.RDFHandlerException) WriterRepresentation(org.restlet.representation.WriterRepresentation) Statement(org.openrdf.model.Statement) RdfXmlSerializer(org.qi4j.library.rdf.serializer.RdfXmlSerializer) EmptyRepresentation(org.restlet.representation.EmptyRepresentation) StringRepresentation(org.restlet.representation.StringRepresentation) WriterRepresentation(org.restlet.representation.WriterRepresentation) Representation(org.restlet.representation.Representation) IOException(java.io.IOException) PrintWriter(java.io.PrintWriter) Writer(java.io.Writer)

Example 2 with RDFHandlerException

use of org.openrdf.rio.RDFHandlerException in project gocd by gocd.

the class SesameGraph method dumpTriplesNotInContext.

private void dumpTriplesNotInContext(Writer writer) {
    try {
        writer.append("Statements not in any context: \n");
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
    RDFXMLWriter xmlWriter = new RDFXMLWriter(writer);
    xmlWriter.startRDF();
    try {
        RepositoryResult<Statement> result = conn.getStatements(null, null, null, false);
        while (result.hasNext()) {
            Statement statement = result.next();
            if (statement.getContext() == null) {
                xmlWriter.handleStatement(statement);
            }
        }
    } catch (RepositoryException | RDFHandlerException e) {
        throw new RuntimeException(e);
    } finally {
        try {
            xmlWriter.endRDF();
        } catch (RDFHandlerException e) {
            throw new RuntimeException(e);
        }
    }
}
Also used : ShineRuntimeException(com.thoughtworks.studios.shine.ShineRuntimeException) RDFHandlerException(org.openrdf.rio.RDFHandlerException) RDFXMLWriter(org.openrdf.rio.rdfxml.RDFXMLWriter) Statement(org.openrdf.model.Statement) RepositoryException(org.openrdf.repository.RepositoryException) IOException(java.io.IOException)

Aggregations

IOException (java.io.IOException)2 Statement (org.openrdf.model.Statement)2 RDFHandlerException (org.openrdf.rio.RDFHandlerException)2 ShineRuntimeException (com.thoughtworks.studios.shine.ShineRuntimeException)1 PrintWriter (java.io.PrintWriter)1 Writer (java.io.Writer)1 RepositoryException (org.openrdf.repository.RepositoryException)1 RDFXMLWriter (org.openrdf.rio.rdfxml.RDFXMLWriter)1 RdfXmlSerializer (org.qi4j.library.rdf.serializer.RdfXmlSerializer)1 EmptyRepresentation (org.restlet.representation.EmptyRepresentation)1 Representation (org.restlet.representation.Representation)1 StringRepresentation (org.restlet.representation.StringRepresentation)1 WriterRepresentation (org.restlet.representation.WriterRepresentation)1