Search in sources :

Example 76 with Context

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

the class DefaultRenderingManager method getHTML.

/**
 *  Returns the converted HTML of the page's specific version. The version must be a positive integer, otherwise the current
 *  version is returned.
 *
 *  @param pagename WikiName of the page to convert.
 *  @param version Version number to fetch
 *  @return HTML-rendered page text.
 */
@Override
public String getHTML(final String pagename, final int version) {
    final Page page = m_engine.getManager(PageManager.class).getPage(pagename, version);
    final Context context = Wiki.context().create(m_engine, page);
    context.setRequestContext(ContextEnum.PAGE_NONE.getRequestContext());
    return getHTML(context, page);
}
Also used : Context(org.apache.wiki.api.core.Context) PageManager(org.apache.wiki.pages.PageManager) Page(org.apache.wiki.api.core.Page)

Example 77 with Context

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

the class AttachmentsIteratorTag method doStartTag.

/**
 *  {@inheritDoc}
 */
@Override
public final int doStartTag() {
    m_wikiContext = (Context) pageContext.getAttribute(Context.ATTR_CONTEXT, PageContext.REQUEST_SCOPE);
    final Engine engine = m_wikiContext.getEngine();
    final AttachmentManager mgr = engine.getManager(AttachmentManager.class);
    final Page page;
    page = m_wikiContext.getPage();
    if (!mgr.attachmentsEnabled()) {
        return SKIP_BODY;
    }
    try {
        if (page != null && engine.getManager(PageManager.class).wikiPageExists(page)) {
            final List<Attachment> atts = mgr.listAttachments(page);
            if (atts == null) {
                log.debug("No attachments to display.");
                // There are no attachments included
                return SKIP_BODY;
            }
            m_iterator = atts.iterator();
            if (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);
            } else {
                return SKIP_BODY;
            }
        } else {
            return SKIP_BODY;
        }
        return EVAL_BODY_BUFFERED;
    } catch (final ProviderException e) {
        log.fatal("Provider failed while trying to iterator through history", e);
    // FIXME: THrow something.
    }
    return SKIP_BODY;
}
Also used : Context(org.apache.wiki.api.core.Context) PageContext(javax.servlet.jsp.PageContext) ProviderException(org.apache.wiki.api.exceptions.ProviderException) Page(org.apache.wiki.api.core.Page) Attachment(org.apache.wiki.api.core.Attachment) AttachmentManager(org.apache.wiki.attachment.AttachmentManager) Engine(org.apache.wiki.api.core.Engine)

Example 78 with Context

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

the class HistoryIteratorTag 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 Context context = m_wikiContext.clone();
        context.setPage((Page) m_iterator.next());
        pageContext.setAttribute(Context.ATTR_CONTEXT, context, PageContext.REQUEST_SCOPE);
        pageContext.setAttribute(getId(), context.getPage());
        return EVAL_BODY_BUFFERED;
    }
    return SKIP_BODY;
}
Also used : Context(org.apache.wiki.api.core.Context) PageContext(javax.servlet.jsp.PageContext) IOException(java.io.IOException) JspWriter(javax.servlet.jsp.JspWriter)

Example 79 with Context

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

the class PluginBeanTest method testDoGet.

@Test
public void testDoGet() throws WikiException, NotCompliantMBeanException {
    testEngine = new TestEngine(props);
    final Context context = Wiki.context().create(testEngine, Wiki.contents().page(testEngine, "TestPage01"));
    final PluginBean pb = new PluginBean(testEngine);
    final String expectedHtml = "<div>" + "<h4>Plugins</h4>" + "<table border=\"1\">" + "<tr><th>Name</th><th>Alias</th><th>Author</th><th>Notes</th></tr>" + "<tr><td>IfPlugin</td><td>If</td><td>Janne Jalkanen</td><td></td></tr>" + "<tr><td>Note</td><td></td><td>Janne Jalkanen</td><td></td></tr>" + "<tr><td>SamplePlugin</td><td>samplealias</td><td>Janne Jalkanen</td><td></td></tr>" + "<tr><td>SamplePlugin2</td><td>samplealias2</td><td>Janne Jalkanen</td><td></td></tr>" + "</table>" + "</div>";
    Assertions.assertEquals(expectedHtml, pb.doGet(context));
}
Also used : Context(org.apache.wiki.api.core.Context) TestEngine(org.apache.wiki.TestEngine) Test(org.junit.jupiter.api.Test)

Example 80 with Context

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

the class RPCHandlerTest method setUp.

@BeforeEach
public void setUp() throws Exception {
    m_handler = new RPCHandler();
    final Context ctx = Wiki.context().create(m_engine, Wiki.contents().page(m_engine, "Dummy"));
    m_handler.initialize(ctx);
}
Also used : Context(org.apache.wiki.api.core.Context) BeforeEach(org.junit.jupiter.api.BeforeEach)

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