Search in sources :

Example 1 with WikiPage

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

the class MailUtilTest method setUp.

@Before
public void setUp() throws Exception {
    PropertyConfigurator.configure(m_props);
    TestEngine testEngine = new TestEngine(m_props);
    m_context = new WikiContext(testEngine, new WikiPage(testEngine, PAGE_NAME));
}
Also used : WikiContext(org.apache.wiki.WikiContext) WikiPage(org.apache.wiki.WikiPage) TestEngine(org.apache.wiki.TestEngine) Before(org.junit.Before)

Example 2 with WikiPage

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

the class RPCHandlerTest method testPageInfo.

@Test
public void testPageInfo() throws Exception {
    m_engine.saveText(NAME1, "Foobar.[{ALLOW view Anonymous}]");
    WikiPage directInfo = m_engine.getPage(NAME1);
    Hashtable ht = m_handler.getPageInfo(NAME1);
    Assert.assertEquals("name", (String) ht.get("name"), NAME1);
    Date d = (Date) ht.get("lastModified");
    Calendar cal = Calendar.getInstance();
    cal.setTime(d);
    // System.out.println("Real: "+directInfo.getLastModified() );
    // System.out.println("RPC:  "+d );
    // Offset the ZONE offset and DST offset away.  DST only
    // if we're actually in DST.
    cal.add(Calendar.MILLISECOND, (cal.get(Calendar.ZONE_OFFSET) + (cal.getTimeZone().inDaylightTime(d) ? cal.get(Calendar.DST_OFFSET) : 0)));
    // System.out.println("RPC2: "+cal.getTime() );
    Assert.assertEquals("date", cal.getTime().getTime(), directInfo.getLastModified().getTime());
}
Also used : Hashtable(java.util.Hashtable) WikiPage(org.apache.wiki.WikiPage) Calendar(java.util.Calendar) Date(java.util.Date) Test(org.junit.Test)

Example 3 with WikiPage

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

the class AbstractRPCHandler method getRecentChanges.

public Vector getRecentChanges(Date since) {
    checkPermission(PagePermission.VIEW);
    Collection<WikiPage> pages = m_engine.getRecentChanges();
    Vector<Hashtable<?, ?>> result = new Vector<Hashtable<?, ?>>();
    // Transform UTC into local time.
    Calendar cal = Calendar.getInstance();
    cal.setTime(since);
    cal.add(Calendar.MILLISECOND, cal.get(Calendar.ZONE_OFFSET) + (cal.getTimeZone().inDaylightTime(since) ? cal.get(Calendar.DST_OFFSET) : 0));
    for (WikiPage page : pages) {
        if (page.getLastModified().after(cal.getTime())) {
            result.add(encodeWikiPage(page));
        }
    }
    return result;
}
Also used : WikiPage(org.apache.wiki.WikiPage)

Example 4 with WikiPage

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

the class MetaWeblogHandler method editPost.

/**
 *  Allows the user to edit a post.  It does not allow general
 *   editability of wiki pages, because of the limitations of the
 *  metaWeblog API.
 */
boolean editPost(String postid, String username, String password, Hashtable content, boolean publish) throws XmlRpcException {
    WikiEngine engine = m_context.getEngine();
    log.info("metaWeblog.editPost(" + postid + ") called");
    // FIXME: Is postid correct?  Should we determine it from the page name?
    WikiPage page = engine.getPage(postid);
    checkPermissions(page, username, password, "edit");
    try {
        WikiPage entryPage = (WikiPage) page.clone();
        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("Updating entry: " + text);
        engine.saveText(context, text.toString());
    } catch (Exception e) {
        log.error("Failed to create weblog entry", e);
        throw new XmlRpcException(0, "Failed to update weblog entry: " + e.getMessage());
    }
    return true;
}
Also used : WikiContext(org.apache.wiki.WikiContext) WikiPage(org.apache.wiki.WikiPage) 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 5 with WikiPage

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

the class MetaWeblogHandler method getRecentPosts.

/**
 *  Returns a list of the recent posts to this weblog.
 *
 *  @param blogid The id of the blog.
 *  @param username The username to use
 *  @param password The password
 *  @param numberOfPosts How many posts to find
 *  @throws XmlRpcException If something goes wrong
 *  @return As per MetaweblogAPI specification
 */
// FIXME: The implementation is suboptimal, as it
// goes through all of the blog entries.
@SuppressWarnings("unchecked")
public Hashtable getRecentPosts(String blogid, String username, String password, int numberOfPosts) throws XmlRpcException {
    Hashtable<String, Hashtable<String, Object>> result = new Hashtable<String, Hashtable<String, Object>>();
    log.info("metaWeblog.getRecentPosts() called");
    WikiPage page = m_context.getEngine().getPage(blogid);
    checkPermissions(page, username, password, "view");
    try {
        WeblogPlugin plugin = new WeblogPlugin();
        List<WikiPage> changed = plugin.findBlogEntries(m_context.getEngine(), blogid, new Date(0L), new Date());
        Collections.sort(changed, new PageTimeComparator());
        int items = 0;
        for (Iterator<WikiPage> i = changed.iterator(); i.hasNext() && items < numberOfPosts; items++) {
            WikiPage p = i.next();
            result.put("entry", makeEntry(p));
        }
    } catch (ProviderException e) {
        log.error("Failed to list recent posts", e);
        throw new XmlRpcException(0, e.getMessage());
    }
    return result;
}
Also used : WeblogPlugin(org.apache.wiki.plugin.WeblogPlugin) ProviderException(org.apache.wiki.api.exceptions.ProviderException) Hashtable(java.util.Hashtable) WikiPage(org.apache.wiki.WikiPage) Date(java.util.Date) PageTimeComparator(org.apache.wiki.util.comparators.PageTimeComparator) XmlRpcException(org.apache.xmlrpc.XmlRpcException)

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