@RequestMapping(method = RequestMethod.GET)
public void serve(@RequestParam("file") String file, @RequestParam(required = false, value = "width") String width, @RequestParam(required = false, value = "height") String height, @RequestParam(required = false, value = "escape") String escape, HttpServletRequest request, HttpServletResponse response) throws IOException {
if (hasText(file)) {
if (decipherer.isEncrypted(file)) {
Document doc = dao.find(Document.class, new UUID(decipherer.decrypt(file)));
response.setContentType(doc.getMimeType());
if (logger.isDebugEnabled()) logger.debug("Setting MIME type [" + doc.getMimeType() + "] to document [" + doc.getId() + "]");
if (doc.isText()) sendText(doc, escape, response);
else send(new ByteArrayInputStream(doc.getContents()), doc.getMimeType(), response.getOutputStream(), width, height);
} else {