use of org.apache.wiki.attachment.Attachment in project jspwiki by apache.
the class RPCHandlerTest method testListLinksWithAttachments.
@Test
public void testListLinksWithAttachments() throws Exception {
String text = "[Foobar] [Test/TestAtt.txt]";
String pageName = NAME1;
m_engine.saveText(pageName, text);
Attachment att = new Attachment(m_engine, NAME1, "TestAtt.txt");
att.setAuthor("FirstPost");
m_engine.getAttachmentManager().storeAttachment(att, m_engine.makeAttachmentFile());
// Test.
Vector links = m_handler.listLinks(pageName);
Assert.assertEquals("link count", 2, links.size());
Hashtable linkinfo = (Hashtable) links.elementAt(0);
Assert.assertEquals("edit name", "Foobar", linkinfo.get("page"));
Assert.assertEquals("edit type", "local", linkinfo.get("type"));
Assert.assertEquals("edit href", "/test/Edit.jsp?page=Foobar", linkinfo.get("href"));
linkinfo = (Hashtable) links.elementAt(1);
Assert.assertEquals("att name", NAME1 + "/TestAtt.txt", linkinfo.get("page"));
Assert.assertEquals("att type", "local", linkinfo.get("type"));
Assert.assertEquals("att href", "/test/attach/" + NAME1 + "/TestAtt.txt", linkinfo.get("href"));
}
use of org.apache.wiki.attachment.Attachment in project jspwiki by apache.
the class MetaWeblogHandler method newMediaObject.
/**
* Creates an attachment and adds it to the blog. The attachment
* is created into the main blog page, not the actual post page,
* because we do not know it at this point.
*
* @param blogid The id of the blog.
* @param username The username to use
* @param password The password
* @param content As per the MetaweblogAPI contract
* @return As per the MetaweblogAPI contract
* @throws XmlRpcException If something goes wrong
*/
public Hashtable newMediaObject(String blogid, String username, String password, Hashtable content) throws XmlRpcException {
WikiEngine engine = m_context.getEngine();
String url = "";
log.info("metaWeblog.newMediaObject() called");
WikiPage page = engine.getPage(blogid);
checkPermissions(page, username, password, "upload");
String name = (String) content.get("name");
byte[] data = (byte[]) content.get("bits");
AttachmentManager attmgr = engine.getAttachmentManager();
try {
Attachment att = new Attachment(engine, blogid, name);
att.setAuthor(username);
attmgr.storeAttachment(att, new ByteArrayInputStream(data));
url = engine.getURL(WikiContext.ATTACH, att.getName(), null, true);
} catch (Exception e) {
log.error("Failed to upload attachment", e);
throw new XmlRpcException(0, "Failed to upload media object: " + e.getMessage());
}
Hashtable<String, Object> result = new Hashtable<String, Object>();
result.put("url", url);
return result;
}
use of org.apache.wiki.attachment.Attachment in project jspwiki by apache.
the class RPCHandler method getAllPages.
public Vector getAllPages() {
checkPermission(PagePermission.VIEW);
Collection<WikiPage> pages = m_engine.getRecentChanges();
Vector<String> result = new Vector<String>();
for (WikiPage p : pages) {
if (!(p instanceof Attachment)) {
result.add(toRPCString(p.getName()));
}
}
return result;
}
use of org.apache.wiki.attachment.Attachment in project jspwiki by apache.
the class RPCHandlerUTF8 method getRecentChanges.
public Vector getRecentChanges(Date since) {
checkPermission(PagePermission.VIEW);
Collection<WikiPage> pages = m_engine.getRecentChanges();
Vector<Hashtable<String, Object>> result = new Vector<Hashtable<String, Object>>();
Calendar cal = Calendar.getInstance();
cal.setTime(since);
//
// Convert UTC to our time.
//
cal.add(Calendar.MILLISECOND, (cal.get(Calendar.ZONE_OFFSET) + (cal.getTimeZone().inDaylightTime(since) ? cal.get(Calendar.DST_OFFSET) : 0)));
since = cal.getTime();
for (WikiPage page : pages) {
if (page.getLastModified().after(since) && !(page instanceof Attachment)) {
result.add(encodeWikiPage(page));
}
}
return result;
}
use of org.apache.wiki.attachment.Attachment in project jspwiki by apache.
the class WikiEngineTest method testDeletePageAndAttachments.
@Test
public void testDeletePageAndAttachments() throws Exception {
m_engine.saveText(NAME1, "Test");
Attachment att = new Attachment(m_engine, NAME1, "TestAtt.txt");
att.setAuthor("FirstPost");
m_engine.getAttachmentManager().storeAttachment(att, m_engine.makeAttachmentFile());
String files = props.getProperty(FileSystemProvider.PROP_PAGEDIR);
File saved = new File(files, NAME1 + FileSystemProvider.FILE_EXT);
String atts = props.getProperty(BasicAttachmentProvider.PROP_STORAGEDIR);
File attfile = new File(atts, NAME1 + "-att/TestAtt.txt-dir");
Assert.assertTrue("Didn't create it!", saved.exists());
Assert.assertTrue("Attachment dir does not exist", attfile.exists());
WikiPage page = m_engine.getPage(NAME1, WikiProvider.LATEST_VERSION);
m_engine.deletePage(page.getName());
Assert.assertFalse("Page has not been removed!", saved.exists());
Assert.assertFalse("Attachment has not been removed", attfile.exists());
}
Aggregations