Search in sources :

Example 1 with Entry

use of org.intabulas.sandler.elements.Entry in project jspwiki by apache.

the class AtomAPIServlet method doGet.

/**
 *  Handles HTTP GET.  However, we do not respond to GET requests,
 *  other than to show an explanatory text.
 *
 *  {@inheritDoc}
 */
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException {
    log.debug("Received HTTP GET to AtomAPIServlet");
    String blogid = getPageName(request);
    log.debug("Requested page " + blogid);
    try {
        if (blogid == null) {
            Feed feed = listBlogs();
            response.setContentType("application/x.atom+xml; charset=UTF-8");
            response.getWriter().println(Sandler.marshallFeed(feed));
            response.getWriter().flush();
        } else {
            Entry entry = getBlogEntry(blogid);
            response.setContentType("application/x.atom+xml; charset=UTF-8");
            response.getWriter().println(Sandler.marshallEntry(entry));
            response.getWriter().flush();
        }
    } catch (Exception e) {
        log.error("Unable to generate response", e);
        throw new ServletException("Internal problem - whack Janne on the head to get a better error report", e);
    }
}
Also used : ServletException(javax.servlet.ServletException) Entry(org.intabulas.sandler.elements.Entry) ServletException(javax.servlet.ServletException) FeedMarshallException(org.intabulas.sandler.exceptions.FeedMarshallException) WikiException(org.apache.wiki.api.exceptions.WikiException) IOException(java.io.IOException) ProviderException(org.apache.wiki.api.exceptions.ProviderException) Feed(org.intabulas.sandler.elements.Feed)

Example 2 with Entry

use of org.intabulas.sandler.elements.Entry 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)

Example 3 with Entry

use of org.intabulas.sandler.elements.Entry in project jspwiki by apache.

the class AtomAPIServlet method getBlogEntry.

private Entry getBlogEntry(String entryid) throws ProviderException {
    WikiPage page = m_engine.getPage(entryid);
    WikiPage firstVersion = m_engine.getPage(entryid, 1);
    Entry entry = SyndicationFactory.newSyndicationEntry();
    String pageText = m_engine.getText(page.getName());
    String title = "";
    int firstLine = pageText.indexOf('\n');
    if (firstLine > 0) {
        title = pageText.substring(0, firstLine);
    }
    if (title.trim().length() == 0)
        title = page.getName();
    // Remove wiki formatting
    while (title.startsWith("!")) title = title.substring(1);
    entry.setTitle(title);
    entry.setCreated(firstVersion.getLastModified());
    entry.setModified(page.getLastModified());
    entry.setAuthor(SyndicationFactory.createPerson(page.getAuthor(), null, null));
    entry.addContent(SyndicationFactory.createEscapedContent(pageText));
    return entry;
}
Also used : Entry(org.intabulas.sandler.elements.Entry) WikiPage(org.apache.wiki.WikiPage)

Aggregations

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