You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jspwiki.apache.org by aj...@apache.org on 2010/02/12 05:36:09 UTC

svn commit: r909225 - in /incubator/jspwiki/trunk/src/java/org/apache/wiki: action/ ui/stripes/

Author: ajaquith
Date: Fri Feb 12 04:36:08 2010
New Revision: 909225

URL: http://svn.apache.org/viewvc?rev=909225&view=rev
Log:
Introduced TemplateResolution, which forwards the user to the appropriate resource in /templates/<template>. It replaces the use of ForwardResolution in most of the ActionBeans. For example, to forward to a template JSP ("display JSP"), you'd do this: new TemplateResolution( "PageInfo.jsp" ). JSPWiki will figure out where the template JSP actually is, and forward to the correct path.

Added:
    incubator/jspwiki/trunk/src/java/org/apache/wiki/ui/stripes/TemplateResolution.java
Modified:
    incubator/jspwiki/trunk/src/java/org/apache/wiki/action/DiffActionBean.java
    incubator/jspwiki/trunk/src/java/org/apache/wiki/action/EditActionBean.java
    incubator/jspwiki/trunk/src/java/org/apache/wiki/action/GroupActionBean.java
    incubator/jspwiki/trunk/src/java/org/apache/wiki/action/LoginActionBean.java
    incubator/jspwiki/trunk/src/java/org/apache/wiki/action/LostPasswordActionBean.java
    incubator/jspwiki/trunk/src/java/org/apache/wiki/action/MessageActionBean.java
    incubator/jspwiki/trunk/src/java/org/apache/wiki/action/SearchActionBean.java
    incubator/jspwiki/trunk/src/java/org/apache/wiki/action/UserPreferencesActionBean.java
    incubator/jspwiki/trunk/src/java/org/apache/wiki/action/UserProfileActionBean.java
    incubator/jspwiki/trunk/src/java/org/apache/wiki/action/ViewActionBean.java
    incubator/jspwiki/trunk/src/java/org/apache/wiki/action/WorkflowActionBean.java

Modified: incubator/jspwiki/trunk/src/java/org/apache/wiki/action/DiffActionBean.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/src/java/org/apache/wiki/action/DiffActionBean.java?rev=909225&r1=909224&r2=909225&view=diff
==============================================================================
--- incubator/jspwiki/trunk/src/java/org/apache/wiki/action/DiffActionBean.java (original)
+++ incubator/jspwiki/trunk/src/java/org/apache/wiki/action/DiffActionBean.java Fri Feb 12 04:36:08 2010
@@ -10,6 +10,7 @@
 import org.apache.wiki.content.PageNotFoundException;
 import org.apache.wiki.providers.ProviderException;
 import org.apache.wiki.ui.stripes.HandlerPermission;
