Search in sources :

Example 26 with Page

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

the class SpamFilter method checkPageName.

private void checkPageName(final Context context, final String content, final Change change) throws RedirectException {
    final Page page = context.getPage();
    final String pageName = page.getName();
    final int maxlength = Integer.parseInt(m_pageNameMaxLength);
    if (pageName.length() > maxlength) {
        // 
        // Spam filter has a match.
        // 
        final String uid = log(context, REJECT, REASON_PAGENAME_TOO_LONG + "(" + m_pageNameMaxLength + ")", pageName);
        log.info("SPAM:PageNameTooLong (" + uid + "). The length of the page name is too large (" + pageName.length() + " , limit is " + m_pageNameMaxLength + ")");
        checkStrategy(context, REASON_PAGENAME_TOO_LONG, "Herb says '" + pageName + "' is a bad pageName and I trust Herb! (Incident code " + uid + ")");
    }
}
Also used : Page(org.apache.wiki.api.core.Page)

Example 27 with Page

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

the class DiffLinkTag method doWikiStartTag.

@Override
public final int doWikiStartTag() throws IOException {
    final Engine engine = m_wikiContext.getEngine();
    String pageName = m_pageName;
    if (m_pageName == null) {
        if (m_wikiContext.getPage() != null) {
            pageName = m_wikiContext.getPage().getName();
        } else {
            return SKIP_BODY;
        }
    }
    final JspWriter out = pageContext.getOut();
    int r1;
    int r2;
    // In case the page does not exist, we fail silently.
    if (!engine.getManager(PageManager.class).wikiPageExists(pageName)) {
        return SKIP_BODY;
    }
    if (VER_LATEST.equals(getVersion())) {
        final Page latest = engine.getManager(PageManager.class).getPage(pageName, WikiProvider.LATEST_VERSION);
        if (latest == null) {
            // This may occur if matchEnglishPlurals is on, and we access the wrong page name
            return SKIP_BODY;
        }
        r1 = latest.getVersion();
    } else if (VER_PREVIOUS.equals(getVersion())) {
        r1 = m_wikiContext.getPage().getVersion() - 1;
        r1 = Math.max(r1, 1);
    } else if (VER_CURRENT.equals(getVersion())) {
        r1 = m_wikiContext.getPage().getVersion();
    } else {
        r1 = Integer.parseInt(getVersion());
    }
    if (VER_LATEST.equals(getNewVersion())) {
        final Page latest = engine.getManager(PageManager.class).getPage(pageName, WikiProvider.LATEST_VERSION);
        r2 = latest.getVersion();
    } else if (VER_PREVIOUS.equals(getNewVersion())) {
        r2 = m_wikiContext.getPage().getVersion() - 1;
        r2 = Math.max(r2, 1);
    } else if (VER_CURRENT.equals(getNewVersion())) {
        r2 = m_wikiContext.getPage().getVersion();
    } else {
        r2 = Integer.parseInt(getNewVersion());
    }
    final String url = m_wikiContext.getURL(ContextEnum.PAGE_DIFF.getRequestContext(), pageName, "r1=" + r1 + "&r2=" + r2);
    switch(m_format) {
        case ANCHOR:
            out.print("<a href=\"" + url + "\">");
            break;
        case URL:
            out.print(url);
            break;
    }
    return EVAL_BODY_INCLUDE;
}
Also used : PageManager(org.apache.wiki.pages.PageManager) Page(org.apache.wiki.api.core.Page) JspWriter(javax.servlet.jsp.JspWriter) Engine(org.apache.wiki.api.core.Engine)

Example 28 with Page

use of org.apache.wiki.api.core.Page 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 29 with Page

use of org.apache.wiki.api.core.Page 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 30 with Page

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

the class NoSuchPageTag method doWikiStartTag.

@Override
public int doWikiStartTag() throws IOException, ProviderException {
    final Engine engine = m_wikiContext.getEngine();
    final Page page;
    if (m_pageName == null) {
        page = m_wikiContext.getPage();
    } else {
        page = engine.getManager(PageManager.class).getPage(m_pageName);
    }
    if (page != null && engine.getManager(PageManager.class).wikiPageExists(page.getName(), page.getVersion())) {
        return SKIP_BODY;
    }
    return EVAL_BODY_INCLUDE;
}
Also used : Page(org.apache.wiki.api.core.Page) Engine(org.apache.wiki.api.core.Engine)

Aggregations

Page (org.apache.wiki.api.core.Page)181 PageManager (org.apache.wiki.pages.PageManager)106 Test (org.junit.jupiter.api.Test)71 Context (org.apache.wiki.api.core.Context)46 Engine (org.apache.wiki.api.core.Engine)30 Attachment (org.apache.wiki.api.core.Attachment)27 ProviderException (org.apache.wiki.api.exceptions.ProviderException)22 Date (java.util.Date)21 WikiPage (org.apache.wiki.WikiPage)18 ReferenceManager (org.apache.wiki.references.ReferenceManager)16 RenderingManager (org.apache.wiki.render.RenderingManager)15 AttachmentManager (org.apache.wiki.attachment.AttachmentManager)14 File (java.io.File)11 ArrayList (java.util.ArrayList)10 Calendar (java.util.Calendar)10 Hashtable (java.util.Hashtable)10 IOException (java.io.IOException)9 Vector (java.util.Vector)9 TestEngine (org.apache.wiki.TestEngine)9 PagePermission (org.apache.wiki.auth.permissions.PagePermission)8