001: /*
002: JSPWiki - a JSP-based WikiWiki clone.
003:
004: Copyright (C) 2001-2002 Janne Jalkanen (Janne.Jalkanen@iki.fi)
005:
006: This program is free software; you can redistribute it and/or modify
007: it under the terms of the GNU Lesser General Public License as published by
008: the Free Software Foundation; either version 2.1 of the License, or
009: (at your option) any later version.
010:
011: This program is distributed in the hope that it will be useful,
012: but WITHOUT ANY WARRANTY; without even the implied warranty of
013: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
014: GNU Lesser General Public License for more details.
015:
016: You should have received a copy of the GNU Lesser General Public License
017: along with this program; if not, write to the Free Software
018: Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
019: */
020: package com.ecyrd.jspwiki.ui;
021:
022: import java.security.Permission;
023:
024: import com.ecyrd.jspwiki.auth.permissions.AllPermission;
025: import com.ecyrd.jspwiki.auth.permissions.WikiPermission;
026:
027: /**
028: * <p>Defines Commands for wiki-wide operations such as creating groups, editing
029: * preferences and profiles, and logging in/out. WikiCommands can be combined
030: * with Strings (representing the name of a wiki instance) to produce
031: * targeted Commands.</p>
032: * <p>This class is not <code>final</code>; it may be extended in
033: * the future.</p>
034: * @see com.ecyrd.jspwiki.WikiEngine#getApplicationName().
035: * @author Andrew Jaquith
036: * @since 2.4.22
037: */
038: public final class WikiCommand extends AbstractCommand {
039:
040: public static final Command CREATE_GROUP = new WikiCommand(
041: "createGroup", "%uNewGroup.jsp", "NewGroupContent.jsp",
042: null, WikiPermission.CREATE_GROUPS_ACTION);
043:
044: public static final Command ERROR = new WikiCommand("error",
045: "%uError.jsp", "DisplayMessage.jsp", null, null);
046:
047: public static final Command FIND = new WikiCommand("find",
048: "%uSearch.jsp", "FindContent.jsp", null, null);
049:
050: public static final Command INSTALL = new WikiCommand("install",
051: "%uInstall.jsp", null, null, null);
052:
053: public static final Command LOGIN = new WikiCommand("login",
054: "%uLogin.jsp?redirect=%n", "LoginContent.jsp", null,
055: WikiPermission.LOGIN_ACTION);
056:
057: public static final Command LOGOUT = new WikiCommand("logout",
058: "%uLogout.jsp", null, null, WikiPermission.LOGIN_ACTION);
059:
060: public static final Command MESSAGE = new WikiCommand("message",
061: "%uMessage.jsp", "DisplayMessage.jsp", null, null);
062:
063: public static final Command PREFS = new WikiCommand("prefs",
064: "%uUserPreferences.jsp", "PreferencesContent.jsp", null,
065: WikiPermission.EDIT_PROFILE_ACTION);
066:
067: public static final Command WORKFLOW = new WikiCommand("workflow",
068: "%uWorkflow.jsp", "WorkflowContent.jsp", null, null);
069:
070: public static final Command ADMIN = new WikiCommand("admin",
071: "%uadmin/Admin.jsp", "AdminContent.jsp", null);
072:
073: private final String m_action;
074:
075: private final Permission m_permission;
076:
077: /**
078: * Constructs a new Command with a specified wiki context, URL pattern,
079: * type, and content template. The WikiPage for this action is initialized
080: * to <code>null</code>.
081: * @param requestContext the request context
082: * @param urlPattern the URL pattern
083: * @param type the type
084: * @param contentTemplate the content template; may be <code>null</code>
085: * @param action The action
086: * @return IllegalArgumentException if the request content, URL pattern, or
087: * type is <code>null</code>
088: */
089: private WikiCommand(String requestContext, String urlPattern,
090: String contentTemplate, String target, String action) {
091: super (requestContext, urlPattern, contentTemplate, target);
092: m_action = action;
093: if (target == null || m_action == null) {
094: m_permission = null;
095: } else {
096: m_permission = new WikiPermission(target, action);
097: }
098: }
099:
100: /**
101: * Constructs an admin command.
102: *
103: * @param requestContext
104: * @param urlPattern
105: * @param contentTemplate
106: */
107: private WikiCommand(String requestContext, String urlPattern,
108: String contentTemplate, String target) {
109: super (requestContext, urlPattern, contentTemplate, target);
110: m_action = null;
111:
112: m_permission = new AllPermission(target);
113: }
114:
115: /**
116: * Creates and returns a targeted Command by combining a wiki
117: * (a String) with this Command. The supplied <code>target</code>
118: * object must be non-<code>null</code> and of type String.
119: * @param target the name of the wiki to combine into the current Command
120: * @return the new targeted command
121: * @throws IllegalArgumentException if the target is not of the correct type
122: */
123: public final Command targetedCommand(Object target) {
124: if (!(target != null && target instanceof String)) {
125: throw new IllegalArgumentException(
126: "Target must non-null and of type String.");
127: }
128: return new WikiCommand(getRequestContext(), getURLPattern(),
129: getContentTemplate(), (String) target, m_action);
130: }
131:
132: /**
133: * Always returns the "friendly" JSP name.
134: * @see com.ecyrd.jspwiki.ui.Command#getName()
135: */
136: public final String getName() {
137: return getJSPFriendlyName();
138: }
139:
140: /**
141: * @see com.ecyrd.jspwiki.ui.Command#requiredPermission()
142: */
143: public final Permission requiredPermission() {
144: return m_permission;
145: }
146: }
|