+import org.apache.wiki.ui.stripes.TemplateResolution;
 import org.apache.wiki.ui.stripes.WikiRequestContext;
 
 /**
@@ -111,9 +112,9 @@
         WikiPage page = getPage();
         if ( page.isAttachment() )
         {
-            return new ForwardResolution( "/templates/default/AttachmentInfo.jsp" );
+            return new TemplateResolution( "AttachmentInfo.jsp" );
         }
-        return new ForwardResolution( "/templates/default/PageInfo.jsp" );
+        return new TemplateResolution( "PageInfo.jsp" );
     }
 
 }

Modified: incubator/jspwiki/trunk/src/java/org/apache/wiki/action/EditActionBean.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/src/java/org/apache/wiki/action/EditActionBean.java?rev=909225&r1=909224&r2=909225&view=diff
==============================================================================
--- incubator/jspwiki/trunk/src/java/org/apache/wiki/action/EditActionBean.java (original)
+++ incubator/jspwiki/trunk/src/java/org/apache/wiki/action/EditActionBean.java Fri Feb 12 04:36:08 2010
@@ -161,12 +161,12 @@
         // Init edit fields and forward to the display JSP
         m_append = true;
         initEditFields( "Commenting on" );
-        return new ForwardResolution( "/templates/default/Comment.jsp" );
+        return new TemplateResolution( "Comment.jsp" );
     }
 
     /**
      * Loads the page's current text, initializes the EditActionBean for
-     * editing, and forwards to the template JSP {@code /templates/default/Edit.jsp}.
+     * editing, and forwards to the template JSP {@code Edit.jsp}.
      * @return always returns a {@link ForwardResolution} to the template JSP
      * @throws ProviderException if the page's current contents cannot
      * be retrieved
@@ -182,7 +182,7 @@
         
         // Init edit fields and forward to the display JSP
         initEditFields( "Editing" );
-        return new ForwardResolution( "/templates/default/Edit.jsp" );
+        return new TemplateResolution( "Edit.jsp" );
     }
 
     /**

Modified: incubator/jspwiki/trunk/src/java/org/apache/wiki/action/GroupActionBean.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/src/java/org/apache/wiki/action/GroupActionBean.java?rev=909225&r1=909224&r2=909225&view=diff
==============================================================================
--- incubator/jspwiki/trunk/src/java/org/apache/wiki/action/GroupActionBean.java (original)
+++ incubator/jspwiki/trunk/src/java/org/apache/wiki/action/GroupActionBean.java Fri Feb 12 04:36:08 2010
@@ -46,10 +46,7 @@
 import org.apache.wiki.auth.permissions.WikiPermission;
 import org.apache.wiki.log.Logger;
 import org.apache.wiki.log.LoggerFactory;
-import org.apache.wiki.ui.stripes.HandlerPermission;
-import org.apache.wiki.ui.stripes.LineDelimitedTypeConverter;
-import org.apache.wiki.ui.stripes.WikiInterceptor;
-import org.apache.wiki.ui.stripes.WikiRequestContext;
+import org.apache.wiki.ui.stripes.*;
 
 /**
  * <p>
@@ -166,7 +163,7 @@
     public Resolution create()
     {
         String groupName = m_group == null ? DEFAULT_NEW_GROUP_NAME : m_group.getName();
-        ForwardResolution r = new ForwardResolution( "/templates/default/EditGroup.jsp" );
+        TemplateResolution r = new TemplateResolution( "EditGroup.jsp" );
         r.addParameter( "group", groupName );
         r.addParameter( "members", getContext().getWikiSession().getUserPrincipal() );
         return r;
@@ -210,7 +207,7 @@
     @WikiRequestContext( "editGroup" )
     public Resolution edit()
     {
-        return new ForwardResolution( "/templates/default/EditGroup.jsp" ).addParameter( "group", m_group.getName() );
+        return new TemplateResolution( "EditGroup.jsp" ).addParameter( "group", m_group.getName() );
     }
 
     public Group getGroup()
@@ -344,7 +341,7 @@
         // User supplied a group, and it already exists
         if( m_group != null && mgr.findRole( m_group.getName() ) != null )
         {
-            return new ForwardResolution( "/templates/default/Group.jsp" );
+            return new TemplateResolution( "Group.jsp" );
         }
 
         // It is an error if we see LocalizableError with key

Modified: incubator/jspwiki/trunk/src/java/org/apache/wiki/action/LoginActionBean.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/src/java/org/apache/wiki/action/LoginActionBean.java?rev=909225&r1=909224&r2=909225&view=diff
==============================================================================
--- incubator/jspwiki/trunk/src/java/org/apache/wiki/action/LoginActionBean.java (original)
+++ incubator/jspwiki/trunk/src/java/org/apache/wiki/action/LoginActionBean.java Fri Feb 12 04:36:08 2010
@@ -41,6 +41,7 @@
 import org.apache.wiki.log.Logger;
 import org.apache.wiki.log.LoggerFactory;
 import org.apache.wiki.ui.stripes.HandlerPermission;
+import org.apache.wiki.ui.stripes.TemplateResolution;
 import org.apache.wiki.ui.stripes.WikiRequestContext;
 
 /**
@@ -247,6 +248,6 @@
         }
 
         // The user hasn't logged in yet, so forward them to the template JSP
-        return new ForwardResolution( "/templates/default/Login.jsp" ).addParameter( "tab", "login" );
+        return new TemplateResolution( "Login.jsp" ).addParameter( "tab", "login" );
     }
 }

Modified: incubator/jspwiki/trunk/src/java/org/apache/wiki/action/LostPasswordActionBean.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/src/java/org/apache/wiki/action/LostPasswordActionBean.java?rev=909225&r1=909224&r2=909225&view=diff
==============================================================================
--- incubator/jspwiki/trunk/src/java/org/apache/wiki/action/LostPasswordActionBean.java (original)
+++ incubator/jspwiki/trunk/src/java/org/apache/wiki/action/LostPasswordActionBean.java Fri Feb 12 04:36:08 2010
@@ -40,6 +40,7 @@
 import org.apache.wiki.auth.user.UserProfile;
 import org.apache.wiki.log.Logger;
 import org.apache.wiki.log.LoggerFactory;
+import org.apache.wiki.ui.stripes.TemplateResolution;
 import org.apache.wiki.util.MailUtil;
 import org.apache.wiki.util.TextUtil;
 
@@ -67,7 +68,7 @@
      * Event handler that resets the user's password, based on the e-mail
      * address returned by {@link #getEmail()}.
      * 
-     * @return always returns <code>null</code>
+     * @return always forwards the user to the template JSP
      */
     @HandlesEvent( "reset" )
     public Resolution reset()
