Search in sources :

Example 31 with Page

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

the class NextVersionTag method doWikiStartTag.

public final int doWikiStartTag() throws IOException {
    final Page page = m_wikiContext.getPage();
    int version = page.getVersion();
    if (version != WikiProvider.LATEST_VERSION) {
        version++;
    }
    pageContext.getOut().print(version);
    return SKIP_BODY;
}
Also used : Page(org.apache.wiki.api.core.Page)

Example 32 with Page

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

the class PageDateTag method doWikiStartTag.

public final int doWikiStartTag() throws IOException {
    final Page page = m_wikiContext.getPage();
    if (page != null) {
        final Date d = page.getLastModified();
        // Date may be null if the page does not exist.
        if (d != null) {
            final SimpleDateFormat fmt;
            if (m_format == null) {
                fmt = Preferences.getDateFormat(m_wikiContext, TimeFormat.DATETIME);
            } else {
                fmt = new SimpleDateFormat(m_format);
            }
            pageContext.getOut().write(fmt.format(d));
        } else {
            pageContext.getOut().write("<never>");
        }
    }
    return SKIP_BODY;
}
Also used : Page(org.apache.wiki.api.core.Page) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date)

Example 33 with Page

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

the class PageInfoLinkTag method doWikiStartTag.

@Override
public final int doWikiStartTag() throws IOException {
    final Engine engine = m_wikiContext.getEngine();
    String pageName = m_pageName;
    if (m_pageName == null) {
        final Page p = m_wikiContext.getPage();
        if (p != null) {
            pageName = p.getName();
        } else {
            return SKIP_BODY;
        }
    }
    if (engine.getManager(PageManager.class).wikiPageExists(pageName)) {
        final JspWriter out = pageContext.getOut();
        final String url = m_wikiContext.getURL(ContextEnum.PAGE_INFO.getRequestContext(), pageName);
        switch(m_format) {
            case ANCHOR:
                out.print("<a class=\"pageinfo\" href=\"" + url + "\" accesskey=\"" + m_accesskey + "\" title=\"" + m_title + "\">");
                break;
            case URL:
                out.print(url);
                break;
        }
        return EVAL_BODY_INCLUDE;
    }
    return SKIP_BODY;
}
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 34 with Page

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

the class PageSizeTag method doWikiStartTag.

@Override
public final int doWikiStartTag() throws IOException {
    final Engine engine = m_wikiContext.getEngine();
    final Page page = m_wikiContext.getPage();
    try {
        if (page != null) {
            long size = page.getSize();
            if (size == -1 && engine.getManager(PageManager.class).wikiPageExists(page)) {
                // should never happen with attachments
                size = engine.getManager(PageManager.class).getPureText(page.getName(), page.getVersion()).length();
                page.setSize(size);
            }
            pageContext.getOut().write(Long.toString(size));
        }
    } catch (final ProviderException e) {
        log.warn("Providers did not work: ", e);
        pageContext.getOut().write("Error determining page size: " + e.getMessage());
    }
    return SKIP_BODY;
}
Also used : 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 35 with Page

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

the class PermissionTag method checkPermission.

/**
 *  Checks a single permission.
 *
 *  @param permission permission to check for
 *  @return true if granted, false if not
 */
private boolean checkPermission(final String permission) {
    final Session session = m_wikiContext.getWikiSession();
    final Page page = m_wikiContext.getPage();
    final AuthorizationManager mgr = m_wikiContext.getEngine().getManager(AuthorizationManager.class);
    boolean gotPermission = false;
    if (CREATE_GROUPS.equals(permission) || CREATE_PAGES.equals(permission) || EDIT_PREFERENCES.equals(permission) || EDIT_PROFILE.equals(permission) || LOGIN.equals(permission)) {
        gotPermission = mgr.checkPermission(session, new WikiPermission(page.getWiki(), permission));
    } else if (VIEW_GROUP.equals(permission) || EDIT_GROUP.equals(permission) || DELETE_GROUP.equals(permission)) {
        final Command command = m_wikiContext.getCommand();
        gotPermission = false;
        if (command instanceof GroupCommand && command.getTarget() != null) {
            final GroupPrincipal group = (GroupPrincipal) command.getTarget();
            final String groupName = group.getName();
            String action = "view";
            if (EDIT_GROUP.equals(permission)) {
                action = "edit";
            } else if (DELETE_GROUP.equals(permission)) {
                action = "delete";
            }
            gotPermission = mgr.checkPermission(session, new GroupPermission(groupName, action));
        }
    } else if (ALL_PERMISSION.equals(permission)) {
        gotPermission = mgr.checkPermission(session, new AllPermission(m_wikiContext.getEngine().getApplicationName()));
    } else if (page != null) {
        // 
        if (EDIT.equals(permission)) {
            final Page latest = m_wikiContext.getEngine().getManager(PageManager.class).getPage(page.getName());
            if (page.getVersion() != WikiProvider.LATEST_VERSION && latest.getVersion() != page.getVersion()) {
                return false;
            }
        }
        final Permission p = PermissionFactory.getPagePermission(page, permission);
        gotPermission = mgr.checkPermission(session, p);
    }
    return gotPermission;
}
Also used : GroupCommand(org.apache.wiki.ui.GroupCommand) GroupCommand(org.apache.wiki.ui.GroupCommand) Command(org.apache.wiki.api.core.Command) GroupPrincipal(org.apache.wiki.auth.GroupPrincipal) WikiPermission(org.apache.wiki.auth.permissions.WikiPermission) AllPermission(org.apache.wiki.auth.permissions.AllPermission) Permission(java.security.Permission) GroupPermission(org.apache.wiki.auth.permissions.GroupPermission) AllPermission(org.apache.wiki.auth.permissions.AllPermission) Page(org.apache.wiki.api.core.Page) GroupPermission(org.apache.wiki.auth.permissions.GroupPermission) AuthorizationManager(org.apache.wiki.auth.AuthorizationManager) WikiPermission(org.apache.wiki.auth.permissions.WikiPermission) Session(org.apache.wiki.api.core.Session)

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