use of org.apache.wiki.plugin.WeblogEntryPlugin 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.WeblogEntryPlugin 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);
}
use of org.apache.wiki.plugin.WeblogEntryPlugin in project jspwiki by apache.
the class MetaWeblogHandler method newPost.
/**
* Adds a new post to the blog.
*
* @param blogid The id of the blog.
* @param username The username to use
* @param password The password
* @param content As per Metaweblogapi contract
* @param publish This parameter is ignored for JSPWiki.
* @return Returns an empty string
* @throws XmlRpcException If something goes wrong
*/
public String newPost(String blogid, String username, String password, Hashtable content, boolean publish) throws XmlRpcException {
log.info("metaWeblog.newPost() called");
WikiEngine engine = m_context.getEngine();
WikiPage page = engine.getPage(blogid);
checkPermissions(page, username, password, "createPages");
try {
WeblogEntryPlugin plugin = new WeblogEntryPlugin();
String pageName = plugin.getNewEntryPage(engine, blogid);
WikiPage entryPage = new WikiPage(engine, pageName);
entryPage.setAuthor(username);
WikiContext context = new WikiContext(engine, entryPage);
StringBuilder text = new StringBuilder();
text.append("!" + content.get("title"));
text.append("\n\n");
text.append(content.get("description"));
log.debug("Writing entry: " + text);
engine.saveText(context, text.toString());
} catch (Exception e) {
log.error("Failed to create weblog entry", e);
throw new XmlRpcException(0, "Failed to create weblog entry: " + e.getMessage());
}
// FIXME:
return "";
}
use of org.apache.wiki.plugin.WeblogEntryPlugin 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);
}
}
Aggregations