@@ -141,7 +142,7 @@
             errors.addGlobalError( new LocalizableError( messageKey, m_email ) );
         }
 
-        return new ForwardResolution( "/templates/default/Login.jsp" ).addParameter( "tab", "reset" );
+        return new TemplateResolution( "Login.jsp" ).addParameter( "tab", "reset" );
     }
 
     /**
@@ -165,7 +166,7 @@
     @HandlesEvent( "view" )
     public Resolution view()
     {
-        return new ForwardResolution( "/templates/default/Login.jsp" ).addParameter( "tab", "reset" );
+        return new TemplateResolution( "Login.jsp" ).addParameter( "tab", "reset" );
     }
 
 }

Modified: incubator/jspwiki/trunk/src/java/org/apache/wiki/action/MessageActionBean.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/src/java/org/apache/wiki/action/MessageActionBean.java?rev=909225&r1=909224&r2=909225&view=diff
==============================================================================
--- incubator/jspwiki/trunk/src/java/org/apache/wiki/action/MessageActionBean.java (original)
+++ incubator/jspwiki/trunk/src/java/org/apache/wiki/action/MessageActionBean.java Fri Feb 12 04:36:08 2010
@@ -30,6 +30,7 @@
 import org.apache.wiki.WikiContext;
 import org.apache.wiki.log.Logger;
 import org.apache.wiki.log.LoggerFactory;
+import org.apache.wiki.ui.stripes.TemplateResolution;
 import org.apache.wiki.ui.stripes.WikiRequestContext;
 import org.apache.wiki.util.FileUtil;
 
@@ -135,7 +136,7 @@
     @WikiRequestContext( "message" )
     public Resolution message()
     {
-        return new ForwardResolution( "/templates/default/Message.jsp" );
+        return new TemplateResolution( "Message.jsp" );
     }
 
     /**

Modified: incubator/jspwiki/trunk/src/java/org/apache/wiki/action/SearchActionBean.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/src/java/org/apache/wiki/action/SearchActionBean.java?rev=909225&r1=909224&r2=909225&view=diff
==============================================================================
--- incubator/jspwiki/trunk/src/java/org/apache/wiki/action/SearchActionBean.java (original)
+++ incubator/jspwiki/trunk/src/java/org/apache/wiki/action/SearchActionBean.java Fri Feb 12 04:36:08 2010
@@ -36,6 +36,7 @@
 import org.apache.wiki.log.Logger;
 import org.apache.wiki.log.LoggerFactory;
 import org.apache.wiki.search.SearchResult;
+import org.apache.wiki.ui.stripes.TemplateResolution;
 import org.apache.wiki.ui.stripes.WikiRequestContext;
 
 /**
@@ -193,7 +194,7 @@
      * {@link #getResults()} method (and EL expression
      * <code>$wikiActionBean.results</code>).
      * 
-     * @return always returns a {@link ForwardResolution} to
+     * @return always returns a {@link ForwardResolution} to the template JSP
      *         <code>/Search.jsp</code>.
      */
     @DefaultHandler
