Search in sources :

Example 71 with Context

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)"));
}
Also used : Context(org.apache.wiki.api.core.Context) PageManager(org.apache.wiki.pages.PageManager) RenderingManager(org.apache.wiki.render.RenderingManager) Page(org.apache.wiki.api.core.Page) Test(org.junit.jupiter.api.Test)

Example 72 with Context

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

Example 73 with Context

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);
    }
}
Also used : Context(org.apache.wiki.api.core.Context) WikiException(org.apache.wiki.api.exceptions.WikiException) Page(org.apache.wiki.api.core.Page) IOException(java.io.IOException) WeblogEntryPlugin(org.apache.wiki.plugin.WeblogEntryPlugin) ServletException(javax.servlet.ServletException) PageManager(org.apache.wiki.pages.PageManager) Entry(org.intabulas.sandler.elements.Entry) Content(org.intabulas.sandler.elements.Content) FeedMarshallException(org.intabulas.sandler.exceptions.FeedMarshallException) Person(org.intabulas.sandler.elements.Person)

Example 74 with Context

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;
}
Also used : Context(org.apache.wiki.api.core.Context) PageManager(org.apache.wiki.pages.PageManager) Page(org.apache.wiki.api.core.Page) Date(java.util.Date) Link(org.intabulas.sandler.elements.Link) Feed(org.intabulas.sandler.elements.Feed)

Example 75 with Context

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();
}
Also used : Context(org.apache.wiki.api.core.Context) DifferenceManager(org.apache.wiki.diff.DifferenceManager)

Aggregations

Context (org.apache.wiki.api.core.Context)81 Page (org.apache.wiki.api.core.Page)46 PageManager (org.apache.wiki.pages.PageManager)42 Test (org.junit.jupiter.api.Test)40 RenderingManager (org.apache.wiki.render.RenderingManager)15 PageContext (javax.servlet.jsp.PageContext)11 Engine (org.apache.wiki.api.core.Engine)9 ReferenceManager (org.apache.wiki.references.ReferenceManager)8 IOException (java.io.IOException)7 ArrayList (java.util.ArrayList)6 Date (java.util.Date)6 ServletContext (javax.servlet.ServletContext)6 ProviderException (org.apache.wiki.api.exceptions.ProviderException)6 WikiContext (org.apache.wiki.WikiContext)5 StringReader (java.io.StringReader)4 Properties (java.util.Properties)4 MockHttpServletRequest (net.sourceforge.stripes.mock.MockHttpServletRequest)4 WikiSessionTest (org.apache.wiki.WikiSessionTest)4 Attachment (org.apache.wiki.api.core.Attachment)4 SearchResult (org.apache.wiki.api.search.SearchResult)4