Parser parser = abdera.getParser();
try {
MimeType contentType = request.getContentType();
String ctype = (contentType != null) ? contentType.toString() : null;
if (ctype != null && !MimeTypeHelper.isAtom(ctype) && !MimeTypeHelper.isXml(ctype))
return new EmptyResponseContext(415);
Document<Entry> entry_doc =
(Document<Entry>) request.getDocument(parser).clone();
if (entry_doc != null) {
Entry entry = entry_doc.getRoot();
if (!isValidEntry(entry))
return new EmptyResponseContext(400);
entry.setUpdated(new Date());
entry.getIdElement().setValue(factory.newUuidUri());
entry.addLink("feed/" + entry.getId().toString(), "edit");
Feed feed = get_feed_doc(abdera).getRoot();
feed.insertEntry(entry);
feed.setUpdated(new Date());
BaseResponseContext rc = new BaseResponseContext(entry);
IRI baseUri = resolveBase(request);
rc.setLocation(baseUri.resolve(entry.getEditLinkResolvedHref()).toString());
rc.setContentLocation(rc.getLocation().toString());
rc.setEntityTag(calculateEntityTag(entry));
rc.setStatus(201);
return rc;
} else {
return new EmptyResponseContext(400);
}
} catch (ParseException pe) {
return new EmptyResponseContext(415);
} catch (ClassCastException cce) {
return new EmptyResponseContext(415);
} catch (Exception e) {
return new EmptyResponseContext(400);
}
}