@@ -202,7 +203,7 @@
     public Resolution search()
     {
         m_results = m_query == null ? NO_RESULTS : doSearch( m_query );
-        return new ForwardResolution( "/templates/default/Search.jsp" );
+        return new TemplateResolution( "Search.jsp" );
     }
     
     /**

Modified: incubator/jspwiki/trunk/src/java/org/apache/wiki/action/UserPreferencesActionBean.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/src/java/org/apache/wiki/action/UserPreferencesActionBean.java?rev=909225&r1=909224&r2=909225&view=diff
==============================================================================
--- incubator/jspwiki/trunk/src/java/org/apache/wiki/action/UserPreferencesActionBean.java (original)
+++ incubator/jspwiki/trunk/src/java/org/apache/wiki/action/UserPreferencesActionBean.java Fri Feb 12 04:36:08 2010
@@ -28,6 +28,10 @@
 import javax.servlet.http.HttpServletResponse;
 import javax.servlet.http.HttpSession;
 
+import net.sourceforge.stripes.action.*;
+import net.sourceforge.stripes.controller.LifecycleStage;
+import net.sourceforge.stripes.validation.Validate;
+
 import org.apache.wiki.WikiContext;
 import org.apache.wiki.auth.login.CookieAssertionLoginModule;
 import org.apache.wiki.auth.permissions.WikiPermission;
@@ -37,12 +41,9 @@
 import org.apache.wiki.ui.EditorManager;
 import org.apache.wiki.ui.TemplateManager;
 import org.apache.wiki.ui.stripes.HandlerPermission;
+import org.apache.wiki.ui.stripes.TemplateResolution;
 import org.apache.wiki.ui.stripes.WikiRequestContext;
 
-import net.sourceforge.stripes.action.*;
-import net.sourceforge.stripes.controller.LifecycleStage;
-import net.sourceforge.stripes.validation.Validate;
-
 
 /**
  */
@@ -340,7 +341,7 @@
 
     /**
      * Handler for displaying user preferences that simply forwards to the
-     * preferences display JSP <code>PreferencesContent.jsp</code>.
+     * preferences template JSP <code>PreferencesContent.jsp</code>.
      * 
      * @return a forward to the content template
      */
@@ -350,6 +351,6 @@
     @WikiRequestContext( "prefs" )
     public Resolution view()
     {
-        return new ForwardResolution( "/templates/default/Preferences.jsp" ).addParameter( "tab", "prefs" );
+        return new TemplateResolution( "Preferences.jsp" ).addParameter( "tab", "prefs" );
     }
 }

Modified: incubator/jspwiki/trunk/src/java/org/apache/wiki/action/UserProfileActionBean.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/src/java/org/apache/wiki/action/UserProfileActionBean.java?rev=909225&r1=909224&r2=909225&view=diff
==============================================================================
--- incubator/jspwiki/trunk/src/java/org/apache/wiki/action/UserProfileActionBean.java (original)
+++ incubator/jspwiki/trunk/src/java/org/apache/wiki/action/UserProfileActionBean.java Fri Feb 12 04:36:08 2010
@@ -38,10 +38,7 @@
 import org.apache.wiki.auth.user.UserProfile;
 import org.apache.wiki.log.Logger;
 import org.apache.wiki.log.LoggerFactory;
