Search in sources :

Example 1 with RDFParserRegistry

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

the class RDFConsumer method readFrom.

@Override
public Model readFrom(final Class<Model> t, final Type type, final Annotation[] annts, final MediaType mt, final MultivaluedMap<String, String> mm, final InputStream in) throws IOException, WebApplicationException {
    RDFParserRegistry registry = RDFParserRegistry.getInstance();
    Optional<RDFFormat> format = registry.getFileFormatForMIMEType(mt.toString());
    if (!format.isPresent()) {
        String msg = "Can not consume RDF of mimetype + " + mt.toString();
        Response response = Response.status(Response.Status.BAD_REQUEST).type(MediaType.TEXT_PLAIN).entity(msg).build();
        throw new WebApplicationException(response);
    }
    Model input = Rio.parse(in, TURTLE_BASE_URI, format.get());
    return AgentUtil.setMessageInformation(input, mm);
}
Also used : Response(javax.ws.rs.core.Response) WebApplicationException(javax.ws.rs.WebApplicationException) Model(org.eclipse.rdf4j.model.Model) RDFParserRegistry(org.eclipse.rdf4j.rio.RDFParserRegistry) RDFFormat(org.eclipse.rdf4j.rio.RDFFormat)

Example 2 with RDFParserRegistry

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

the class MAJANServiceHandler method getRDFFormat.

private RDFFormat getRDFFormat(String contentType) {
    RDFParserRegistry registry = RDFParserRegistry.getInstance();
    Optional<RDFFormat> format = registry.getFileFormatForMIMEType(contentType);
    if (!format.isPresent()) {
        return null;
    }
    return format.get();
}
Also used : RDFParserRegistry(org.eclipse.rdf4j.rio.RDFParserRegistry) RDFFormat(org.eclipse.rdf4j.rio.RDFFormat)

Example 3 with RDFParserRegistry

use of org.eclipse.rdf4j.rio.RDFParserRegistry 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)3 RDFParserRegistry (org.eclipse.rdf4j.rio.RDFParserRegistry)3 Model (org.eclipse.rdf4j.model.Model)2 WebApplicationException (javax.ws.rs.WebApplicationException)1 Response (javax.ws.rs.core.Response)1