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());
}
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());
}
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());
}
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());
}
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 "";
}
Aggregations