-import org.apache.wiki.ui.stripes.HandlerPermission;
-import org.apache.wiki.ui.stripes.SpamProtect;
-import org.apache.wiki.ui.stripes.WikiActionBeanContext;
-import org.apache.wiki.ui.stripes.WikiRequestContext;
+import org.apache.wiki.ui.stripes.*;
 import org.apache.wiki.workflow.DecisionRequiredException;
 
 
@@ -266,7 +263,7 @@
     }
 
     /**
-     * Event handler that forwards the user to <code>/CreateProfile.jsp</code>.
+     * Event handler that forwards the user to the template JSP {@code CreateProfile.jsp}.
      * 
      * @return the resolution
      */
@@ -274,7 +271,7 @@
     @DontValidate
     public Resolution create()
     {
-        return new ForwardResolution( "/templates/default/CreateProfile.jsp" ).addParameter( "tab", "profile" );
+        return new TemplateResolution( "CreateProfile.jsp" ).addParameter( "tab", "profile" );
     }
 
     /**
@@ -289,7 +286,7 @@
     @WikiRequestContext( "profile" )
     public Resolution view()
     {
-        return new ForwardResolution( "/templates/default/Preferences.jsp" ).addParameter( "tab", "profile" );
+        return new TemplateResolution( "Preferences.jsp" ).addParameter( "tab", "profile" );
     }
 
 }

Modified: incubator/jspwiki/trunk/src/java/org/apache/wiki/action/ViewActionBean.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/src/java/org/apache/wiki/action/ViewActionBean.java?rev=909225&r1=909224&r2=909225&view=diff
==============================================================================
--- incubator/jspwiki/trunk/src/java/org/apache/wiki/action/ViewActionBean.java (original)
+++ incubator/jspwiki/trunk/src/java/org/apache/wiki/action/ViewActionBean.java Fri Feb 12 04:36:08 2010
@@ -48,6 +48,7 @@
 import org.apache.wiki.plugin.PluginManager;
 import org.apache.wiki.providers.ProviderException;
 import org.apache.wiki.ui.stripes.HandlerPermission;
+import org.apache.wiki.ui.stripes.TemplateResolution;
 import org.apache.wiki.ui.stripes.WikiActionBeanContext;
 import org.apache.wiki.ui.stripes.WikiRequestContext;
 
@@ -107,7 +108,7 @@
     }
 
     /**
-     * Handler that forwards to the page information display JSP
+     * Handler that forwards to the template JSP
      * {@code PageInfo.jsp}.
      * 
      * @return a forward to the content template
@@ -116,7 +117,7 @@
     @HandlerPermission( permissionClass = PagePermission.class, target = "${page.path}", actions = PagePermission.VIEW_ACTION )
     public Resolution attachments()
     {
-        return new ForwardResolution( "/templates/default/PageInfo.jsp" ).addParameter( "tab", "attachments" );
+        return new TemplateResolution( "PageInfo.jsp" ).addParameter( "tab", "attachments" );
     }
 
     /**
@@ -154,9 +155,9 @@
         WikiPage page = getPage();
         if ( page.isAttachment() )
         {
-            return new ForwardResolution( "/templates/default/AttachmentInfo.jsp" );
+            return new TemplateResolution( "AttachmentInfo.jsp" );
         }
-        return new ForwardResolution( "/templates/default/PageInfo.jsp" ).addParameter( "tab", "info" );
+        return new TemplateResolution( "PageInfo.jsp" ).addParameter( "tab", "info" );
     }
 
     /**
@@ -294,7 +295,7 @@
 
     /**
      * Default handler that simply forwards the user back to the template JSP
-     * <code>/Wiki.jsp</code>.
+     * <code>Wiki.jsp</code>.
      * 
      * @return a forward to the content template
      */
