ContentNode node = dir.getChild(id);
if (node == null || !(node instanceof ContentResource)) {
throw new WebApplicationException(Response.Status.NOT_FOUND);
}
final ErrorReport log = read((ContentResource) node);
if (log == null) {
return Response.status(Response.Status.NOT_FOUND)
.entity("No object with id " + id).build();
}
ResponseBuilder out = Response.ok(new StreamingOutput() {
public void write(OutputStream out) throws IOException, WebApplicationException {
PrintStream ps = new PrintStream(out);
ps.println("User: " + log.getCreator());
ps.println("Submitted: " +
SimpleDateFormat.getDateTimeInstance().format(log.getTimeStamp()));
ps.println("Comments:");
ps.println(log.getComments());
ps.println("---------- Error Report ----------");
ps.println(log.getContent());
}
});
if (asAttachment) {
out.header("Content-Disposition",
"attachment; filename=" + log.getId() + ".txt");
}
return out.build();
} catch (ContentRepositoryException ce) {
throw new WebApplicationException(ce, Response.Status.INTERNAL_SERVER_ERROR);