Search in sources :

Example 6 with Context

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

the class JSPWikiMarkupParser method getCleanTranslator.

/**
 *  Does a lazy init.  Otherwise, we would get into a situation where HTMLRenderer would try and boot a TranslatorReader before
 *  the TranslatorReader it is contained by is up.
 */
private JSPWikiMarkupParser getCleanTranslator() {
    if (m_cleanTranslator == null) {
        final Context dummyContext = Wiki.context().create(m_engine, m_context.getHttpRequest(), m_context.getPage());
        m_cleanTranslator = new JSPWikiMarkupParser(dummyContext, null);
        m_cleanTranslator.m_allowHTML = true;
    }
    return m_cleanTranslator;
}
Also used : Context(org.apache.wiki.api.core.Context)

Example 7 with Context

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

the class RPCServlet method doPost.

/**
 *  Handle HTTP POST.  This is an XML-RPC call, and we'll just forward the query to an XmlRpcServer.
 */
@Override
public void doPost(final HttpServletRequest request, final HttpServletResponse response) throws ServletException {
    log.debug("Received POST to RPCServlet");
    try {
        final Context ctx = Wiki.context().create(m_engine, request, ContextEnum.PAGE_NONE.getRequestContext());
        final XmlRpcContext xmlrpcContext = new WikiXmlRpcContext(m_xmlrpcServer.getHandlerMapping(), ctx);
        final byte[] result = m_xmlrpcServer.execute(request.getInputStream(), xmlrpcContext);
        // 
        // I think it's safe to write the output as UTF-8: The XML-RPC standard never creates other than USASCII
        // (which is UTF-8 compatible), and our special UTF-8 hack just creates UTF-8.  So in all cases our butt
        // should be covered.
        // 
        response.setContentType("text/xml; charset=utf-8");
        response.setContentLength(result.length);
        final OutputStream out = response.getOutputStream();
        out.write(result);
        out.flush();
    // log.debug("Result = "+new String(result) );
    } catch (final IOException e) {
        throw new ServletException("Failed to build RPC result", e);
    }
}
Also used : Context(org.apache.wiki.api.core.Context) XmlRpcContext(org.apache.xmlrpc.XmlRpcContext) ServletException(javax.servlet.ServletException) XmlRpcContext(org.apache.xmlrpc.XmlRpcContext) OutputStream(java.io.OutputStream) IOException(java.io.IOException)

Example 8 with Context

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

the class MetaWeblogHandler method newPost.

/**
 *  Adds a new post to the blog.
 *
 *  @param blogid The id of the blog.
 *  @param username The username to use
 *  @param password The password
 *  @param content As per Metaweblogapi contract
 *  @param publish This parameter is ignored for JSPWiki.
 *  @return Returns an empty string
 *  @throws XmlRpcException If something goes wrong
 */
public String newPost(final String blogid, final String username, final String password, final Hashtable<String, Object> content, final boolean publish) throws XmlRpcException {
    log.info("metaWeblog.newPost() called");
    final Engine engine = m_context.getEngine();
    final Page page = engine.getManager(PageManager.class).getPage(blogid);
    checkPermissions(page, username, password, "createPages");
    try {
        final WeblogEntryPlugin plugin = new WeblogEntryPlugin();
        final String pageName = plugin.getNewEntryPage(engine, blogid);
        final Page entryPage = Wiki.contents().page(engine, pageName);
        entryPage.setAuthor(username);
        final Context context = Wiki.context().create(engine, entryPage);
        final StringBuilder text = new StringBuilder();
        text.append("!").append(content.get("title"));
        text.append("\n\n");
        text.append(content.get("description"));
        log.debug("Writing entry: " + text);
        engine.getManager(PageManager.class).saveText(context, text.toString());
    } catch (final Exception e) {
        log.error("Failed to create weblog entry", e);
        throw new XmlRpcException(0, "Failed to create weblog entry: " + e.getMessage());
    }
    // FIXME:
    return "";
}
Also used : Context(org.apache.wiki.api.core.Context) PageManager(org.apache.wiki.pages.PageManager) Page(org.apache.wiki.api.core.Page) WeblogEntryPlugin(org.apache.wiki.plugin.WeblogEntryPlugin) Engine(org.apache.wiki.api.core.Engine) XmlRpcException(org.apache.xmlrpc.XmlRpcException) WikiSecurityException(org.apache.wiki.auth.WikiSecurityException) XmlRpcException(org.apache.xmlrpc.XmlRpcException)

Example 9 with Context

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

the class HistoryIteratorTag 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 Page page = m_wikiContext.getPage();
    try {
        if (page != null && engine.getManager(PageManager.class).wikiPageExists(page)) {
            final List<Page> versions = engine.getManager(PageManager.class).getVersionHistory(page.getName());
            if (versions == null) {
                // There is no history
                return SKIP_BODY;
            }
            m_iterator = versions.iterator();
            if (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());
            } 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) PageManager(org.apache.wiki.pages.PageManager) ProviderException(org.apache.wiki.api.exceptions.ProviderException) Page(org.apache.wiki.api.core.Page) Engine(org.apache.wiki.api.core.Engine)

Example 10 with Context

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

the class InsertDiffTag method doWikiStartTag.

/**
 * {@inheritDoc}
 */
@Override
public final int doWikiStartTag() throws IOException {
    final Engine engine = m_wikiContext.getEngine();
    final Context ctx;
    if (m_pageName == null) {
        ctx = m_wikiContext;
    } else {
        ctx = m_wikiContext.clone();
        ctx.setPage(engine.getManager(PageManager.class).getPage(m_pageName));
    }
    final Integer vernew = (Integer) pageContext.getAttribute(ATTR_NEWVERSION, PageContext.REQUEST_SCOPE);
    final Integer verold = (Integer) pageContext.getAttribute(ATTR_OLDVERSION, PageContext.REQUEST_SCOPE);
    log.debug("Request diff between version " + verold + " and " + vernew);
    if (ctx.getPage() != null) {
        final JspWriter out = pageContext.getOut();
        final String diff = engine.getManager(DifferenceManager.class).getDiff(ctx, vernew.intValue(), verold.intValue());
        if (diff.isEmpty()) {
            return EVAL_BODY_INCLUDE;
        }
        out.write(diff);
    }
    return SKIP_BODY;
}
Also used : Context(org.apache.wiki.api.core.Context) PageContext(javax.servlet.jsp.PageContext) DifferenceManager(org.apache.wiki.diff.DifferenceManager) JspWriter(javax.servlet.jsp.JspWriter) Engine(org.apache.wiki.api.core.Engine)

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