Search in sources :

Example 1 with Person

use of org.intabulas.sandler.elements.Person 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);
    }
}
Also used : ServletException(javax.servlet.ServletException) Entry(org.intabulas.sandler.elements.Entry) WikiContext(org.apache.wiki.WikiContext) WikiException(org.apache.wiki.api.exceptions.WikiException) Content(org.intabulas.sandler.elements.Content) WikiPage(org.apache.wiki.WikiPage) FeedMarshallException(org.intabulas.sandler.exceptions.FeedMarshallException) IOException(java.io.IOException) WeblogEntryPlugin(org.apache.wiki.plugin.WeblogEntryPlugin) Person(org.intabulas.sandler.elements.Person)

Aggregations

IOException (java.io.IOException)1 ServletException (javax.servlet.ServletException)1 WikiContext (org.apache.wiki.WikiContext)1 WikiPage (org.apache.wiki.WikiPage)1 WikiException (org.apache.wiki.api.exceptions.WikiException)1 WeblogEntryPlugin (org.apache.wiki.plugin.WeblogEntryPlugin)1 Content (org.intabulas.sandler.elements.Content)1 Entry (org.intabulas.sandler.elements.Entry)1 Person (org.intabulas.sandler.elements.Person)1 FeedMarshallException (org.intabulas.sandler.exceptions.FeedMarshallException)1