Search in sources :

Example 11 with Context

use of org.apache.wiki.api.core.Context in project jspwiki by apache.

the class IteratorTag method buildContext.

/**
 *  Arg, I hate globals.
 */
private void buildContext() {
    final Context context = m_wikiContext.clone();
    final Object o = m_iterator.next();
    if (o instanceof Page) {
        context.setPage((Page) o);
    }
    pageContext.setAttribute(Context.ATTR_CONTEXT, context, PageContext.REQUEST_SCOPE);
    pageContext.setAttribute(getId(), o);
}
Also used : Context(org.apache.wiki.api.core.Context) PageContext(javax.servlet.jsp.PageContext) Page(org.apache.wiki.api.core.Page)

Example 12 with Context

use of org.apache.wiki.api.core.Context in project jspwiki by apache.

the class AttachmentsIteratorTag method doAfterBody.

/**
 *  {@inheritDoc}
 */
@Override
public final int doAfterBody() {
    if (bodyContent != null) {
        try {
            final JspWriter out = getPreviousOut();
            out.print(bodyContent.getString());
            bodyContent.clearBody();
        } catch (final IOException e) {
            log.error("Unable to get inner tag text", e);
        // FIXME: throw something?
        }
    }
    if (m_iterator != null && m_iterator.hasNext()) {
        final Attachment att = (Attachment) m_iterator.next();
        final Context context = m_wikiContext.clone();
        context.setPage(att);
        pageContext.setAttribute(Context.ATTR_CONTEXT, context, PageContext.REQUEST_SCOPE);
        pageContext.setAttribute(getId(), att);
        return EVAL_BODY_BUFFERED;
    }
    return SKIP_BODY;
}
Also used : Context(org.apache.wiki.api.core.Context) PageContext(javax.servlet.jsp.PageContext) Attachment(org.apache.wiki.api.core.Attachment) IOException(java.io.IOException) JspWriter(javax.servlet.jsp.JspWriter)

Example 13 with Context

use of org.apache.wiki.api.core.Context in project jspwiki by apache.

the class SearchResultIteratorTag method nextResult.

private int nextResult() {
    if (m_iterator != null && m_iterator.hasNext() && m_count++ < m_maxItems) {
        final SearchResult r = (SearchResult) m_iterator.next();
        // Create a wiki context for the result
        final Engine engine = m_wikiContext.getEngine();
        final HttpServletRequest request = m_wikiContext.getHttpRequest();
        final Command command = PageCommand.VIEW.targetedCommand(r.getPage());
        final Context context = Wiki.context().create(engine, request, command);
        // Stash it in the page context
        pageContext.setAttribute(Context.ATTR_CONTEXT, context, PageContext.REQUEST_SCOPE);
        pageContext.setAttribute(getId(), r);
        return EVAL_BODY_BUFFERED;
    }
    return SKIP_BODY;
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) Context(org.apache.wiki.api.core.Context) PageContext(javax.servlet.jsp.PageContext) PageCommand(org.apache.wiki.ui.PageCommand) Command(org.apache.wiki.api.core.Command) SearchResult(org.apache.wiki.api.search.SearchResult) Engine(org.apache.wiki.api.core.Engine)

Example 14 with Context

use of org.apache.wiki.api.core.Context in project jspwiki by apache.

the class SearchManagerTest method testSimpleSearch4.

@Test
public void testSimpleSearch4() throws Exception {
    final String txt = "It was the dawn of the third age of mankind, ten years after the Earth-Minbari War.";
    final MockHttpServletRequest request = m_engine.newHttpRequest();
    request.getParameterMap().put("page", new String[] { "TestPage" });
    final Context ctx = Wiki.context().create(m_engine, request, ContextEnum.PAGE_EDIT.getRequestContext());
    m_engine.getManager(PageManager.class).saveText(ctx, txt);
    Collection<SearchResult> res = new ArrayList<>();
    Awaitility.await("testSimpleSearch4").until(findsResultsFor(res, "mankind"));
    Assertions.assertEquals(1, res.size(), "result not found");
    m_engine.getManager(PageManager.class).saveText(ctx, "[{ALLOW view Authenticated}] It was the dawn of the third age of mankind... page is blocked");
    res = m_mgr.findPages("mankind", ctx);
    Assertions.assertNotNull(res, "null result");
    Assertions.assertEquals(0, res.size(), "result found, should be blocked");
    m_engine.deleteTestPage("TestPage");
}
Also used : Context(org.apache.wiki.api.core.Context) PageManager(org.apache.wiki.pages.PageManager) MockHttpServletRequest(net.sourceforge.stripes.mock.MockHttpServletRequest) ArrayList(java.util.ArrayList) SearchResult(org.apache.wiki.api.search.SearchResult) Test(org.junit.jupiter.api.Test)

Example 15 with Context

use of org.apache.wiki.api.core.Context in project jspwiki by apache.

the class SaveWikiPageTaskTest method testSaveWikiPageTask.

@Test
public void testSaveWikiPageTask() throws Exception {
    final TestEngine engine = TestEngine.build(with("jspwiki.lucene.initialdelay", "0"), with("jspwiki.lucene.indexdelay", "1"));
    final String pageName = "TestSaveWikiPageTestPage";
    final Page page = Wiki.contents().page(engine, pageName);
    engine.saveText(pageName, "initial text on first revision");
    final Context context = Wiki.context().create(engine, engine.newHttpRequest(), page);
    final SaveWikiPageTask task = new SaveWikiPageTask();
    task.setWorkflow(1, new HashMap<>());
    task.getWorkflowContext().put(WorkflowManager.WF_WP_SAVE_FACT_PROPOSED_TEXT, "correct horse battery staple");
    final Collection<SearchResult> res = new ArrayList<>();
    Assertions.assertEquals(Outcome.STEP_COMPLETE, task.execute(context));
    Awaitility.await("ensure page gets indexed").until(findsResultsFor(context, res, "horse"));
    Assertions.assertEquals(1, res.size(), "no pages found");
    Assertions.assertEquals(pageName, res.iterator().next().getPage().getName(), "page");
}
Also used : Context(org.apache.wiki.api.core.Context) ArrayList(java.util.ArrayList) Page(org.apache.wiki.api.core.Page) SearchResult(org.apache.wiki.api.search.SearchResult) TestEngine(org.apache.wiki.TestEngine) Test(org.junit.jupiter.api.Test)

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