Search in sources :

Example 16 with WikiEngine

use of org.apache.wiki.WikiEngine 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 17 with WikiEngine

use of org.apache.wiki.WikiEngine 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 18 with WikiEngine

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

the class InsertPageTag method doWikiStartTag.

public final int doWikiStartTag() throws IOException, ProviderException {
    WikiEngine engine = m_wikiContext.getEngine();
    WikiPage insertedPage;
    if (m_pageName == null) {
        insertedPage = m_wikiContext.getPage();
        if (!engine.pageExists(insertedPage))
            return SKIP_BODY;
    } else {
        insertedPage = engine.getPage(m_pageName);
    }
    if (insertedPage != null) {
        // FIXME: Do version setting later.
        // page.setVersion( WikiProvider.LATEST_VERSION );
        log.debug("Inserting page " + insertedPage);
        JspWriter out = pageContext.getOut();
        WikiPage oldPage = m_wikiContext.setRealPage(insertedPage);
        switch(m_mode) {
            case HTML:
                out.print(engine.getHTML(m_wikiContext, insertedPage));
                break;
            case PLAIN:
                out.print(engine.getText(m_wikiContext, insertedPage));
                break;
        }
        m_wikiContext.setRealPage(oldPage);
    }
    return SKIP_BODY;
}
Also used : WikiPage(org.apache.wiki.WikiPage) JspWriter(javax.servlet.jsp.JspWriter) WikiEngine(org.apache.wiki.WikiEngine)

Example 19 with WikiEngine

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

the class LinkTag method doEndTag.

public int doEndTag() {
    try {
        if (!m_overrideAbsolute) {
            // TODO: see WikiContext.getURL(); this check needs to be specified somewhere.
            WikiEngine engine = m_wikiContext.getEngine();
            m_absolute = "absolute".equals(engine.getWikiProperties().getProperty(WikiEngine.PROP_REFSTYLE));
        }
        JspWriter out = pageContext.getOut();
        String url = figureOutURL();
        StringBuilder sb = new StringBuilder(20);
        sb.append((m_cssClass != null) ? "class=\"" + m_cssClass + "\" " : "");
        sb.append((m_style != null) ? "style=\"" + m_style + "\" " : "");
        sb.append((m_target != null) ? "target=\"" + m_target + "\" " : "");
        sb.append((m_title != null) ? "title=\"" + m_title + "\" " : "");
        sb.append((m_rel != null) ? "rel=\"" + m_rel + "\" " : "");
        sb.append((m_accesskey != null) ? "accesskey=\"" + m_accesskey + "\" " : "");
        switch(m_format) {
            case URL:
                out.print(url);
                break;
            default:
            case ANCHOR:
                out.print("<a " + sb.toString() + " href=\"" + url + "\">");
                break;
        }
        // of LinkTag, but happens to be the way it has worked previously.
        if (m_bodyContent != null) {
            String linktext = m_bodyContent.getString().trim();
            out.write(linktext);
        }
        // Finish off by closing opened anchor
        if (m_format == ANCHOR)
            out.print("</a>");
    } catch (Exception e) {
        // Yes, we want to catch all exceptions here, including RuntimeExceptions
        log.error("Tag failed", e);
    }
    return EVAL_PAGE;
}
Also used : JspWriter(javax.servlet.jsp.JspWriter) WikiEngine(org.apache.wiki.WikiEngine) JspException(javax.servlet.jsp.JspException) ProviderException(org.apache.wiki.api.exceptions.ProviderException)

Example 20 with WikiEngine

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

the class CheckLockTag method doWikiStartTag.

/**
 *  {@inheritDoc}
 */
@Override
public final int doWikiStartTag() throws IOException, ProviderException {
    WikiEngine engine = m_wikiContext.getEngine();
    WikiPage page = m_wikiContext.getPage();
    if (page != null) {
        PageManager mgr = engine.getPageManager();
        PageLock lock = mgr.getCurrentLock(page);
        HttpSession session = pageContext.getSession();
        PageLock userLock = (PageLock) session.getAttribute("lock-" + page.getName());
        if ((lock != null && m_mode == LockState.LOCKED && lock != userLock) || (lock != null && m_mode == LockState.OWNED && lock == userLock) || (lock == null && m_mode == LockState.NOTLOCKED)) {
            String tid = getId();
            if (tid != null && lock != null) {
                pageContext.setAttribute(tid, lock);
            }
            return EVAL_BODY_INCLUDE;
        }
    }
    return SKIP_BODY;
}
Also used : PageManager(org.apache.wiki.PageManager) HttpSession(javax.servlet.http.HttpSession) WikiPage(org.apache.wiki.WikiPage) PageLock(org.apache.wiki.PageLock) WikiEngine(org.apache.wiki.WikiEngine)

Aggregations

WikiEngine (org.apache.wiki.WikiEngine)67 WikiPage (org.apache.wiki.WikiPage)29 ProviderException (org.apache.wiki.api.exceptions.ProviderException)15 Attachment (org.apache.wiki.attachment.Attachment)10 WikiContext (org.apache.wiki.WikiContext)9 Properties (java.util.Properties)8 JspWriter (javax.servlet.jsp.JspWriter)8 TestEngine (org.apache.wiki.TestEngine)8 Element (org.jdom2.Element)7 IOException (java.io.IOException)5 SimpleDateFormat (java.text.SimpleDateFormat)5 Calendar (java.util.Calendar)5 Date (java.util.Date)5 ResourceBundle (java.util.ResourceBundle)5 PluginException (org.apache.wiki.api.exceptions.PluginException)5 Before (org.junit.Before)5 Principal (java.security.Principal)4 HttpServletRequest (javax.servlet.http.HttpServletRequest)4 InternalWikiException (org.apache.wiki.InternalWikiException)4 ArrayList (java.util.ArrayList)3