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