@@ -306,7 +307,7 @@
     public Resolution view() throws ProviderException
     {
         // Forward to display JSP
-        return new ForwardResolution( "/templates/default/Wiki.jsp" ).addParameter( "tab", "view" );
+        return new TemplateResolution( "Wiki.jsp" ).addParameter( "tab", "view" );
     }
 
     /**

Modified: incubator/jspwiki/trunk/src/java/org/apache/wiki/action/WorkflowActionBean.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/src/java/org/apache/wiki/action/WorkflowActionBean.java?rev=909225&r1=909224&r2=909225&view=diff
==============================================================================
--- incubator/jspwiki/trunk/src/java/org/apache/wiki/action/WorkflowActionBean.java (original)
+++ incubator/jspwiki/trunk/src/java/org/apache/wiki/action/WorkflowActionBean.java Fri Feb 12 04:36:08 2010
@@ -30,6 +30,7 @@
 import org.apache.wiki.WikiEngine;
 import org.apache.wiki.WikiSession;
 import org.apache.wiki.api.WikiException;
+import org.apache.wiki.ui.stripes.TemplateResolution;
 import org.apache.wiki.ui.stripes.WikiRequestContext;
 import org.apache.wiki.workflow.Decision;
 import org.apache.wiki.workflow.DecisionQueue;
@@ -171,13 +172,13 @@
      * Event that the user to the preview display JSP.
      * 
      * @return always returns a forward resolution to the template JSP
-     * {@code /Workflow.jsp}.
+     * {@code Workflow.jsp}.
      */
     @DefaultHandler
     @HandlesEvent( "view" )
     @WikiRequestContext( "workflow" )
     public Resolution view()
     {
-        return new ForwardResolution( "/templates/default/Workflow.jsp" );
+        return new TemplateResolution( "Workflow.jsp" );
     }
 }

Added: incubator/jspwiki/trunk/src/java/org/apache/wiki/ui/stripes/TemplateResolution.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/src/java/org/apache/wiki/ui/stripes/TemplateResolution.java?rev=909225&view=auto
==============================================================================
--- incubator/jspwiki/trunk/src/java/org/apache/wiki/ui/stripes/TemplateResolution.java (added)
+++ incubator/jspwiki/trunk/src/java/org/apache/wiki/ui/stripes/TemplateResolution.java Fri Feb 12 04:36:08 2010
@@ -0,0 +1,55 @@
+package org.apache.wiki.ui.stripes;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import net.sourceforge.stripes.action.OnwardResolution;
+
+import org.apache.wiki.WikiEngine;
+import org.apache.wiki.log.Logger;
+import org.apache.wiki.log.LoggerFactory;
+import org.apache.wiki.ui.TemplateManager;
+
+/**
+ * <p>
+ * Forwards the user to a template resource prefixed by
+ * <code>/templates/<var>template</var>/</code>. If the resource is not found in
+ * the <code>/templates/<var>template</var>/</code> path, the forward will be to
+ * <code>/templates/default</code> instead.
+ * </p>
+ */
+public class TemplateResolution extends OnwardResolution<TemplateResolution>
+{
+    private static final Logger LOG = LoggerFactory.getLogger( TemplateResolution.class ); 
+    
+    /**
+     * Constructs a new TemplateResolution
+     * 
+     * @param resource the path of the resource, relative to
+     *            <code>/templates/<var>template</var>/</code>. {@code resource}
+     *            should <em>not</em> start with a slash.
+     */
+    public TemplateResolution( String resource )
+    {
+        super( resource );
+    }
+
+    public void execute( HttpServletRequest request, HttpServletResponse response ) throws Exception
+    {
+        // Figure out what the resolved template path should be
+        WikiEngine engine = WikiEngine.getInstance( request.getSession().getServletContext(), null );
+        TemplateManager templates = engine.getTemplateManager();
+        String path = templates.getTemplateResources().get( getPath() );
+        if( path == null )
+        {
+            path = "/templates/default/" + path;
+        }
+        setPath( path );
+
+        // Get the URL and forward the user
+        LOG.debug( "Forwarding user to resolved template resource: " + path );
+        String url = this.getUrl( request.getLocale() );
+        request.getRequestDispatcher( url ).forward( request, response );
+    }
+
+}