Search in sources :

Example 11 with Attachment

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");
}
Also used : Attachment(org.apache.wiki.api.core.Attachment) Test(org.junit.jupiter.api.Test)

Example 12 with Attachment

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");
}
Also used : Attachment(org.apache.wiki.api.core.Attachment) Test(org.junit.jupiter.api.Test)

Example 13 with Attachment

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");
}
Also used : Attachment(org.apache.wiki.api.core.Attachment) Test(org.junit.jupiter.api.Test)

Example 14 with Attachment

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;
}
Also used : Hashtable(java.util.Hashtable) Page(org.apache.wiki.api.core.Page) Attachment(org.apache.wiki.api.core.Attachment) XmlRpcException(org.apache.xmlrpc.XmlRpcException) WikiSecurityException(org.apache.wiki.auth.WikiSecurityException) PageManager(org.apache.wiki.pages.PageManager) ByteArrayInputStream(java.io.ByteArrayInputStream) AttachmentManager(org.apache.wiki.attachment.AttachmentManager) Engine(org.apache.wiki.api.core.Engine) XmlRpcException(org.apache.xmlrpc.XmlRpcException)

Example 15 with Attachment

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;
}
Also used : PageManager(org.apache.wiki.pages.PageManager) Hashtable(java.util.Hashtable) Calendar(java.util.Calendar) Page(org.apache.wiki.api.core.Page) Attachment(org.apache.wiki.api.core.Attachment) Vector(java.util.Vector)

Aggregations

Attachment (org.apache.wiki.api.core.Attachment)76 Test (org.junit.jupiter.api.Test)37 AttachmentManager (org.apache.wiki.attachment.AttachmentManager)35 Page (org.apache.wiki.api.core.Page)27 ProviderException (org.apache.wiki.api.exceptions.ProviderException)20 PageManager (org.apache.wiki.pages.PageManager)19 File (java.io.File)15 Date (java.util.Date)10 Engine (org.apache.wiki.api.core.Engine)10 ReferenceManager (org.apache.wiki.references.ReferenceManager)9 InputStream (java.io.InputStream)8 FileInputStream (java.io.FileInputStream)6 IOException (java.io.IOException)6 InputStreamReader (java.io.InputStreamReader)6 StringWriter (java.io.StringWriter)6 Vector (java.util.Vector)6 WikiContext (org.apache.wiki.WikiContext)6 Permission (java.security.Permission)4 ArrayList (java.util.ArrayList)4 Hashtable (java.util.Hashtable)4