use of org.intabulas.sandler.exceptions.FeedMarshallException in project jspwiki by apache.
the class AtomAPIServlet method doPost.
/**
* Implements the PostURI of the Atom spec.
* <p>
* Implementation notes:
* <ul>
* <li>Only fetches the first content. All other contents are ignored.
* <li>Assumes that incoming code is plain text or WikiMarkup, not html.
* </ul>
*
* @param request {@inheritDoc}
* @param response {@inheritDoc}
* @throws ServletException {@inheritDoc}
*/
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException {
log.debug("Received POST to AtomAPIServlet");
try {
String blogid = getPageName(request);
WikiPage page = m_engine.getPage(blogid);
if (page == null) {
throw new ServletException("Page " + blogid + " does not exist, cannot add blog post.");
}
// FIXME: Do authentication here
Entry entry = Sandler.unmarshallEntry(request.getInputStream());
//
// Fetch the obligatory parts of the content.
//
Content title = entry.getTitle();
Content content = entry.getContent(0);
Person author = entry.getAuthor();
// FIXME: Sandler 0.5 does not support generator
//
// Generate new blog entry.
//
WeblogEntryPlugin plugin = new WeblogEntryPlugin();
String pageName = plugin.getNewEntryPage(m_engine, blogid);
String username = author.getName();
WikiPage entryPage = new WikiPage(m_engine, pageName);
entryPage.setAuthor(username);
WikiContext context = new WikiContext(m_engine, request, entryPage);
StringBuilder text = new StringBuilder();
text.append("!" + title.getBody());
text.append("\n\n");
text.append(content.getBody());
log.debug("Writing entry: " + text);
m_engine.saveText(context, text.toString());
} catch (FeedMarshallException e) {
log.error("Received faulty Atom entry", e);
throw new ServletException("Faulty Atom entry", e);
} catch (IOException e) {
log.error("I/O exception", e);
throw new ServletException("Could not get body of request", e);
} catch (WikiException e) {
log.error("Provider exception while posting", e);
throw new ServletException("JSPWiki cannot save the entry", e);
}
}
Aggregations