Search in sources :

Example 6 with WikiPage

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

the class MetaWeblogHandler method getPost.

/**
 *  Gets the text of any page.  The title of the page is parsed
 *  (if any is provided).
 */
Hashtable getPost(String postid, String username, String password) throws XmlRpcException {
    String wikiname = "FIXME";
    WikiPage page = m_context.getEngine().getPage(wikiname);
    checkPermissions(page, username, password, "view");
    return makeEntry(page);
}
Also used : WikiPage(org.apache.wiki.WikiPage)

Example 7 with WikiPage

use of org.apache.wiki.WikiPage 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;
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) Hashtable(java.util.Hashtable) WikiPage(org.apache.wiki.WikiPage) Attachment(org.apache.wiki.attachment.Attachment) AttachmentManager(org.apache.wiki.attachment.AttachmentManager) 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)

Example 8 with WikiPage

use of org.apache.wiki.WikiPage 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;
}
Also used : WikiPage(org.apache.wiki.WikiPage) Attachment(org.apache.wiki.attachment.Attachment) Vector(java.util.Vector)

Example 9 with WikiPage

use of org.apache.wiki.WikiPage 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;
}
Also used : Hashtable(java.util.Hashtable) WikiPage(org.apache.wiki.WikiPage) Calendar(java.util.Calendar) Attachment(org.apache.wiki.attachment.Attachment) Vector(java.util.Vector)

Example 10 with WikiPage

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

the class AttachmentManagerTest method testListAttachments.

@Test
public void testListAttachments() throws Exception {
    Attachment att = new Attachment(m_engine, NAME1, "test1.txt");
    att.setAuthor("FirstPost");
    m_manager.storeAttachment(att, makeAttachmentFile());
    Collection<?> c = m_manager.listAttachments(new WikiPage(m_engine, NAME1));
    Assert.assertEquals("Length", 1, c.size());
    Attachment att2 = (Attachment) c.toArray()[0];
    Assert.assertEquals("name", att.getName(), att2.getName());
    Assert.assertEquals("author", att.getAuthor(), att2.getAuthor());
}
Also used : WikiPage(org.apache.wiki.WikiPage) Test(org.junit.Test)

Aggregations

WikiPage (org.apache.wiki.WikiPage)186 Test (org.junit.Test)77 WikiContext (org.apache.wiki.WikiContext)63 WikiEngine (org.apache.wiki.WikiEngine)29 Attachment (org.apache.wiki.attachment.Attachment)26 ProviderException (org.apache.wiki.api.exceptions.ProviderException)22 Date (java.util.Date)17 File (java.io.File)16 Collection (java.util.Collection)16 TestEngine (org.apache.wiki.TestEngine)15 Iterator (java.util.Iterator)13 StringReader (java.io.StringReader)9 Hashtable (java.util.Hashtable)9 IOException (java.io.IOException)8 ArrayList (java.util.ArrayList)8 Calendar (java.util.Calendar)8 Vector (java.util.Vector)8 StringWriter (java.io.StringWriter)7 InternalWikiException (org.apache.wiki.InternalWikiException)7 PagePermission (org.apache.wiki.auth.permissions.PagePermission)7