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;
}
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("<b>Bar</b>") != -1);
}
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 &quot;blah&quot;.</description>") != -1);
Assert.assertTrue("has proper Bar", blog.indexOf("<b>Bar</b>") != -1);
}
Aggregations