Search in sources :

Example 41 with WikiPage

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

the class PageDateTag method doWikiStartTag.

public final int doWikiStartTag() throws IOException {
    WikiPage page = m_wikiContext.getPage();
    if (page != null) {
        Date d = page.getLastModified();
        // 
        if (d != null) {
            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 : WikiPage(org.apache.wiki.WikiPage) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date)

Example 42 with WikiPage

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

the class PageInfoLinkTag method doWikiStartTag.

public final int doWikiStartTag() throws IOException {
    WikiEngine engine = m_wikiContext.getEngine();
    String pageName = m_pageName;
    if (m_pageName == null) {
        WikiPage p = m_wikiContext.getPage();
        if (p != null) {
            pageName = p.getName();
        } else {
            return SKIP_BODY;
        }
    }
    if (engine.pageExists(pageName)) {
        JspWriter out = pageContext.getOut();
        String url = m_wikiContext.getURL(WikiContext.INFO, 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 : WikiPage(org.apache.wiki.WikiPage) JspWriter(javax.servlet.jsp.JspWriter) WikiEngine(org.apache.wiki.WikiEngine)

Example 43 with WikiPage

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

the class PageNameTag method doWikiStartTag.

public final int doWikiStartTag() throws IOException {
    WikiEngine engine = m_wikiContext.getEngine();
    WikiPage page = m_wikiContext.getPage();
    if (page != null) {
        if (page instanceof Attachment) {
            pageContext.getOut().print(((Attachment) page).getFileName());
        } else {
            pageContext.getOut().print(engine.beautifyTitle(m_wikiContext.getName()));
        }
    }
    return SKIP_BODY;
}
Also used : WikiPage(org.apache.wiki.WikiPage) Attachment(org.apache.wiki.attachment.Attachment) WikiEngine(org.apache.wiki.WikiEngine)

Example 44 with WikiPage

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

the class PageSizeTag method doWikiStartTag.

public final int doWikiStartTag() throws IOException {
    WikiEngine engine = m_wikiContext.getEngine();
    WikiPage page = m_wikiContext.getPage();
    try {
        if (page != null) {
            long size = page.getSize();
            if (// should never happen with attachments
            size == -1 && engine.pageExists(page)) {
                size = engine.getPureText(page.getName(), page.getVersion()).length();
                page.setSize(size);
            }
            pageContext.getOut().write(Long.toString(size));
        }
    } catch (ProviderException e) {
        log.warn("Providers did not work: ", e);
        pageContext.getOut().write("Error determining page size: " + e.getMessage());
    }
    return SKIP_BODY;
}
Also used : ProviderException(org.apache.wiki.api.exceptions.ProviderException) WikiPage(org.apache.wiki.WikiPage) WikiEngine(org.apache.wiki.WikiEngine)

Example 45 with WikiPage

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

the class PermissionTag method checkPermission.

/**
 *  Checks a single permission.
 *
 *  @param permission
 *  @return true if granted, false if not
 */
private boolean checkPermission(String permission) {
    WikiSession session = m_wikiContext.getWikiSession();
    WikiPage page = m_wikiContext.getPage();
    AuthorizationManager mgr = m_wikiContext.getEngine().getAuthorizationManager();
    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)) {
        Command command = m_wikiContext.getCommand();
        gotPermission = false;
        if (command instanceof GroupCommand && command.getTarget() != null) {
            GroupPrincipal group = (GroupPrincipal) command.getTarget();
            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)) {
            WikiPage latest = m_wikiContext.getEngine().getPage(page.getName());
            if (page.getVersion() != WikiProvider.LATEST_VERSION && latest.getVersion() != page.getVersion()) {
                return false;
            }
        }
        Permission p = PermissionFactory.getPagePermission(page, permission);
        gotPermission = mgr.checkPermission(session, p);
    }
    return gotPermission;
}
Also used : WikiSession(org.apache.wiki.WikiSession) GroupCommand(org.apache.wiki.ui.GroupCommand) Command(org.apache.wiki.ui.Command) GroupCommand(org.apache.wiki.ui.GroupCommand) GroupPrincipal(org.apache.wiki.auth.GroupPrincipal) WikiPage(org.apache.wiki.WikiPage) 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) GroupPermission(org.apache.wiki.auth.permissions.GroupPermission) AuthorizationManager(org.apache.wiki.auth.AuthorizationManager) WikiPermission(org.apache.wiki.auth.permissions.WikiPermission)

Aggregations

WikiPage (org.apache.wiki.WikiPage)186 Test (org.junit.Test)77 WikiContext (org.apache.wiki.WikiContext)63 WikiEngine (org.apache.wiki.WikiEngine)29 Attachment (org.apache.wiki.attachment.Attachment)26 ProviderException (org.apache.wiki.api.exceptions.ProviderException)22 Date (java.util.Date)17 File (java.io.File)16 Collection (java.util.Collection)16 TestEngine (org.apache.wiki.TestEngine)15 Iterator (java.util.Iterator)13 StringReader (java.io.StringReader)9 Hashtable (java.util.Hashtable)9 IOException (java.io.IOException)8 ArrayList (java.util.ArrayList)8 Calendar (java.util.Calendar)8 Vector (java.util.Vector)8 StringWriter (java.io.StringWriter)7 InternalWikiException (org.apache.wiki.InternalWikiException)7 PagePermission (org.apache.wiki.auth.permissions.PagePermission)7