@RequestMapping("/document/{docId}") public void downloadFile(@PathVariable Integer docId, @RequestParam(value="inline", required=false) Boolean inline, HttpServletResponse resp) throws IOException { Document doc = Document.findDocument(docId); File outputFile = new File(Constants.UPLOAD_DIR + "/" + docId); resp.reset(); if (inline == null) { resp.setHeader("Content-Disposition", "attachment; filename=\"" + doc.getFilename() + "\""); } resp.setContentType(doc.getContentType()); resp.setContentLength((int)outputFile.length()); BufferedInputStream in = new BufferedInputStream(new FileInputStream(outputFile)); FileCopyUtils.copy(in, resp.getOutputStream()); resp.flushBuffer(); }
if (base instanceof Document) { Document doc = (Document)base; MimeType mt = doc.getContentType(); type = (mt != null) ? mt.toString() : getMimeType(doc.getRoot()); } else if (base instanceof Element) { Element el = (Element)base; if (el.getDocument() != null) { MimeType mt = el.getDocument().getContentType(); type = (mt != null) ? mt.toString() : null;
if (base instanceof Document) { Document doc = (Document)base; MimeType mt = doc.getContentType(); type = (mt != null) ? mt.toString() : getMimeType(doc.getRoot()); } else if (base instanceof Element) { Element el = (Element)base; if (el.getDocument() != null) { MimeType mt = el.getDocument().getContentType(); type = (mt != null) ? mt.toString() : null;
private static void toJson(Document document, JSONStream jstream) throws IOException { jstream.startObject(); jstream.writeField("base", document.getBaseUri()); jstream.writeField("content-type", document.getContentType()); jstream.writeField("etag", document.getEntityTag()); jstream.writeField("language", document.getLanguage()); jstream.writeField("slug", document.getSlug()); jstream.writeField("last-modified", document.getLastModified()); Element root = document.getRoot(); if (root != null) { String rootname = root.getQName().getLocalPart(); writeElement(rootname, document.getRoot(), jstream); } jstream.endObject(); }