@SuppressWarnings("unchecked") public <T extends Base> String getMimeType(T base) { Element element = base instanceof Element ? (Element)base : base instanceof Document ? ((Document)base).getRoot() : null; QName qname = element != null ? element.getQName() : null; return element != null && qname != null ? mimetypes.get(qname) : null; }
@SuppressWarnings("unchecked") private String getCharsetFromBase(Base base) { if (base == null) return null; if (base instanceof Document) { return ((Document)base).getCharset(); } else if (base instanceof Element) { return getCharsetFromBase(((Element)base).getDocument()); } return 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(); }
@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(); }
/** * Return a document */ @SuppressWarnings("unchecked") public static ResponseContext returnBase(Base base, int status, Date lastModified) { log.debug(Localizer.get("RETURNING.DOCUMENT")); BaseResponseContext response = new BaseResponseContext(base); response.setStatus(status); if (lastModified != null) response.setLastModified(lastModified); // response.setContentType(MimeTypeHelper.getMimeType(base)); Document doc = base instanceof Document ? (Document)base : ((Element)base).getDocument(); if (doc.getEntityTag() != null) { response.setEntityTag(doc.getEntityTag()); } else if (doc.getLastModified() != null) { response.setLastModified(doc.getLastModified()); } return response; }
/** * Retrieves the FOM Entry object from the request payload. */ @SuppressWarnings("unchecked") protected Entry getEntryFromRequest(RequestContext request) throws ResponseContextException { Abdera abdera = request.getAbdera(); Parser parser = abdera.getParser(); Document<Entry> entry_doc; try { entry_doc = (Document<Entry>)request.getDocument(parser).clone(); } catch (ParseException e) { throw new ResponseContextException(400, e); } catch (IOException e) { throw new ResponseContextException(500, e); } if (entry_doc == null) { return null; } return entry_doc.getRoot(); }
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;
response.setContentType("application/json"); response.setCharacterEncoding("UTF-8"); if (doc.getEntityTag() != null) response.setHeader("ETag", doc.getEntityTag().toString()); if (doc.getLanguage() != null) response.setHeader("Content-Language", doc.getLanguage()); if (doc.getLastModified() != null) response.setDateHeader("Last-Modified", doc.getLastModified().getTime()); OutputStream out = response.getOutputStream(); doc.writeTo("json", out); } catch (Exception e) { response.sendError(500);
@SuppressWarnings("unchecked") public void writeTo(Base base, OutputStream out, WriterOptions options) throws IOException { out = getCompressedOutputStream(out, options); String charset = options.getCharset(); if (charset == null) { if (base instanceof Document) charset = ((Document)base).getCharset(); else if (base instanceof Element) { Document doc = ((Element)base).getDocument(); if (doc != null) charset = doc.getCharset(); } if (charset == null) charset = "UTF-8"; } else { Document doc = null; if (base instanceof Document) doc = (Document)base; else if (base instanceof Element) doc = ((Element)base).getDocument(); if (doc != null) doc.setCharset(charset); } base.writeTo(new OutputStreamWriter(out, charset)); finishCompressedOutputStream(out, options); if (options.getAutoClose()) out.close(); }
/** * Sends an HTTP PUT request to the specified URI. * * @param uri The request URI * @param base A FOM Document or Element providing the payload of the request * @param options The request options */ public ClientResponse put(String uri, Base base, RequestOptions options) { if (options == null) options = getDefaultRequestOptions(); if (base instanceof Document) { Document d = (Document)base; if (options.getSlug() == null && d.getSlug() != null) options.setSlug(d.getSlug()); if (options.isConditionalPut()) { if (d.getEntityTag() != null) options.setIfMatch(d.getEntityTag()); else if (d.getLastModified() != null) options.setIfUnmodifiedSince(d.getLastModified()); } } return execute("PUT", uri, new BaseRequestEntity(base, options.isUseChunked()), options); }
public StreamBuilder startDocument(String xmlversion, String charset) { if (root != null) throw new IllegalStateException("Document already started"); root = abdera.getFactory().newDocument(); ((Document)root).setCharset(charset); current = root; return this; }
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;
public StreamBuilder startDocument(String xmlversion, String charset) { if (root != null) throw new IllegalStateException("Document already started"); root = abdera.getFactory().newDocument(); ((Document)root).setCharset(charset); current = root; return this; }
@SuppressWarnings("unchecked") public <T extends Base> String getMimeType(T base) { Element element = base instanceof Element ? (Element)base : base instanceof Document ? ((Document)base).getRoot() : null; QName qname = element != null ? element.getQName() : null; return element != null && qname != null ? mimetypes.get(qname) : null; }
.getDocument(parser).clone(); if (entry_doc != null) { Entry entry = entry_doc.getRoot(); if (!entry.getId().equals(orig_entry.getId())) { return new EmptyResponseContext(409); "edit"); orig_entry.discard(); Feed feed = get_feed_doc(abdera).getRoot(); feed.insertEntry(entry); feed.setUpdated(new Date());
/** * Sets the content for this entry */ public Content setContent(InputStream in, String mediatype) { if (MimeTypeHelper.isText(mediatype)) { try { StringBuilder buf = new StringBuilder(); String charset = MimeTypeHelper.getCharset(mediatype); Document doc = this.getDocument(); charset = charset != null ? charset : doc != null ? doc.getCharset() : null; charset = charset != null ? charset : "UTF-8"; InputStreamReader isr = new InputStreamReader(in, charset); char[] data = new char[500]; int r = -1; while ((r = isr.read(data)) != -1) { buf.append(data, 0, r); } return setContent(buf.toString(), mediatype); } catch (IOException e) { throw new RuntimeException(e); } } else { InputStreamDataSource ds = new InputStreamDataSource(in, mediatype); DataHandler dh = new DataHandler(ds); return setContent(dh, mediatype); } }
private Response makeRepositoryInfoResponse(HttpServletRequest httpRequest, URI baseUri, String repositoryId) { Service service = AbderaFactory.getInstance().getFactory().newService(); service.declareNS(AtomCMIS.CMIS_NS_URI, AtomCMIS.CMIS_PREFIX); service.declareNS(AtomCMIS.CMISRA_NS_URI, AtomCMIS.CMISRA_PREFIX); addCmisRepository(httpRequest, service, repositoryId, baseUri); Document<Service> serviceDocument = service.getDocument(); serviceDocument.setCharset("utf-8"); ResponseContext abderaResponse = new BaseResponseContext<Document<Service>>(serviceDocument); abderaResponse.setStatus(200); return Response.ok(abderaResponse).header(HttpHeaders.CACHE_CONTROL, "no-cache") .type(MediaType.APPLICATION_ATOM_XML).build(); }
public boolean isEncrypted(Document doc) throws SecurityException { Element el = doc.getRoot(); return el.getQName().equals(Constants.ENCRYPTEDDATA); }