use of org.apache.wiki.api.core.Attachment in project jspwiki by apache.
the class AttachmentManagerTest method testExists2.
@Test
public void testExists2() throws Exception {
final Attachment att = Wiki.contents().attachment(m_engine, NAME1, "test1.bin");
att.setAuthor("FirstPost");
m_manager.storeAttachment(att, makeAttachmentFile());
Assertions.assertTrue(m_engine.getManager(PageManager.class).wikiPageExists(att.getName()), "attachment disappeared");
}
use of org.apache.wiki.api.core.Attachment in project jspwiki by apache.
the class AttachmentManagerTest method testExists.
@Test
public void testExists() throws Exception {
final Attachment att = Wiki.contents().attachment(m_engine, NAME1, "test1");
att.setAuthor("FirstPost");
m_manager.storeAttachment(att, makeAttachmentFile());
Assertions.assertTrue(m_engine.getManager(PageManager.class).wikiPageExists(NAME1 + "/test1"), "attachment disappeared");
}
use of org.apache.wiki.api.core.Attachment in project jspwiki by apache.
the class AttachmentManagerTest method testListAttachments.
@Test
public void testListAttachments() throws Exception {
final Attachment att = Wiki.contents().attachment(m_engine, NAME1, "test1.txt");
att.setAuthor("FirstPost");
m_manager.storeAttachment(att, makeAttachmentFile());
final List<Attachment> c = m_manager.listAttachments(Wiki.contents().page(m_engine, NAME1));
Assertions.assertEquals(1, c.size(), "Length");
final Attachment att2 = (Attachment) c.toArray()[0];
Assertions.assertEquals(att.getName(), att2.getName(), "name");
Assertions.assertEquals(att.getAuthor(), att2.getAuthor(), "author");
}
use of org.apache.wiki.api.core.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<String, Object> newMediaObject(final String blogid, final String username, final String password, final Hashtable<String, Object> content) throws XmlRpcException {
final Engine engine = m_context.getEngine();
final String url;
log.info("metaWeblog.newMediaObject() called");
final Page page = engine.getManager(PageManager.class).getPage(blogid);
checkPermissions(page, username, password, "upload");
final String name = (String) content.get("name");
final byte[] data = (byte[]) content.get("bits");
final AttachmentManager attmgr = engine.getManager(AttachmentManager.class);
try {
final Attachment att = Wiki.contents().attachment(engine, blogid, name);
att.setAuthor(username);
attmgr.storeAttachment(att, new ByteArrayInputStream(data));
url = engine.getURL(ContextEnum.PAGE_ATTACH.getRequestContext(), att.getName(), null);
} catch (final Exception e) {
log.error("Failed to upload attachment", e);
throw new XmlRpcException(0, "Failed to upload media object: " + e.getMessage());
}
final Hashtable<String, Object> result = new Hashtable<>();
result.put("url", url);
return result;
}
use of org.apache.wiki.api.core.Attachment in project jspwiki by apache.
the class RPCHandlerUTF8 method getRecentChanges.
@Override
public Vector<Hashtable<String, Object>> getRecentChanges(Date since) {
checkPermission(PagePermission.VIEW);
final Set<Page> pages = m_engine.getManager(PageManager.class).getRecentChanges();
final Vector<Hashtable<String, Object>> result = new Vector<>();
final 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 (final Page page : pages) {
if (page.getLastModified().after(since) && !(page instanceof Attachment)) {
result.add(encodeWikiPage(page));
}
}
return result;
}
Aggregations