} else {
acceptedTypes = MarmottaHttpUtils.parseAcceptHeader(types);
}
List<ContentType> offeredTypes = MarmottaHttpUtils.parseStringList(exportService.getProducedTypes());
final ContentType bestType = MarmottaHttpUtils.bestContentType(offeredTypes,acceptedTypes);
// create a file name for the export, preferrably with a good extension ...
String fileName;
if(context_string != null) {
String[] components = context_string.split("/");
fileName = components[components.length-1] + "-export-" + DateUtils.FILENAME_FORMAT.format(new Date());
} else {
fileName = "lmf-export-" + DateUtils.FILENAME_FORMAT.format(new Date());
}
if(bestType != null) {
RDFFormat format = Rio.getWriterFormatForMIMEType(bestType.getMime());
if(format != null) {
fileName += "." + format.getDefaultFileExtension();
}
URI context = null;
if(context_string != null) {
try {
RepositoryConnection conn = sesameService.getConnection();
try {
conn.begin();
context = conn.getValueFactory().createURI(context_string);
} finally {
conn.commit();
conn.close();
}
} catch (RepositoryException e) {
handleRepositoryException(e,ExportWebService.class);
}
if(context == null) return Response.status(Response.Status.NOT_FOUND).entity("the context given as argument could not be found").build();
} else {
context = null;
}
final URI fcontext = context;
StreamingOutput entity = new StreamingOutput() {
@Override
public void write(OutputStream output) throws IOException, WebApplicationException {
try {
//FIXME: html should not be exported, but rendered?
exportService.exportData(output,fcontext,bestType.getMime());
} catch (UnsupportedExporterException e) {
throw new WebApplicationException(e, Response.Status.NOT_ACCEPTABLE);
}
}
};
return Response
.status(Response.Status.OK)
.header("Content-Type", bestType.getMime())
.header("Content-Disposition", "attachment; filename=\""+fileName+"\"")
.entity(entity)
.build();
} else