Search in sources :

Example 41 with WikiEngine

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

the class BugReportHandler method findNextPage.

/**
 *  Finds a free page name for adding the bug report.  Tries to construct a page,
 *  and if it's found, adds a number to it and tries again.
 */
private synchronized String findNextPage(WikiContext context, String title, String baseName) {
    String basicPageName = ((baseName != null) ? baseName : "Bug") + MarkupParser.cleanLink(title);
    WikiEngine engine = context.getEngine();
    String pageName = basicPageName;
    long lastbug = 2;
    while (engine.pageExists(pageName)) {
        pageName = basicPageName + lastbug++;
    }
    return pageName;
}
Also used : WikiEngine(org.apache.wiki.WikiEngine)

Example 42 with WikiEngine

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

the class UserNameTag method doWikiStartTag.

public final int doWikiStartTag() throws IOException {
    WikiEngine engine = this.m_wikiContext.getEngine();
    WikiSession wikiSession = WikiSession.getWikiSession(engine, (HttpServletRequest) pageContext.getRequest());
    Principal user = wikiSession.getUserPrincipal();
    if (user != null) {
        if (VALID_USER_NAME_PATTERN.matcher(user.getName()).matches()) {
            pageContext.getOut().print(TextUtil.replaceEntities(user.getName()));
        } else {
            pageContext.getOut().print(Preferences.getBundle(m_wikiContext, InternationalizationManager.CORE_BUNDLE).getString("security.user.fullname.invalid"));
        }
    }
    return SKIP_BODY;
}
Also used : WikiSession(org.apache.wiki.WikiSession) WikiEngine(org.apache.wiki.WikiEngine) Principal(java.security.Principal)

Example 43 with WikiEngine

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

the class UserProfileTag method doWikiStartTag.

public final int doWikiStartTag() throws IOException, WikiSecurityException {
    UserManager manager = m_wikiContext.getEngine().getUserManager();
    UserProfile profile = manager.getUserProfile(m_wikiContext.getWikiSession());
    String result = null;
    if (EXISTS.equals(m_prop) || NOT_NEW.equals(m_prop)) {
        return profile.isNew() ? SKIP_BODY : EVAL_BODY_INCLUDE;
    } else if (NEW.equals(m_prop) || NOT_EXISTS.equals(m_prop)) {
        return profile.isNew() ? EVAL_BODY_INCLUDE : SKIP_BODY;
    } else if (CREATED.equals(m_prop) && profile.getCreated() != null) {
        result = profile.getCreated().toString();
    } else if (EMAIL.equals(m_prop)) {
        result = profile.getEmail();
    } else if (FULLNAME.equals(m_prop)) {
        result = profile.getFullname();
    } else if (GROUPS.equals(m_prop)) {
        result = printGroups(m_wikiContext);
    } else if (LOGINNAME.equals(m_prop)) {
        result = profile.getLoginName();
    } else if (MODIFIED.equals(m_prop) && profile.getLastModified() != null) {
        result = profile.getLastModified().toString();
    } else if (ROLES.equals(m_prop)) {
        result = printRoles(m_wikiContext);
    } else if (WIKINAME.equals(m_prop)) {
        result = profile.getWikiName();
        if (result == null) {
            // 
            // Default back to the declared user name
            // 
            WikiEngine engine = this.m_wikiContext.getEngine();
            WikiSession wikiSession = WikiSession.getWikiSession(engine, (HttpServletRequest) pageContext.getRequest());
            Principal user = wikiSession.getUserPrincipal();
            if (user != null) {
                result = user.getName();
            }
        }
    } else if (CHANGE_PASSWORD.equals(m_prop) || CHANGE_LOGIN_NAME.equals(m_prop)) {
        AuthenticationManager authMgr = m_wikiContext.getEngine().getAuthenticationManager();
        if (!authMgr.isContainerAuthenticated()) {
            return EVAL_BODY_INCLUDE;
        }
    } else if (NOT_CHANGE_PASSWORD.equals(m_prop) || NOT_CHANGE_LOGIN_NAME.equals(m_prop)) {
        AuthenticationManager authMgr = m_wikiContext.getEngine().getAuthenticationManager();
        if (authMgr.isContainerAuthenticated()) {
            return EVAL_BODY_INCLUDE;
        }
    }
    if (result != null) {
        pageContext.getOut().print(TextUtil.replaceEntities(result));
    }
    return SKIP_BODY;
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) AuthenticationManager(org.apache.wiki.auth.AuthenticationManager) WikiSession(org.apache.wiki.WikiSession) UserProfile(org.apache.wiki.auth.user.UserProfile) UserManager(org.apache.wiki.auth.UserManager) WikiEngine(org.apache.wiki.WikiEngine) Principal(java.security.Principal) GroupPrincipal(org.apache.wiki.auth.GroupPrincipal)

Example 44 with WikiEngine

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

the class VariableTag method doWikiStartTag.

public final int doWikiStartTag() throws JspException, IOException {
    WikiEngine engine = m_wikiContext.getEngine();
    JspWriter out = pageContext.getOut();
    String msg = null;
    String value = null;
    try {
        value = engine.getVariableManager().getValue(m_wikiContext, getVar());
    } catch (NoSuchVariableException e) {
        msg = "No such variable: " + e.getMessage();
    } catch (IllegalArgumentException e) {
        msg = "Incorrect variable name: " + e.getMessage();
    }
    if (value == null) {
        value = m_default;
    }
    if (value == null) {
        value = msg;
    }
    out.write(TextUtil.replaceEntities(value));
    return SKIP_BODY;
}
Also used : NoSuchVariableException(org.apache.wiki.api.exceptions.NoSuchVariableException) JspWriter(javax.servlet.jsp.JspWriter) WikiEngine(org.apache.wiki.WikiEngine)

Example 45 with WikiEngine

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

the class ParentPageNameTag method doWikiStartTag.

/**
 * {@inheritDoc}
 */
@Override
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(engine.beautifyTitle(((Attachment) page).getParentName()));
        } else {
            String name = page.getName();
            int entrystart = name.indexOf("_blogentry_");
            if (entrystart != -1) {
                name = name.substring(0, entrystart);
            }
            int commentstart = name.indexOf("_comments_");
            if (commentstart != -1) {
                name = name.substring(0, commentstart);
            }
            pageContext.getOut().print(engine.beautifyTitle(name));
        }
    }
    return SKIP_BODY;
}
Also used : WikiPage(org.apache.wiki.WikiPage) Attachment(org.apache.wiki.attachment.Attachment) 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