conn.begin();
// FIXME String appendix = uuid == null ? "?uri=" + URLEncoder.encode(uri, "utf-8") :
// "/" + uuid;
URI resource = conn.getValueFactory().createURI(uri);
// 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(resource != null) {
final Resource subject = resource;
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(resource, conn)).build();
response.getMetadata().add("ETag", "W/\"" + ETagGenerator.getWeakETag(conn, resource) + "\"");
if (!mimetype.contains("html")) { // then create a proper filename
String[] components;
if (uri.contains("#")) {
components = uri.split("#");
} else {
components = uri.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/")) {