Search in sources :

Example 1 with WeblogPlugin

use of org.apache.wiki.plugin.WeblogPlugin in project jspwiki by apache.

the class MetaWeblogHandler method getRecentPosts.

/**
 *  Returns a list of the recent posts to this weblog.
 *
 *  @param blogid The id of the blog.
 *  @param username The username to use
 *  @param password The password
 *  @param numberOfPosts How many posts to find
 *  @throws XmlRpcException If something goes wrong
 *  @return As per MetaweblogAPI specification
 */
// FIXME: The implementation is suboptimal, as it
// goes through all of the blog entries.
@SuppressWarnings("unchecked")
public Hashtable getRecentPosts(String blogid, String username, String password, int numberOfPosts) throws XmlRpcException {
    Hashtable<String, Hashtable<String, Object>> result = new Hashtable<String, Hashtable<String, Object>>();
    log.info("metaWeblog.getRecentPosts() called");
    WikiPage page = m_context.getEngine().getPage(blogid);
    checkPermissions(page, username, password, "view");
    try {
        WeblogPlugin plugin = new WeblogPlugin();
        List<WikiPage> changed = plugin.findBlogEntries(m_context.getEngine(), blogid, new Date(0L), new Date());
        Collections.sort(changed, new PageTimeComparator());
        int items = 0;
        for (Iterator<WikiPage> i = changed.iterator(); i.hasNext() && items < numberOfPosts; items++) {
            WikiPage p = i.next();
            result.put("entry", makeEntry(p));
        }
    } catch (ProviderException e) {
        log.error("Failed to list recent posts", e);
        throw new XmlRpcException(0, e.getMessage());
    }
    return result;
}
Also used : WeblogPlugin(org.apache.wiki.plugin.WeblogPlugin) ProviderException(org.apache.wiki.api.exceptions.ProviderException) Hashtable(java.util.Hashtable) WikiPage(org.apache.wiki.WikiPage) Date(java.util.Date) PageTimeComparator(org.apache.wiki.util.comparators.PageTimeComparator) XmlRpcException(org.apache.xmlrpc.XmlRpcException)

Example 2 with WeblogPlugin

use of org.apache.wiki.plugin.WeblogPlugin in project jspwiki by apache.

the class RSSGeneratorTest method testBlogRSS.

@Test
public void testBlogRSS() throws Exception {
    WeblogEntryPlugin plugin = new WeblogEntryPlugin();
    m_testEngine.saveText("TestBlog", "Foo1");
    String newPage = plugin.getNewEntryPage(m_testEngine, "TestBlog");
    m_testEngine.saveText(newPage, "!Title1\r\nFoo");
    newPage = plugin.getNewEntryPage(m_testEngine, "TestBlog");
    m_testEngine.saveText(newPage, "!Title2\r\n__Bar__");
    RSSGenerator gen = m_testEngine.getRSSGenerator();
    WikiContext context = new WikiContext(m_testEngine, m_testEngine.getPage("TestBlog"));
    WeblogPlugin blogplugin = new WeblogPlugin();
    List<?> entries = blogplugin.findBlogEntries(m_testEngine, "TestBlog", new Date(0), new Date(Long.MAX_VALUE));
    Feed feed = new RSS10Feed(context);
    String blog = gen.generateBlogRSS(context, entries, feed);
    Assert.assertTrue("has Foo", blog.indexOf("<description>Foo</description>") != -1);
    Assert.assertTrue("has proper Bar", blog.indexOf("&lt;b&gt;Bar&lt;/b&gt;") != -1);
}
Also used : WikiContext(org.apache.wiki.WikiContext) WeblogPlugin(org.apache.wiki.plugin.WeblogPlugin) WeblogEntryPlugin(org.apache.wiki.plugin.WeblogEntryPlugin) Date(java.util.Date) Test(org.junit.Test)

Example 3 with WeblogPlugin

use of org.apache.wiki.plugin.WeblogPlugin in project jspwiki by apache.

the class RSSGeneratorTest method testBlogRSS2.

@Test
public void testBlogRSS2() throws Exception {
    WeblogEntryPlugin plugin = new WeblogEntryPlugin();
    m_testEngine.saveText("TestBlog", "Foo1");
    String newPage = plugin.getNewEntryPage(m_testEngine, "TestBlog");
    m_testEngine.saveText(newPage, "!Title1\r\nFoo \"blah\".");
    newPage = plugin.getNewEntryPage(m_testEngine, "TestBlog");
    m_testEngine.saveText(newPage, "!Title2\r\n__Bar__");
    RSSGenerator gen = m_testEngine.getRSSGenerator();
    WikiContext context = new WikiContext(m_testEngine, m_testEngine.getPage("TestBlog"));
    WeblogPlugin blogplugin = new WeblogPlugin();
    List<?> entries = blogplugin.findBlogEntries(m_testEngine, "TestBlog", new Date(0), new Date(Long.MAX_VALUE));
    Feed feed = new RSS20Feed(context);
    String blog = gen.generateBlogRSS(context, entries, feed);
    Assert.assertTrue("has Foo", blog.indexOf("<description>Foo &amp;quot;blah&amp;quot;.</description>") != -1);
    Assert.assertTrue("has proper Bar", blog.indexOf("&lt;b&gt;Bar&lt;/b&gt;") != -1);
}
Also used : WikiContext(org.apache.wiki.WikiContext) WeblogPlugin(org.apache.wiki.plugin.WeblogPlugin) WeblogEntryPlugin(org.apache.wiki.plugin.WeblogEntryPlugin) Date(java.util.Date) Test(org.junit.Test)

Aggregations

Date (java.util.Date)3 WeblogPlugin (org.apache.wiki.plugin.WeblogPlugin)3 WikiContext (org.apache.wiki.WikiContext)2 WeblogEntryPlugin (org.apache.wiki.plugin.WeblogEntryPlugin)2 Test (org.junit.Test)2 Hashtable (java.util.Hashtable)1 WikiPage (org.apache.wiki.WikiPage)1 ProviderException (org.apache.wiki.api.exceptions.ProviderException)1 PageTimeComparator (org.apache.wiki.util.comparators.PageTimeComparator)1 XmlRpcException (org.apache.xmlrpc.XmlRpcException)1