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));
}
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());
}
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;
}
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;
}
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;
}
Aggregations