if (r == null || !ResourceUtils.isUsed(conn, r)) {
return ResourceWebServiceHelper.buildErrorPage(resource, configurationService.getBaseUri(), Response.Status.NOT_FOUND, "the requested resource could not be found in LMF right now, but may be available again in the future", configurationService, templatingService);
}
// create parser
final RDFFormat serializer = kiWiIOService.getSerializer(mimetype);
if (serializer == null) {
Response response = Response.status(406).entity("mimetype can not be processed").build();
ResourceWebServiceHelper.addHeader(response, "Content-Type", ResourceWebServiceHelper.appendMetaTypes(kiWiIOService.getProducedTypes()));
return response;
}
if(r != null) {
final Resource subject = r;
StreamingOutput entity = new StreamingOutput() {
@Override
public void write(OutputStream output) throws IOException, WebApplicationException {
// FIXME: This method is executed AFTER the @Transactional!
RDFWriter writer = Rio.createWriter(serializer,output);
try {
RepositoryConnection connection = sesameService.getConnection();
try {
connection.begin();
connection.exportStatements(subject,null,null,true,writer);
} finally {
connection.commit();
connection.close();
}
} catch (RepositoryException e) {
throw new WebApplicationException(e, Status.INTERNAL_SERVER_ERROR);
} catch (RDFHandlerException e) {
throw new IOException("error while writing RDF data to stream", e);
}
}
};
// build response
Response response = Response.ok(entity).lastModified(KiWiSesameUtil.lastModified(r, conn)).build();
response.getMetadata().add("ETag", "W/\"" + ETagGenerator.getWeakETag(conn, r) + "\"");
if (!mimetype.contains("html")) { // then create a proper filename
String[] components;
if (resource.contains("#")) {
components = resource.split("#");
} else {
components = resource.split("/");
}
final String fileName = components[components.length-1] + "." + serializer.getDefaultFileExtension();
response.getMetadata().add("Content-Disposition", "attachment; filename=\""+fileName+"\"");
}
// create the Content-Type header for the response
if (mimetype.startsWith("text/") || mimetype.startsWith("application/")) {