Search in sources :

Example 11 with WikiContext

use of org.apache.wiki.WikiContext in project jspwiki by apache.

the class RSSGenerator method getPageDescription.

private String getPageDescription(WikiPage page) {
    StringBuilder buf = new StringBuilder();
    String author = getAuthor(page);
    WikiContext ctx = new WikiContext(m_engine, page);
    if (page.getVersion() > 1) {
        String diff = m_engine.getDiff(ctx, // FIXME: Will fail when non-contiguous versions
        page.getVersion() - 1, page.getVersion());
        buf.append(author + " changed this page on " + page.getLastModified() + ":<br /><hr /><br />");
        buf.append(diff);
    } else {
        buf.append(author + " created this page on " + page.getLastModified() + ":<br /><hr /><br />");
        buf.append(m_engine.getHTML(page.getName()));
    }
    return buf.toString();
}
Also used : WikiContext(org.apache.wiki.WikiContext)

Example 12 with WikiContext

use of org.apache.wiki.WikiContext in project jspwiki by apache.

the class HistoryIteratorTag method doStartTag.

public final int doStartTag() {
    m_wikiContext = (WikiContext) pageContext.getAttribute(WikiTagBase.ATTR_CONTEXT, PageContext.REQUEST_SCOPE);
    WikiEngine engine = m_wikiContext.getEngine();
    WikiPage page;
    page = m_wikiContext.getPage();
    try {
        if (page != null && engine.pageExists(page)) {
            Collection versions = engine.getVersionHistory(page.getName());
            if (versions == null) {
                // There is no history
                return SKIP_BODY;
            }
            m_iterator = versions.iterator();
            if (m_iterator.hasNext()) {
                WikiContext context = (WikiContext) m_wikiContext.clone();
                context.setPage((WikiPage) m_iterator.next());
                pageContext.setAttribute(WikiTagBase.ATTR_CONTEXT, context, PageContext.REQUEST_SCOPE);
                pageContext.setAttribute(getId(), context.getPage());
            } else {
                return SKIP_BODY;
            }
        }
        return EVAL_BODY_BUFFERED;
    } catch (ProviderException e) {
        log.fatal("Provider failed while trying to iterator through history", e);
    // FIXME: THrow something.
    }
    return SKIP_BODY;
}
Also used : WikiContext(org.apache.wiki.WikiContext) ProviderException(org.apache.wiki.api.exceptions.ProviderException) WikiPage(org.apache.wiki.WikiPage) Collection(java.util.Collection) WikiEngine(org.apache.wiki.WikiEngine)

Example 13 with WikiContext

use of org.apache.wiki.WikiContext in project jspwiki by apache.

the class InsertDiffTag method doWikiStartTag.

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

Example 14 with WikiContext

use of org.apache.wiki.WikiContext in project jspwiki by apache.

the class IteratorTag method buildContext.

/**
 *  Arg, I hate globals.
 */
private void buildContext() {
    // 
    // Build a clone of the current context
    // 
    WikiContext context = (WikiContext) m_wikiContext.clone();
    Object o = m_iterator.next();
    if (o instanceof WikiPage)
        context.setPage((WikiPage) o);
    // 
    // Push it to the iterator stack, and set the id.
    // 
    pageContext.setAttribute(WikiTagBase.ATTR_CONTEXT, context, PageContext.REQUEST_SCOPE);
    pageContext.setAttribute(getId(), o);
}
Also used : WikiContext(org.apache.wiki.WikiContext) WikiPage(org.apache.wiki.WikiPage)

Example 15 with WikiContext

use of org.apache.wiki.WikiContext in project jspwiki by apache.

the class AttachmentsIteratorTag method doAfterBody.

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

Aggregations

WikiContext (org.apache.wiki.WikiContext)90 WikiPage (org.apache.wiki.WikiPage)63 Test (org.junit.Test)40 TestEngine (org.apache.wiki.TestEngine)11 StringReader (java.io.StringReader)9 WikiEngine (org.apache.wiki.WikiEngine)9 ProviderException (org.apache.wiki.api.exceptions.ProviderException)8 IOException (java.io.IOException)7 InputStream (java.io.InputStream)7 Before (org.junit.Before)7 BufferedReader (java.io.BufferedReader)6 StringWriter (java.io.StringWriter)6 Collection (java.util.Collection)6 InputStreamReader (java.io.InputStreamReader)5 Date (java.util.Date)5 LinkCollector (org.apache.wiki.LinkCollector)5 Attachment (org.apache.wiki.attachment.Attachment)5 Properties (java.util.Properties)4 MockHttpServletRequest (net.sourceforge.stripes.mock.MockHttpServletRequest)4 WikiDocument (org.apache.wiki.parser.WikiDocument)4