use of org.apache.wiki.api.core.Context in project jspwiki by apache.
the class PageViewPluginTest method testShowCountsBasic.
@Test
public void testShowCountsBasic() throws Exception {
final Page page1 = testEngine.getManager(PageManager.class).getPage("TestPage01");
final Context context1 = Wiki.context().create(testEngine, page1);
final Page page2 = testEngine.getManager(PageManager.class).getPage("TestPage02");
final Context context2 = Wiki.context().create(testEngine, page2);
// generate counts:
testEngine.getManager(RenderingManager.class).getHTML(context1, page1);
testEngine.getManager(RenderingManager.class).getHTML(context2, page2);
testEngine.getManager(RenderingManager.class).getHTML(context2, page2);
// mind the double \n in the following string:
final String pageViewPageContent = "[{PageViewPlugin show='list''\n\n* {1} ({2} views)\n}]";
testEngine.saveText("PageViews", pageViewPageContent);
final Page pageviews = testEngine.getManager(PageManager.class).getPage("PageViews");
final Context contextPV = Wiki.context().create(testEngine, pageviews);
final String result = testEngine.getManager(RenderingManager.class).getHTML(contextPV, pageviews);
// System.out.println( result );
Assertions.assertTrue(result.contains("Test Page 01 (2 views)"));
Assertions.assertTrue(result.contains("Test Page 02 (3 views)"));
}
use of org.apache.wiki.api.core.Context in project jspwiki by apache.
the class ReferringPagesPluginTest method testReferenceWidth.
@Test
public void testReferenceWidth() throws Exception {
final Context context2 = Wiki.context().create(engine, Wiki.contents().page(engine, "Foobar"));
final String res = manager.execute(context2, "{INSERT org.apache.wiki.plugin.ReferringPagesPlugin WHERE maxwidth=5}");
Assertions.assertEquals(mkFullLink("TestP...", "TestPage") + "<br />", res);
}
use of org.apache.wiki.api.core.Context in project jspwiki by apache.
the class AtomAPIServlet method doPost.
/**
* Implements the PostURI of the Atom spec.
* <p>
* Implementation notes:
* <ul>
* <li>Only fetches the first content. All other contents are ignored.
* <li>Assumes that incoming code is plain text or WikiMarkup, not html.
* </ul>
*
* {@inheritDoc}
*/
@Override
public void doPost(final HttpServletRequest request, final HttpServletResponse response) throws ServletException {
log.debug("Received POST to AtomAPIServlet");
try {
final String blogid = getPageName(request);
final Page page = m_engine.getManager(PageManager.class).getPage(blogid);
if (page == null) {
throw new ServletException("Page " + blogid + " does not exist, cannot add blog post.");
}
// FIXME: Do authentication here
final Entry entry = Sandler.unmarshallEntry(request.getInputStream());
// Fetch the obligatory parts of the content.
final Content title = entry.getTitle();
final Content content = entry.getContent(0);
final Person author = entry.getAuthor();
// FIXME: Sandler 0.5 does not support generator
// Generate new blog entry.
final WeblogEntryPlugin plugin = new WeblogEntryPlugin();
final String pageName = plugin.getNewEntryPage(m_engine, blogid);
final String username = author.getName();
final Page entryPage = Wiki.contents().page(m_engine, pageName);
entryPage.setAuthor(username);
final Context context = Wiki.context().create(m_engine, request, entryPage);
final StringBuilder text = new StringBuilder();
text.append("!").append(title.getBody()).append("\n\n").append(content.getBody());
log.debug("Writing entry: " + text);
m_engine.getManager(PageManager.class).saveText(context, text.toString());
} catch (final FeedMarshallException e) {
log.error("Received faulty Atom entry", e);
throw new ServletException("Faulty Atom entry", e);
} catch (final IOException e) {
log.error("I/O exception", e);
throw new ServletException("Could not get body of request", e);
} catch (final WikiException e) {
log.error("Provider exception while posting", e);
throw new ServletException("JSPWiki cannot save the entry", e);
}
}
use of org.apache.wiki.api.core.Context in project jspwiki by apache.
the class AtomAPIServlet method listBlogs.
/**
* Creates and outputs a full list of all available blogs
*/
private Feed listBlogs() throws ProviderException {
final Collection<Page> pages = m_engine.getManager(PageManager.class).getAllPages();
final Feed feed = SyndicationFactory.newSyndicationFeed();
feed.setTitle("List of blogs at this site");
feed.setModified(new Date());
for (final Page p : pages) {
// List only weblogs
// FIXME: Unfortunately, a weblog is not known until it has een executed once, because plugins are off during the initial startup phase.
log.debug(p.getName() + " = " + p.getAttribute(WeblogPlugin.ATTR_ISWEBLOG));
if (!("true".equals(p.getAttribute(WeblogPlugin.ATTR_ISWEBLOG)))) {
continue;
}
final String encodedName = TextUtil.urlEncodeUTF8(p.getName());
final Context context = Wiki.context().create(m_engine, p);
final String title = TextUtil.replaceEntities(org.apache.wiki.rss.Feed.getSiteName(context));
final Link postlink = createLink("service.post", m_engine.getBaseURL() + "atom/" + encodedName, title);
final Link editlink = createLink("service.edit", m_engine.getBaseURL() + "atom/" + encodedName, title);
final Link feedlink = createLink("service.feed", m_engine.getBaseURL() + "atom.jsp?page=" + encodedName, title);
feed.addLink(postlink);
feed.addLink(feedlink);
feed.addLink(editlink);
}
return feed;
}
use of org.apache.wiki.api.core.Context in project jspwiki by apache.
the class DefaultRSSGenerator method getPageDescription.
private String getPageDescription(final Page page) {
final StringBuilder buf = new StringBuilder();
final String author = getAuthor(page);
final Context ctx = Wiki.context().create(m_engine, page);
if (page.getVersion() > 1) {
final String diff = m_engine.getManager(DifferenceManager.class).getDiff(ctx, // FIXME: Will fail when non-contiguous versions
page.getVersion() - 1, page.getVersion());
buf.append(author).append(" changed this page on ").append(page.getLastModified()).append(":<br /><hr /><br />");
buf.append(diff);
} else {
buf.append(author).append(" created this page on ").append(page.getLastModified()).append(":<br /><hr /><br />");
buf.append(m_engine.getManager(RenderingManager.class).getHTML(page.getName()));
}
return buf.toString();
}
Aggregations