Search in sources :

Example 61 with RDFFormat

use of org.eclipse.rdf4j.rio.RDFFormat in project AJAN-service by aantakli.

the class ModelProducer method writeModel.

public void writeModel(final Model t, final MediaType mt, final OutputStream output) {
    Optional<RDFFormat> format = getFormatForMediaType(mt);
    if (!format.isPresent()) {
        String msg = "Can not produce RDF as mimetype + " + mt.toString();
        Response response = Response.status(Status.BAD_REQUEST).type(MediaType.TEXT_PLAIN).entity(msg).build();
        throw new WebApplicationException(response);
    }
    RDFWriter writer = Rio.createWriter(format.get(), output);
    writer.getWriterConfig().set(BasicWriterSettings.PRETTY_PRINT, true);
    try {
        writer.startRDF();
        for (Statement stm : t) {
            writer.handleNamespace("ajan", "http://www.ajan.de/ajan-ns#");
            writer.handleNamespace("bt", "http://www.ajan.de/behavior/bt-ns#");
            writer.handleNamespace("xsd", "http://www.w3.org/2001/XMLSchema#");
            writer.handleNamespace("actn", "http://www.ajan.de/actn#");
            writer.handleNamespace("rdfs", "http://www.w3.org/2000/01/rdf-schema#");
            writer.handleNamespace("rdf", "http://www.w3.org/1999/02/22-rdf-syntax-ns#");
            writer.handleStatement(stm);
        }
        writer.endRDF();
    } catch (RDFHandlerException ex) {
        Response response = Response.status(Status.INTERNAL_SERVER_ERROR).type(MediaType.TEXT_PLAIN).entity(ex.getMessage()).build();
        throw new WebApplicationException(ex, response);
    }
}
Also used : Response(javax.ws.rs.core.Response) WebApplicationException(javax.ws.rs.WebApplicationException) RDFHandlerException(org.eclipse.rdf4j.rio.RDFHandlerException) Statement(org.eclipse.rdf4j.model.Statement) RDFWriter(org.eclipse.rdf4j.rio.RDFWriter) RDFFormat(org.eclipse.rdf4j.rio.RDFFormat)

Example 62 with RDFFormat

use of org.eclipse.rdf4j.rio.RDFFormat in project AJAN-service by aantakli.

the class RDFConsumer method isReadable.

@Override
public boolean isReadable(final Class<?> type, final Type type1, final Annotation[] antns, final MediaType mt) {
    if (!type.isAssignableFrom(Model.class)) {
        return false;
    }
    RDFParserRegistry registry = RDFParserRegistry.getInstance();
    Optional<RDFFormat> format = registry.getFileFormatForMIMEType(mt.toString());
    return format.isPresent();
}
Also used : Model(org.eclipse.rdf4j.model.Model) RDFParserRegistry(org.eclipse.rdf4j.rio.RDFParserRegistry) RDFFormat(org.eclipse.rdf4j.rio.RDFFormat)

Aggregations

RDFFormat (org.eclipse.rdf4j.rio.RDFFormat)62 ByteArrayOutputStream (java.io.ByteArrayOutputStream)17 IOException (java.io.IOException)17 WriteRdf4j (mom.trd.opentheso.core.exports.rdf4j.WriteRdf4j)14 InputStream (java.io.InputStream)12 RDFParseException (org.eclipse.rdf4j.rio.RDFParseException)11 RepositoryException (org.eclipse.rdf4j.repository.RepositoryException)8 FileInputStream (java.io.FileInputStream)7 Model (org.eclipse.rdf4j.model.Model)6 RDFHandlerException (org.eclipse.rdf4j.rio.RDFHandlerException)6 RDFParser (org.eclipse.rdf4j.rio.RDFParser)5 UnsupportedRDFormatException (org.eclipse.rdf4j.rio.UnsupportedRDFormatException)5 Rdf2GoCore (de.knowwe.rdf2go.Rdf2GoCore)4 ByteArrayInputStream (java.io.ByteArrayInputStream)4 File (java.io.File)4 NodePreference (mom.trd.opentheso.bdd.helper.nodes.NodePreference)4 ExportRdf4jHelper (mom.trd.opentheso.core.exports.rdf4j.ExportRdf4jHelper)4 IRI (org.eclipse.rdf4j.model.IRI)4 Statement (org.eclipse.rdf4j.model.Statement)4 Test (org.junit.Test)4