Search in sources :

Example 1 with WeblogEntryPlugin

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("&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 2 with WeblogEntryPlugin

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 &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)

Example 3 with WeblogEntryPlugin

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 "";
}
Also used : WikiContext(org.apache.wiki.WikiContext) WikiPage(org.apache.wiki.WikiPage) WeblogEntryPlugin(org.apache.wiki.plugin.WeblogEntryPlugin) WikiEngine(org.apache.wiki.WikiEngine) XmlRpcException(org.apache.xmlrpc.XmlRpcException) WikiSecurityException(org.apache.wiki.auth.WikiSecurityException) ProviderException(org.apache.wiki.api.exceptions.ProviderException) XmlRpcException(org.apache.xmlrpc.XmlRpcException)

Example 4 with WeblogEntryPlugin

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);
    }
}
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)

Aggregations

WikiContext (org.apache.wiki.WikiContext)4 WeblogEntryPlugin (org.apache.wiki.plugin.WeblogEntryPlugin)4 Date (java.util.Date)2 WikiPage (org.apache.wiki.WikiPage)2 WeblogPlugin (org.apache.wiki.plugin.WeblogPlugin)2 Test (org.junit.Test)2 IOException (java.io.IOException)1 ServletException (javax.servlet.ServletException)1 WikiEngine (org.apache.wiki.WikiEngine)1 ProviderException (org.apache.wiki.api.exceptions.ProviderException)1 WikiException (org.apache.wiki.api.exceptions.WikiException)1 WikiSecurityException (org.apache.wiki.auth.WikiSecurityException)1 XmlRpcException (org.apache.xmlrpc.XmlRpcException)1 Content (org.intabulas.sandler.elements.Content)1 Entry (org.intabulas.sandler.elements.Entry)1 Person (org.intabulas.sandler.elements.Person)1 FeedMarshallException (org.intabulas.sandler.exceptions.FeedMarshallException)1