Search in sources :

Example 66 with WikiContext

use of org.apache.wiki.WikiContext in project jspwiki by apache.

the class AttachmentManagerTest method testSimpleStoreWithoutExt.

@Test
public void testSimpleStoreWithoutExt() throws Exception {
    Attachment att = new Attachment(m_engine, NAME1, "test1");
    att.setAuthor("FirstPost");
    m_manager.storeAttachment(att, makeAttachmentFile());
    Attachment att2 = m_manager.getAttachmentInfo(new WikiContext(m_engine, new WikiPage(m_engine, NAME1)), "test1");
    Assert.assertNotNull("attachment disappeared", att2);
    Assert.assertEquals("name", att.getName(), att2.getName());
    Assert.assertEquals("author", "FirstPost", att2.getAuthor());
    Assert.assertEquals("size", c_fileContents.length(), att2.getSize());
    Assert.assertEquals("version", 1, att2.getVersion());
    InputStream in = m_manager.getAttachmentStream(att2);
    Assert.assertNotNull("stream", in);
    StringWriter sout = new StringWriter();
    FileUtil.copyContents(new InputStreamReader(in), sout);
    in.close();
    sout.close();
    Assert.assertEquals("contents", c_fileContents, sout.toString());
}
Also used : WikiContext(org.apache.wiki.WikiContext) StringWriter(java.io.StringWriter) InputStreamReader(java.io.InputStreamReader) InputStream(java.io.InputStream) WikiPage(org.apache.wiki.WikiPage) Test(org.junit.Test)

Example 67 with WikiContext

use of org.apache.wiki.WikiContext in project jspwiki by apache.

the class AttachmentManagerTest method testSimpleStore.

@Test
public void testSimpleStore() throws Exception {
    Attachment att = new Attachment(m_engine, NAME1, "test1.txt");
    att.setAuthor("FirstPost");
    m_manager.storeAttachment(att, makeAttachmentFile());
    Attachment att2 = m_manager.getAttachmentInfo(new WikiContext(m_engine, new WikiPage(m_engine, NAME1)), "test1.txt");
    Assert.assertNotNull("attachment disappeared", att2);
    Assert.assertEquals("name", att.getName(), att2.getName());
    Assert.assertEquals("author", att.getAuthor(), att2.getAuthor());
    Assert.assertEquals("size", c_fileContents.length(), att2.getSize());
    InputStream in = m_manager.getAttachmentStream(att2);
    Assert.assertNotNull("stream", in);
    StringWriter sout = new StringWriter();
    FileUtil.copyContents(new InputStreamReader(in), sout);
    in.close();
    sout.close();
    Assert.assertEquals("contents", c_fileContents, sout.toString());
}
Also used : WikiContext(org.apache.wiki.WikiContext) StringWriter(java.io.StringWriter) InputStreamReader(java.io.InputStreamReader) InputStream(java.io.InputStream) WikiPage(org.apache.wiki.WikiPage) Test(org.junit.Test)

Example 68 with WikiContext

use of org.apache.wiki.WikiContext in project jspwiki by apache.

the class AttachmentManagerTest method testSimpleStoreSpace.

@Test
public void testSimpleStoreSpace() throws Exception {
    Attachment att = new Attachment(m_engine, NAME1, "test file.txt");
    att.setAuthor("FirstPost");
    m_manager.storeAttachment(att, makeAttachmentFile());
    Attachment att2 = m_manager.getAttachmentInfo(new WikiContext(m_engine, new WikiPage(m_engine, NAME1)), "test file.txt");
    Assert.assertNotNull("attachment disappeared", att2);
    Assert.assertEquals("name", att.getName(), att2.getName());
    Assert.assertEquals("author", att.getAuthor(), att2.getAuthor());
    Assert.assertEquals("size", c_fileContents.length(), att2.getSize());
    InputStream in = m_manager.getAttachmentStream(att2);
    Assert.assertNotNull("stream", in);
    StringWriter sout = new StringWriter();
    FileUtil.copyContents(new InputStreamReader(in), sout);
    in.close();
    sout.close();
    Assert.assertEquals("contents", c_fileContents, sout.toString());
}
Also used : WikiContext(org.apache.wiki.WikiContext) StringWriter(java.io.StringWriter) InputStreamReader(java.io.InputStreamReader) InputStream(java.io.InputStream) WikiPage(org.apache.wiki.WikiPage) Test(org.junit.Test)

Example 69 with WikiContext

use of org.apache.wiki.WikiContext in project jspwiki by apache.

the class AttachmentManagerTest method testMultipleStore.

@Test
public void testMultipleStore() throws Exception {
    Attachment att = new Attachment(m_engine, NAME1, "test1.txt");
    att.setAuthor("FirstPost");
    m_manager.storeAttachment(att, makeAttachmentFile());
    att.setAuthor("FooBar");
    m_manager.storeAttachment(att, makeAttachmentFile());
    Attachment att2 = m_manager.getAttachmentInfo(new WikiContext(m_engine, new WikiPage(m_engine, NAME1)), "test1.txt");
    Assert.assertNotNull("attachment disappeared", att2);
    Assert.assertEquals("name", att.getName(), att2.getName());
    Assert.assertEquals("author", att.getAuthor(), att2.getAuthor());
    Assert.assertEquals("version", 2, att2.getVersion());
    InputStream in = m_manager.getAttachmentStream(att2);
    Assert.assertNotNull("stream", in);
    StringWriter sout = new StringWriter();
    FileUtil.copyContents(new InputStreamReader(in), sout);
    in.close();
    sout.close();
    Assert.assertEquals("contents", c_fileContents, sout.toString());
    // 
    // Check that first author did not disappear
    // 
    Attachment att3 = m_manager.getAttachmentInfo(new WikiContext(m_engine, new WikiPage(m_engine, NAME1)), "test1.txt", 1);
    Assert.assertEquals("version of v1", 1, att3.getVersion());
    Assert.assertEquals("name of v1", "FirstPost", att3.getAuthor());
}
Also used : WikiContext(org.apache.wiki.WikiContext) StringWriter(java.io.StringWriter) InputStreamReader(java.io.InputStreamReader) InputStream(java.io.InputStream) WikiPage(org.apache.wiki.WikiPage) Test(org.junit.Test)

Example 70 with WikiContext

use of org.apache.wiki.WikiContext 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)

Aggregations

WikiContext (org.apache.wiki.WikiContext)90 WikiPage (org.apache.wiki.WikiPage)63 Test (org.junit.Test)40 TestEngine (org.apache.wiki.TestEngine)11 StringReader (java.io.StringReader)9 WikiEngine (org.apache.wiki.WikiEngine)9 ProviderException (org.apache.wiki.api.exceptions.ProviderException)8 IOException (java.io.IOException)7 InputStream (java.io.InputStream)7 Before (org.junit.Before)7 BufferedReader (java.io.BufferedReader)6 StringWriter (java.io.StringWriter)6 Collection (java.util.Collection)6 InputStreamReader (java.io.InputStreamReader)5 Date (java.util.Date)5 LinkCollector (org.apache.wiki.LinkCollector)5 Attachment (org.apache.wiki.attachment.Attachment)5 Properties (java.util.Properties)4 MockHttpServletRequest (net.sourceforge.stripes.mock.MockHttpServletRequest)4 WikiDocument (org.apache.wiki.parser.WikiDocument)4