/** * {@inheritDoc} */ @Override protected ResponseContext buildGetEntryResponse(RequestContext request, Entry entry) throws ResponseContextException { // The same as in super class but without ETag. Document<Entry> doc = entry.getDocument(); ResponseContext rc = new BaseResponseContext<Document<Entry>>(doc); // rc.setEntityTag(ProviderHelper.calculateEntityTag(entry)); return rc; }
public ResponseContext getEntry(RequestContext request) { Target target = request.getTarget(); String entryId = target.getParameter(BasicProvider.PARAM_ENTRY); try { Entry entry = getEntry(entryId); return entry != null ? ProviderHelper.returnBase(entry.getDocument(), 200, null) : ProviderHelper .notfound(request); } catch (Exception e) { return ProviderHelper.servererror(request, e.getMessage(), e); } }
@Override public ResponseContext getEntry(final RequestContext request) { final Target target = request.getTarget(); final String key = target.getParameter("entry"); final File file = this.getFile(key, false); final Entry entry = this.getEntry(file); if (entry != null) { return ProviderHelper.returnBase(entry.getDocument(), 200, null); } else { return ProviderHelper.notfound(request); } }
public ResponseContext getEntry(RequestContext request) { Target target = request.getTarget(); String key = target.getParameter("entry"); File file = getFile(key, false); Entry entry = getEntry(file); if (entry != null) return ProviderHelper.returnBase(entry.getDocument(), 200, null); else return ProviderHelper.notfound(request); }
/** * Creates the ResponseContext for a GET entry request. By default, a BaseResponseContext is returned. The Entry * will contain an appropriate atom:source element and the Etag header will be set. */ protected ResponseContext buildGetEntryResponse(RequestContext request, Entry entry) throws ResponseContextException { Feed feed = createFeedBase(request); entry.setSource(feed.getAsSource()); Document<Entry> entry_doc = entry.getDocument(); AbstractResponseContext rc = new BaseResponseContext<Document<Entry>>(entry_doc); rc.setEntityTag(calculateEntityTag(entry)); return rc; }
/** * {@inheritDoc} */ protected ResponseContext buildCreateEntryResponse(String link, Entry entry) { Document<Entry> doc = entry.getDocument(); ResponseContext rc = new BaseResponseContext<Document<Entry>>(doc); rc.setLocation(link); rc.setContentLocation(rc.getLocation().toString()); // rc.setEntityTag(ProviderHelper.calculateEntityTag(entry)); rc.setStatus(201); return rc; }
static public Entry createBaseEntry(String author, String title, String linkUrl) { Factory factory = getFactory(); Entry entry = factory.newEntry(); String id = FOMHelper.generateUuid(); entry.setId(id); entry.setUpdated(new Date()); entry.setPublished(new Date()); entry.addAuthor(author); entry.setTitle(title); entry.addLink(linkUrl); // entry.addLink("","self"); // Can have content, as below or not to be a valid entry. // entry.setContentAsXhtml( // "<p>This can go in an atom feed, I think... Will have to try to a blogger account...</p>"); Document<Entry> doc = entry.getDocument(); // We don't (currently) support SLUG String slug = "Suggested-reference-which-we-will-probably-ignore"; doc.setSlug(slug); return entry; }
/** * Implements GET on an ENTRY */ public ResponseContext getEntry(RequestContext request) { Entry entry; String entryId = getEntryID(request); try { entry = getEntryInternal(request, entryId); Document<Entry> entryDoc = entry.getDocument(); AbstractResponseContext rc = new BaseResponseContext<Document<Entry>>(entryDoc); rc.setEntityTag(calculateEntityTag(entry)); return rc; } catch (NotFoundException e) { return makeExceptionResponse(HttpServletResponse.SC_NOT_FOUND, "No entry for id " + entryId); } catch (BadRequestException e) { return makeExceptionResponse(HttpServletResponse.SC_BAD_REQUEST, e); } }
public ResponseContext getEntry(RequestContext request) { Entry entry = getAbderaEntry(request); if (entry != null) { Feed feed = entry.getParentElement(); entry = (Entry) entry.clone(); entry.setSource(feed.getAsSource()); Document<Entry> entry_doc = entry.getDocument(); AbstractResponseContext rc = new BaseResponseContext<Document<Entry>>( entry_doc); rc.setEntityTag(calculateEntityTag(entry)); return rc; } else { return new EmptyResponseContext(404); } }
public ResponseContext postEntry(RequestContext request) { if (request.isAtom()) { try { Entry entry = (Entry)request.getDocument().getRoot().clone(); String key = createKey(request); setEditDetail(request, entry, key); File file = getFile(key); FileOutputStream out = new FileOutputStream(file); entry.writeTo(out); String edit = entry.getEditLinkResolvedHref().toString(); return ProviderHelper.returnBase(entry.getDocument(), 201, null).setLocation(edit); } catch (Exception e) { return ProviderHelper.badrequest(request); } } else { return ProviderHelper.notsupported(request); } }
@Override public ResponseContext putEntry(final RequestContext request) { if (request.isAtom()) { try { final Entry entry = (Entry) request.getDocument().getRoot() .clone(); final String key = request.getTarget().getParameter("entry"); this.setEditDetail(request, entry, key); final File file = this.getFile(key, false); final FileOutputStream out = new FileOutputStream(file); entry.writeTo(out); final String edit = entry.getEditLinkResolvedHref().toString(); return ProviderHelper .returnBase(entry.getDocument(), 200, null) .setLocation(edit); } catch (final Exception e) { return ProviderHelper.badrequest(request); } } else { return ProviderHelper.notsupported(request); } }
public ResponseContext putEntry(RequestContext request) { if (request.isAtom()) { try { Entry entry = (Entry)request.getDocument().getRoot().clone(); String key = request.getTarget().getParameter("entry"); setEditDetail(request, entry, key); File file = getFile(key, false); FileOutputStream out = new FileOutputStream(file); entry.writeTo(out); String edit = entry.getEditLinkResolvedHref().toString(); return ProviderHelper.returnBase(entry.getDocument(), 200, null).setLocation(edit); } catch (Exception e) { return ProviderHelper.badrequest(request); } } else { return ProviderHelper.notsupported(request); } }
@Override public ResponseContext postEntry(final RequestContext request) { if (request.isAtom()) { try { final Entry entry = (Entry) request.getDocument().getRoot() .clone(); final String key = this.createKey(request); this.setEditDetail(request, entry, key); final File file = this.getFile(key); final FileOutputStream out = new FileOutputStream(file); entry.writeTo(out); final String edit = entry.getEditLinkResolvedHref().toString(); return ProviderHelper .returnBase(entry.getDocument(), 201, null) .setLocation(edit); } catch (final Exception e) { return ProviderHelper.badrequest(request); } } else { return ProviderHelper.notsupported(request); } }
private ResponseContext createOrUpdateEntry(RequestContext request, boolean createFlag) { try { MimeType mimeType = request.getContentType(); String contentType = mimeType == null ? null : mimeType.toString(); if (contentType != null && !MimeTypeHelper.isAtom(contentType) && !MimeTypeHelper.isXml(contentType)) return ProviderHelper.notsupported(request); Abdera abdera = request.getAbdera(); Parser parser = abdera.getParser(); Entry inputEntry = (Entry)request.getDocument(parser).getRoot(); Target target = request.getTarget(); String entryId = !createFlag ? target.getParameter(BasicProvider.PARAM_ENTRY) : null; Entry newEntry = createFlag ? createEntry(inputEntry) : updateEntry(entryId, inputEntry); if (newEntry != null) { Document<Entry> newEntryDoc = newEntry.getDocument(); String loc = newEntry.getEditLinkResolvedHref().toString(); return ProviderHelper.returnBase(newEntryDoc, createFlag ? 201 : 200, null).setLocation(loc); } else { return ProviderHelper.notfound(request); } } catch (Exception e) { return ProviderHelper.servererror(request, e.getMessage(), e); } }