extract command list with request context, url pattern and content template to its own Enum
diff --git a/jspwiki-api/src/main/java/org/apache/wiki/api/core/ContextEnum.java b/jspwiki-api/src/main/java/org/apache/wiki/api/core/ContextEnum.java
new file mode 100644
index 0000000..800aee6
--- /dev/null
+++ b/jspwiki-api/src/main/java/org/apache/wiki/api/core/ContextEnum.java
@@ -0,0 +1,58 @@
+package org.apache.wiki.api.core;
+
+public enum ContextEnum {
+
+ GROUP_DELETE( "deleteGroup", "%uDeleteGroup.jsp?group=%n", null ),
+ GROUP_EDIT( "editGroup", "%uEditGroup.jsp?group=%n", "EditGroupContent.jsp" ),
+ GROUP_VIEW( "viewGroup", "%uGroup.jsp?group=%n", "GroupContent.jsp" ),
+
+ PAGE_ATTACH( "att", "%uattach/%n", null ),
+ PAGE_COMMENT( "comment", "%uComment.jsp?page=%n", "CommentContent.jsp" ),
+ PAGE_CONFLICT ( "conflict", "%uPageModified.jsp?page=%n", "ConflictContent.jsp" ),
+ PAGE_DELETE( "del", "%uDelete.jsp?page=%n", null ),
+ PAGE_DIFF( "diff", "%uDiff.jsp?page=%n", "DiffContent.jsp" ),
+ PAGE_EDIT( "edit", "%uEdit.jsp?page=%n", "EditContent.jsp" ),
+ PAGE_INFO( "info", "%uPageInfo.jsp?page=%n", "InfoContent.jsp" ),
+ PAGE_NONE( "", "%u%n", null ),
+ PAGE_PREVIEW( "preview", "%uPreview.jsp?page=%n", "PreviewContent.jsp" ),
+ PAGE_RENAME( "rename", "%uRename.jsp?page=%n", "InfoContent.jsp" ),
+ PAGE_RSS( "rss", "%urss.jsp", null ),
+ PAGE_UPLOAD( "upload", "%uUpload.jsp?page=%n", null ),
+ PAGE_VIEW( "view", "%uWiki.jsp?page=%n", "PageContent.jsp" ),
+
+ REDIRECT( "", "%u%n", null ),
+
+ WIKI_ADMIN( "admin", "%uadmin/Admin.jsp", "AdminContent.jsp" ),
+ WIKI_CREATE_GROUP( "createGroup", "%uNewGroup.jsp", "NewGroupContent.jsp" ),
+ WIKI_ERROR( "error", "%uError.jsp", "DisplayMessage.jsp" ),
+ WIKI_FIND( "find", "%uSearch.jsp", "FindContent.jsp" ),
+ WIKI_INSTALL( "install", "%uInstall.jsp", null ),
+ WIKI_LOGIN( "login", "%uLogin.jsp?redirect=%n", "LoginContent.jsp" ),
+ WIKI_LOGOUT( "logout", "%uLogout.jsp", null ),
+ WIKI_MESSAGE( "message", "%uMessage.jsp", "DisplayMessage.jsp" ),
+ WIKI_PREFS( "prefs", "%uUserPreferences.jsp", "PreferencesContent.jsp" ),
+ WIKI_WORKFLOW( "workflow", "%uWorkflow.jsp", "WorkflowContent.jsp" );
+
+ private final String contentTemplate;
+ private final String requestContext;
+ private final String urlPattern;
+
+ ContextEnum( final String requestContext, final String urlPattern, final String contentTemplate ) {
+ this.requestContext = requestContext;
+ this.urlPattern = urlPattern;
+ this.contentTemplate = contentTemplate;
+ }
+
+ public String getContentTemplate() {
+ return contentTemplate;
+ }
+
+ public String getRequestContext() {
+ return requestContext;
+ }
+
+ public String getUrlPattern() {
+ return urlPattern;
+ }
+
+}
diff --git a/jspwiki-main/src/main/java/org/apache/wiki/WikiContext.java b/jspwiki-main/src/main/java/org/apache/wiki/WikiContext.java
index fe537ff..71bc501 100644
--- a/jspwiki-main/src/main/java/org/apache/wiki/WikiContext.java
+++ b/jspwiki-main/src/main/java/org/apache/wiki/WikiContext.java
@@ -21,6 +21,7 @@
import org.apache.log4j.Logger;
import org.apache.wiki.api.core.Command;
import org.apache.wiki.api.core.Context;
+import org.apache.wiki.api.core.ContextEnum;
import org.apache.wiki.api.core.Engine;
import org.apache.wiki.api.core.Page;
import org.apache.wiki.api.core.Session;
@@ -33,7 +34,6 @@
import org.apache.wiki.auth.user.UserDatabase;
import org.apache.wiki.pages.PageManager;
import org.apache.wiki.ui.CommandResolver;
-import org.apache.wiki.ui.GroupCommand;
import org.apache.wiki.ui.Installer;
import org.apache.wiki.ui.PageCommand;
import org.apache.wiki.ui.WikiCommand;
@@ -76,85 +76,85 @@
private Session m_session;
/** User is administering JSPWiki (Install, SecurityConfig). */
- public static final String INSTALL = WikiCommand.INSTALL.getRequestContext();
+ public static final String INSTALL = ContextEnum.WIKI_INSTALL.getRequestContext();
/** The VIEW context - the user just wants to view the page contents. */
- public static final String VIEW = PageCommand.VIEW.getRequestContext();
+ public static final String VIEW = ContextEnum.PAGE_VIEW.getRequestContext();
/** User wants to view or administer workflows. */
- public static final String WORKFLOW = WikiCommand.WORKFLOW.getRequestContext();
+ public static final String WORKFLOW = ContextEnum.WIKI_WORKFLOW.getRequestContext();
/** The EDIT context - the user is editing the page. */
- public static final String EDIT = PageCommand.EDIT.getRequestContext();
+ public static final String EDIT = ContextEnum.PAGE_EDIT.getRequestContext();
/** User is preparing for a login/authentication. */
- public static final String LOGIN = WikiCommand.LOGIN.getRequestContext();
+ public static final String LOGIN = ContextEnum.WIKI_LOGIN.getRequestContext();
/** User is preparing to log out. */
- public static final String LOGOUT = WikiCommand.LOGOUT.getRequestContext();
+ public static final String LOGOUT = ContextEnum.WIKI_LOGOUT.getRequestContext();
/** JSPWiki wants to display a message. */
- public static final String MESSAGE = WikiCommand.MESSAGE.getRequestContext();
+ public static final String MESSAGE = ContextEnum.WIKI_MESSAGE.getRequestContext();
/** User is viewing a DIFF between the two versions of the page. */
- public static final String DIFF = PageCommand.DIFF.getRequestContext();
+ public static final String DIFF = ContextEnum.PAGE_DIFF.getRequestContext();
/** User is viewing page history. */
- public static final String INFO = PageCommand.INFO.getRequestContext();
+ public static final String INFO = ContextEnum.PAGE_INFO.getRequestContext();
/** User is previewing the changes he just made. */
- public static final String PREVIEW = PageCommand.PREVIEW.getRequestContext();
+ public static final String PREVIEW = ContextEnum.PAGE_PREVIEW.getRequestContext();
/** User has an internal conflict, and does quite not know what to do. Please provide some counseling. */
- public static final String CONFLICT = PageCommand.CONFLICT.getRequestContext();
+ public static final String CONFLICT = ContextEnum.PAGE_CONFLICT.getRequestContext();
/** An error has been encountered and the user needs to be informed. */
- public static final String ERROR = WikiCommand.ERROR.getRequestContext();
+ public static final String ERROR = ContextEnum.WIKI_ERROR.getRequestContext();
/** User is uploading something. */
- public static final String UPLOAD = PageCommand.UPLOAD.getRequestContext();
+ public static final String UPLOAD = ContextEnum.PAGE_UPLOAD.getRequestContext();
/** User is commenting something. */
- public static final String COMMENT = PageCommand.COMMENT.getRequestContext();
+ public static final String COMMENT = ContextEnum.PAGE_COMMENT.getRequestContext();
/** User is searching for content. */
- public static final String FIND = WikiCommand.FIND.getRequestContext();
+ public static final String FIND = ContextEnum.WIKI_FIND.getRequestContext();
/** User wishes to create a new group */
- public static final String CREATE_GROUP = WikiCommand.CREATE_GROUP.getRequestContext();
+ public static final String CREATE_GROUP = ContextEnum.WIKI_CREATE_GROUP.getRequestContext();
/** User is deleting an existing group. */
- public static final String DELETE_GROUP = GroupCommand.DELETE_GROUP.getRequestContext();
+ public static final String DELETE_GROUP = ContextEnum.GROUP_DELETE.getRequestContext();
/** User is editing an existing group. */
- public static final String EDIT_GROUP = GroupCommand.EDIT_GROUP.getRequestContext();
+ public static final String EDIT_GROUP = ContextEnum.GROUP_EDIT.getRequestContext();
/** User is viewing an existing group */
- public static final String VIEW_GROUP = GroupCommand.VIEW_GROUP.getRequestContext();
+ public static final String VIEW_GROUP = ContextEnum.GROUP_VIEW.getRequestContext();
/** User is editing preferences */
- public static final String PREFS = WikiCommand.PREFS.getRequestContext();
+ public static final String PREFS = ContextEnum.WIKI_PREFS.getRequestContext();
/** User is renaming a page. */
- public static final String RENAME = PageCommand.RENAME.getRequestContext();
+ public static final String RENAME = ContextEnum.PAGE_RENAME.getRequestContext();
/** User is deleting a page or an attachment. */
- public static final String DELETE = PageCommand.DELETE.getRequestContext();
+ public static final String DELETE = ContextEnum.PAGE_DELETE.getRequestContext();
/** User is downloading an attachment. */
- public static final String ATTACH = PageCommand.ATTACH.getRequestContext();
+ public static final String ATTACH = ContextEnum.PAGE_ATTACH.getRequestContext();
/** RSS feed is being generated. */
- public static final String RSS = PageCommand.RSS.getRequestContext();
+ public static final String RSS = ContextEnum.PAGE_RSS.getRequestContext();
/** This is not a JSPWiki context, use it to access static files. */
- public static final String NONE = PageCommand.NONE.getRequestContext();
+ public static final String NONE = ContextEnum.PAGE_NONE.getRequestContext();
/** Same as NONE; this is just a clarification. */
- public static final String OTHER = PageCommand.OTHER.getRequestContext();
+ public static final String OTHER = ContextEnum.PAGE_NONE.getRequestContext();
/** User is doing administrative things. */
- public static final String ADMIN = WikiCommand.ADMIN.getRequestContext();
+ public static final String ADMIN = ContextEnum.WIKI_ADMIN.getRequestContext();
private static final Logger log = Logger.getLogger( WikiContext.class );
@@ -211,7 +211,7 @@
m_realPage = m_page;
// Special case: retarget any empty 'view' PageCommands to the front page
- if ( PageCommand.VIEW.equals( command ) && command.getTarget() == null ) {
+ if ( ContextEnum.PAGE_VIEW.equals( command ) && command.getTarget() == null ) {
m_command = command.targetedCommand( m_page );
}
@@ -781,7 +781,7 @@
/**
* Looks up and returns a PageCommand based on a supplied WikiPage and HTTP request. First, the appropriate Command is obtained by
- * examining the HTTP request; the default is {@link PageCommand#VIEW}. If the Command is a PageCommand (and it should be, in most
+ * examining the HTTP request; the default is {@link ContextEnum#PAGE_VIEW}. If the Command is a PageCommand (and it should be, in most
* cases), a targeted Command is created using the (non-<code>null</code>) WikiPage as target.
*
* @param engine the wiki engine
@@ -790,7 +790,7 @@
* @return the correct command
*/
protected static Command findCommand( final Engine engine, final HttpServletRequest request, final Page page ) {
- final String defaultContext = PageCommand.VIEW.getRequestContext();
+ final String defaultContext = ContextEnum.PAGE_VIEW.getRequestContext();
Command command = engine.getManager( CommandResolver.class ).findCommand( request, defaultContext );
if ( command instanceof PageCommand && page != null ) {
command = command.targetedCommand( page );
diff --git a/jspwiki-main/src/main/java/org/apache/wiki/ui/GroupCommand.java b/jspwiki-main/src/main/java/org/apache/wiki/ui/GroupCommand.java
index 3379b03..ef390b8 100644
--- a/jspwiki-main/src/main/java/org/apache/wiki/ui/GroupCommand.java
+++ b/jspwiki-main/src/main/java/org/apache/wiki/ui/GroupCommand.java
@@ -19,6 +19,7 @@
package org.apache.wiki.ui;
import org.apache.wiki.api.core.Command;
+import org.apache.wiki.api.core.ContextEnum;
import org.apache.wiki.auth.GroupPrincipal;
import org.apache.wiki.auth.permissions.GroupPermission;
@@ -33,29 +34,30 @@
public final class GroupCommand extends AbstractCommand {
/** GroupCommand for deleting a group. */
- public static final Command DELETE_GROUP = new GroupCommand( "deleteGroup",
- "%uDeleteGroup.jsp?group=%n",
- null,
- null,
- GroupPermission.DELETE_ACTION );
+ public static final Command DELETE_GROUP = new GroupCommand( ContextEnum.GROUP_DELETE,null, GroupPermission.DELETE_ACTION );
/** GroupCommand for editing a group. */
- public static final Command EDIT_GROUP = new GroupCommand( "editGroup",
- "%uEditGroup.jsp?group=%n",
- "EditGroupContent.jsp",
- null,
- GroupPermission.EDIT_ACTION );
+ public static final Command EDIT_GROUP = new GroupCommand( ContextEnum.GROUP_EDIT, null, GroupPermission.EDIT_ACTION );
/** GroupCommand for viewing a group. */
- public static final Command VIEW_GROUP = new GroupCommand( "viewGroup",
- "%uGroup.jsp?group=%n",
- "GroupContent.jsp",
- null,
- GroupPermission.VIEW_ACTION );
+ public static final Command VIEW_GROUP = new GroupCommand( ContextEnum.GROUP_VIEW, null, GroupPermission.VIEW_ACTION );
private final String m_action;
private final Permission m_permission;
+
+ /**
+ * Constructs a new Command with a specified wiki context, URL pattern, type, and content template. The WikiPage for this command is
+ * initialized to <code>null</code>.
+ *
+ * @param currentContext the current context.
+ * @param target the target of this command (a GroupPrincipal representing a Group); may be <code>null</code>
+ * @param action the action used to construct a suitable GroupPermission
+ * @throws IllegalArgumentException if the request content, URL pattern, or type is <code>null</code>
+ */
+ private GroupCommand( final ContextEnum currentContext, final GroupPrincipal target, final String action ) {
+ this( currentContext.getRequestContext(), currentContext.getUrlPattern(), currentContext.getContentTemplate(), target, action );
+ }
/**
* Constructs a new Command with a specified wiki context, URL pattern, type, and content template. The WikiPage for this command is
diff --git a/jspwiki-main/src/main/java/org/apache/wiki/ui/PageCommand.java b/jspwiki-main/src/main/java/org/apache/wiki/ui/PageCommand.java
index 11ce763..36b3a5d 100644
--- a/jspwiki-main/src/main/java/org/apache/wiki/ui/PageCommand.java
+++ b/jspwiki-main/src/main/java/org/apache/wiki/ui/PageCommand.java
@@ -19,6 +19,7 @@
package org.apache.wiki.ui;
import org.apache.wiki.api.core.Command;
+import org.apache.wiki.api.core.ContextEnum;
import org.apache.wiki.api.core.Page;
import org.apache.wiki.auth.permissions.PagePermission;
import org.apache.wiki.auth.permissions.PermissionFactory;
@@ -33,50 +34,37 @@
*/
public final class PageCommand extends AbstractCommand {
- public static final Command ATTACH
- = new PageCommand( "att", "%uattach/%n", null, null, PagePermission.UPLOAD_ACTION );
-
- public static final Command COMMENT
- = new PageCommand( "comment", "%uComment.jsp?page=%n", "CommentContent.jsp", null, PagePermission.COMMENT_ACTION );
-
- public static final Command CONFLICT
- = new PageCommand( "conflict", "%uPageModified.jsp?page=%n", "ConflictContent.jsp", null, PagePermission.VIEW_ACTION );
-
- public static final Command DELETE
- = new PageCommand( "del", "%uDelete.jsp?page=%n", null, null, PagePermission.DELETE_ACTION );
-
- public static final Command DIFF
- = new PageCommand( "diff", "%uDiff.jsp?page=%n", "DiffContent.jsp", null, PagePermission.VIEW_ACTION );
-
- public static final Command EDIT
- = new PageCommand( "edit", "%uEdit.jsp?page=%n", "EditContent.jsp", null, PagePermission.EDIT_ACTION );
-
- public static final Command INFO
- = new PageCommand( "info", "%uPageInfo.jsp?page=%n", "InfoContent.jsp", null, PagePermission.VIEW_ACTION );
-
- public static final Command PREVIEW
- = new PageCommand( "preview", "%uPreview.jsp?page=%n", "PreviewContent.jsp", null, PagePermission.VIEW_ACTION );
-
- public static final Command RENAME
- = new PageCommand( "rename", "%uRename.jsp?page=%n", "InfoContent.jsp", null, PagePermission.RENAME_ACTION );
-
- public static final Command RSS
- = new PageCommand( "rss", "%urss.jsp", null, null, PagePermission.VIEW_ACTION );
-
- public static final Command UPLOAD
- = new PageCommand( "upload", "%uUpload.jsp?page=%n", null, null, PagePermission.UPLOAD_ACTION );
-
- public static final Command VIEW
- = new PageCommand( "view", "%uWiki.jsp?page=%n", "PageContent.jsp", null, PagePermission.VIEW_ACTION );
-
- public static final Command NONE
- = new PageCommand( "", "%u%n", null, null, null );
-
+ public static final Command ATTACH = new PageCommand( ContextEnum.PAGE_ATTACH, null, PagePermission.UPLOAD_ACTION );
+ public static final Command COMMENT = new PageCommand( ContextEnum.PAGE_COMMENT, null, PagePermission.COMMENT_ACTION );
+ public static final Command CONFLICT = new PageCommand( ContextEnum.PAGE_CONFLICT, null, PagePermission.VIEW_ACTION );
+ public static final Command DELETE = new PageCommand( ContextEnum.PAGE_DELETE, null, PagePermission.DELETE_ACTION );
+ public static final Command DIFF = new PageCommand( ContextEnum.PAGE_DIFF, null, PagePermission.VIEW_ACTION );
+ public static final Command EDIT = new PageCommand( ContextEnum.PAGE_EDIT, null, PagePermission.EDIT_ACTION );
+ public static final Command INFO = new PageCommand( ContextEnum.PAGE_INFO, null, PagePermission.VIEW_ACTION );
+ public static final Command PREVIEW = new PageCommand( ContextEnum.PAGE_PREVIEW, null, PagePermission.VIEW_ACTION );
+ public static final Command RENAME = new PageCommand( ContextEnum.PAGE_RENAME, null, PagePermission.RENAME_ACTION );
+ public static final Command RSS = new PageCommand( ContextEnum.PAGE_RSS, null, PagePermission.VIEW_ACTION );
+ public static final Command UPLOAD = new PageCommand( ContextEnum.PAGE_UPLOAD, null, PagePermission.UPLOAD_ACTION );
+ public static final Command VIEW = new PageCommand( ContextEnum.PAGE_VIEW, null, PagePermission.VIEW_ACTION );
+ public static final Command NONE = new PageCommand( ContextEnum.PAGE_NONE, null, null );
public static final Command OTHER = NONE;
private final String m_action;
private final Permission m_permission;
+
+ /**
+ * Constructs a new Command with a specified wiki context, URL pattern, type, and content template. The target for this command is
+ * initialized to <code>null</code>.
+ *
+ * @param currentContext the current context.
+ * @param target the target of the command (a WikiPage); may be <code>null</code>
+ * @param action the action used to construct a suitable PagePermission
+ * @throws IllegalArgumentException if the request content, URL pattern, or type is <code>null</code>
+ */
+ private PageCommand( final ContextEnum currentContext, final Page target, final String action ) {
+ this( currentContext.getRequestContext(), currentContext.getUrlPattern(), currentContext.getContentTemplate(), target, action );
+ }
/**
* Constructs a new Command with a specified wiki context, URL pattern, type, and content template. The target for this command is
diff --git a/jspwiki-main/src/main/java/org/apache/wiki/ui/RedirectCommand.java b/jspwiki-main/src/main/java/org/apache/wiki/ui/RedirectCommand.java
index 2a221f4..bccb1e9 100644
--- a/jspwiki-main/src/main/java/org/apache/wiki/ui/RedirectCommand.java
+++ b/jspwiki-main/src/main/java/org/apache/wiki/ui/RedirectCommand.java
@@ -19,6 +19,7 @@
package org.apache.wiki.ui;
import org.apache.wiki.api.core.Command;
+import org.apache.wiki.api.core.ContextEnum;
import java.security.Permission;
@@ -32,12 +33,22 @@
*/
public final class RedirectCommand extends AbstractCommand {
- public static final Command REDIRECT = new RedirectCommand( "", "%u%n", null, null );
+ public static final Command REDIRECT = new RedirectCommand( ContextEnum.REDIRECT, null );
/**
* Constructs a new Command with a specified wiki context, URL pattern, type, and content template. The WikiPage for this action is
* initialized to <code>null</code>.
*
+ * @param currentContext the current context.
+ * @param target the target of the command
+ * @throws IllegalArgumentException if the request content, URL pattern, or type is <code>null</code>
+ */
+ private RedirectCommand( final ContextEnum currentContext, final String target ) {
+ this( currentContext.getRequestContext(), currentContext.getUrlPattern(), currentContext.getContentTemplate(), target );
+ }
+
+ /**
+ *
* @param requestContext the request context
* @param urlPattern the URL pattern
* @param contentTemplate the content template; may be <code>null</code>
diff --git a/jspwiki-main/src/main/java/org/apache/wiki/ui/WikiCommand.java b/jspwiki-main/src/main/java/org/apache/wiki/ui/WikiCommand.java
index 7ac7cec..acb2eae 100644
--- a/jspwiki-main/src/main/java/org/apache/wiki/ui/WikiCommand.java
+++ b/jspwiki-main/src/main/java/org/apache/wiki/ui/WikiCommand.java
@@ -19,6 +19,7 @@
package org.apache.wiki.ui;
import org.apache.wiki.api.core.Command;
+import org.apache.wiki.api.core.ContextEnum;
import org.apache.wiki.auth.permissions.AllPermission;
import org.apache.wiki.auth.permissions.WikiPermission;
@@ -33,39 +34,43 @@
*/
public final class WikiCommand extends AbstractCommand {
- public static final Command CREATE_GROUP
- = new WikiCommand( "createGroup", "%uNewGroup.jsp", "NewGroupContent.jsp", null, WikiPermission.CREATE_GROUPS_ACTION );
-
- public static final Command ERROR
- = new WikiCommand( "error", "%uError.jsp", "DisplayMessage.jsp", null, null );
-
- public static final Command FIND
- = new WikiCommand( "find", "%uSearch.jsp", "FindContent.jsp", null, null );
-
- public static final Command INSTALL
- = new WikiCommand( "install", "%uInstall.jsp", null, null, null );
-
- public static final Command LOGIN
- = new WikiCommand( "login", "%uLogin.jsp?redirect=%n", "LoginContent.jsp", null, WikiPermission.LOGIN_ACTION );
-
- public static final Command LOGOUT
- = new WikiCommand( "logout", "%uLogout.jsp", null, null, WikiPermission.LOGIN_ACTION );
-
- public static final Command MESSAGE
- = new WikiCommand( "message", "%uMessage.jsp", "DisplayMessage.jsp", null, null );
-
- public static final Command PREFS
- = new WikiCommand( "prefs", "%uUserPreferences.jsp", "PreferencesContent.jsp", null, WikiPermission.EDIT_PROFILE_ACTION );
-
- public static final Command WORKFLOW
- = new WikiCommand( "workflow", "%uWorkflow.jsp", "WorkflowContent.jsp", null, null );
-
- public static final Command ADMIN
- = new WikiCommand( "admin", "%uadmin/Admin.jsp", "AdminContent.jsp", null );
+ public static final Command ADMIN = new WikiCommand( ContextEnum.WIKI_ADMIN, null );
+ public static final Command CREATE_GROUP = new WikiCommand( ContextEnum.WIKI_CREATE_GROUP, null, WikiPermission.CREATE_GROUPS_ACTION );
+ public static final Command ERROR = new WikiCommand( ContextEnum.WIKI_ERROR, null, null );
+ public static final Command FIND = new WikiCommand( ContextEnum.WIKI_FIND, null, null );
+ public static final Command INSTALL = new WikiCommand( ContextEnum.WIKI_INSTALL, null, null );
+ public static final Command LOGIN = new WikiCommand( ContextEnum.WIKI_LOGIN, null, WikiPermission.LOGIN_ACTION );
+ public static final Command LOGOUT = new WikiCommand( ContextEnum.WIKI_LOGOUT, null, WikiPermission.LOGIN_ACTION );
+ public static final Command MESSAGE = new WikiCommand( ContextEnum.WIKI_MESSAGE, null, null );
+ public static final Command PREFS = new WikiCommand( ContextEnum.WIKI_PREFS, null, WikiPermission.EDIT_PROFILE_ACTION );
+ public static final Command WORKFLOW = new WikiCommand( ContextEnum.WIKI_WORKFLOW, null, null );
private final String m_action;
private final Permission m_permission;
+
+ /**
+ * Constructs a new Command with a specified wiki context, URL pattern, type, and content template. The WikiPage for this action is
+ * initialized to <code>null</code>.
+ *
+ * @param currentContext the current context.
+ * @throws IllegalArgumentException if the request content, URL pattern, or type is <code>null</code>
+ */
+ private WikiCommand( final ContextEnum currentContext, final String target ) {
+ this( currentContext.getRequestContext(), currentContext.getUrlPattern(), currentContext.getContentTemplate(), target );
+ }
+
+ /**
+ * Constructs a new Command with a specified wiki context, URL pattern, type, and content template. The WikiPage for this action is
+ * initialized to <code>null</code>.
+ *
+ * @param currentContext the current context.
+ * @param action The action
+ * @throws IllegalArgumentException if the request content, URL pattern, or type is <code>null</code>
+ */
+ private WikiCommand( final ContextEnum currentContext, final String target, final String action ) {
+ this( currentContext.getRequestContext(), currentContext.getUrlPattern(), currentContext.getContentTemplate(), target, action );
+ }
/**
* Constructs a new Command with a specified wiki context, URL pattern, type, and content template. The WikiPage for this action is
@@ -114,7 +119,8 @@
* @return the new targeted command
* @throws IllegalArgumentException if the target is not of the correct type
*/
- @Override public Command targetedCommand( final Object target ) {
+ @Override
+ public Command targetedCommand( final Object target ) {
if ( !( target instanceof String ) ) {
throw new IllegalArgumentException( "Target must non-null and of type String." );
}
@@ -126,14 +132,16 @@
*
* @see org.apache.wiki.api.core.Command#getName()
*/
- @Override public String getName() {
+ @Override
+ public String getName() {
return getJSPFriendlyName();
}
/**
* @see org.apache.wiki.api.core.Command#requiredPermission()
*/
- @Override public Permission requiredPermission() {
+ @Override
+ public Permission requiredPermission() {
return m_permission;
}