Search in sources :

Example 1 with Feed

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

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

the class AtomAPIServlet method listBlogs.

/**
 *  Creates and outputs a full list of all available blogs
 */
private Feed listBlogs() throws ProviderException, IOException {
    Collection pages = m_engine.getPageManager().getAllPages();
    Feed feed = SyndicationFactory.newSyndicationFeed();
    feed.setTitle("List of blogs at this site");
    feed.setModified(new Date());
    for (Iterator i = pages.iterator(); i.hasNext(); ) {
        WikiPage p = (WikiPage) i.next();
        // 
        // List only weblogs
        // FIXME: Unfortunately, a weblog is not known until it has
        // been executed once, because plugins are off during
        // the initial startup phase.
        // 
        log.debug(p.getName() + " = " + p.getAttribute(WeblogPlugin.ATTR_ISWEBLOG));
        if (!("true".equals(p.getAttribute(WeblogPlugin.ATTR_ISWEBLOG))))
            continue;
        String encodedName = TextUtil.urlEncodeUTF8(p.getName());
        WikiContext context = new WikiContext(m_engine, p);
        String title = TextUtil.replaceEntities(org.apache.wiki.rss.Feed.getSiteName(context));
        Link postlink = createLink("service.post", m_engine.getBaseURL() + "atom/" + encodedName, title);
        Link editlink = createLink("service.edit", m_engine.getBaseURL() + "atom/" + encodedName, title);
        Link feedlink = createLink("service.feed", m_engine.getBaseURL() + "atom.jsp?page=" + encodedName, title);
        feed.addLink(postlink);
        feed.addLink(feedlink);
        feed.addLink(editlink);
    }
    return feed;
}
Also used : WikiContext(org.apache.wiki.WikiContext) WikiPage(org.apache.wiki.WikiPage) Iterator(java.util.Iterator) Collection(java.util.Collection) Date(java.util.Date) Link(org.intabulas.sandler.elements.Link) Feed(org.intabulas.sandler.elements.Feed)

Aggregations

Feed (org.intabulas.sandler.elements.Feed)2 IOException (java.io.IOException)1 Collection (java.util.Collection)1 Date (java.util.Date)1 Iterator (java.util.Iterator)1 ServletException (javax.servlet.ServletException)1 WikiContext (org.apache.wiki.WikiContext)1 WikiPage (org.apache.wiki.WikiPage)1 ProviderException (org.apache.wiki.api.exceptions.ProviderException)1 WikiException (org.apache.wiki.api.exceptions.WikiException)1 Entry (org.intabulas.sandler.elements.Entry)1 Link (org.intabulas.sandler.elements.Link)1 FeedMarshallException (org.intabulas.sandler.exceptions.FeedMarshallException)1