jspwiki-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ajaqu...@apache.org
Subject svn commit: r724260 - in /incubator/jspwiki/trunk: ./ src/com/ecyrd/jspwiki/ src/com/ecyrd/jspwiki/action/ src/com/ecyrd/jspwiki/ui/stripes/ src/webdocs/ tests/com/ecyrd/jspwiki/action/
Date Mon, 08 Dec 2008 05:07:42 GMT
Author: ajaquith
Date: Sun Dec  7 21:07:42 2008
New Revision: 724260

URL: http://svn.apache.org/viewvc?rev=724260&view=rev
Log:
Improvements to JSPs and special page handling. JSPs are still not quite working yet, but
the webapp does run, and without too many errors.

Modified:
    incubator/jspwiki/trunk/ChangeLog
    incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/Release.java
    incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/WikiEngine.java
    incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/action/AbstractPageActionBean.java
    incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/action/AttachActionBean.java
    incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/action/CommentActionBean.java
    incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/action/DeleteActionBean.java
    incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/action/ErrorActionBean.java
    incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/action/NoneActionBean.java
    incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/action/PageInfoActionBean.java
    incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/action/RenameActionBean.java
    incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/action/ViewActionBean.java
    incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/action/WikiContextFactory.java
    incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/ui/stripes/GroupTypeConverter.java
    incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/ui/stripes/HandlerInfo.java
    incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/ui/stripes/WikiActionBeanContext.java
    incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/ui/stripes/WikiInterceptor.java
    incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/ui/stripes/WikiPageTypeConverter.java
    incubator/jspwiki/trunk/src/webdocs/Wiki.jsp
    incubator/jspwiki/trunk/tests/com/ecyrd/jspwiki/action/ViewActionBeanTest.java
    incubator/jspwiki/trunk/tests/com/ecyrd/jspwiki/action/WikiContextFactoryTest.java

Modified: incubator/jspwiki/trunk/ChangeLog
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/ChangeLog?rev=724260&r1=724259&r2=724260&view=diff
==============================================================================
--- incubator/jspwiki/trunk/ChangeLog (original)
+++ incubator/jspwiki/trunk/ChangeLog Sun Dec  7 21:07:42 2008
@@ -1,5 +1,11 @@
 2008-12-06  Andrew Jaquith <ajaquith AT apache DOT org>
 
+        * 3.0.0-svn-27
+
+        * Improvements to JSPs and special page handling.
+
+2008-12-06  Andrew Jaquith <ajaquith AT apache DOT org>
+
         * 3.0.0-svn-26
 
         * Small tweaks to JspMigrator to look for, and fix, JSP page import directives

Modified: incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/Release.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/Release.java?rev=724260&r1=724259&r2=724260&view=diff
==============================================================================
--- incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/Release.java (original)
+++ incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/Release.java Sun Dec  7 21:07:42 2008
@@ -77,7 +77,7 @@
      *  <p>
      *  If the build identifier is empty, it is not added.
      */
-    public static final String     BUILD         = "26";
+    public static final String     BUILD         = "27";
     
     /**
      *  This is the generic version string you should use

Modified: incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/WikiEngine.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/WikiEngine.java?rev=724260&r1=724259&r2=724260&view=diff
==============================================================================
--- incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/WikiEngine.java (original)
+++ incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/WikiEngine.java Sun Dec  7 21:07:42 2008
@@ -34,6 +34,8 @@
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 
+import net.sourceforge.stripes.action.RedirectResolution;
+
 import org.apache.commons.lang.time.StopWatch;
 import org.apache.jspwiki.api.FilterException;
 import org.apache.jspwiki.api.WikiException;
@@ -1055,7 +1057,7 @@
      *  <p>If the page is a special page, then returns a direct URL
      *  to that page.  Otherwise returns <code>null</code>.
      *  This method delegates requests to
-     *  {@link com.ecyrd.jspwiki.action.WikiContextFactory#getSpecialPageReference(String)}.
+     *  {@link com.ecyrd.jspwiki.action.WikiContextFactory#getSpecialPageResolution(String)}.
      *  </p>
      *  <p>
      *  Special pages are defined in jspwiki.properties using the jspwiki.specialPage
@@ -1068,7 +1070,8 @@
      */
     public String getSpecialPageReference( String original )
     {
-        return m_contextFactory.getSpecialPageReference( original );
+        RedirectResolution resolution = m_contextFactory.getSpecialPageResolution( original
);
+        return resolution == null ? null : resolution.getUrl( Locale.getDefault() );
     }
 
     /**
@@ -1154,7 +1157,7 @@
 
         try
         {
-            if( m_contextFactory.getSpecialPageReference(page) != null ) return true;
+            if( m_contextFactory.getSpecialPageResolution(page) != null ) return true;
 
             if( getFinalPageName( page ) != null )
             {
@@ -1183,7 +1186,7 @@
     public boolean pageExists( String page, int version )
         throws ProviderException
     {
-        if( m_contextFactory.getSpecialPageReference(page) != null ) return true;
+        if( m_contextFactory.getSpecialPageResolution(page) != null ) return true;
 
         String finalName = getFinalPageName( page );
 

Modified: incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/action/AbstractPageActionBean.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/action/AbstractPageActionBean.java?rev=724260&r1=724259&r2=724260&view=diff
==============================================================================
--- incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/action/AbstractPageActionBean.java (original)
+++ incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/action/AbstractPageActionBean.java Sun Dec
 7 21:07:42 2008
@@ -6,17 +6,19 @@
 
 /**
  * Abstract WikiActionBean subclass used by all ActionBeans that use and process
- * WikiPages using the <code>page</code> request parameter. In particular, this
- * subclass contains special processing logic that sets the page property
- * of the underlying {@link WikiActionBeanContext} when the {@link #setPage(WikiPage)}
- * method is called by the Stripes controller.
+ * WikiPages using the <code>page</code> request parameter. In particular,
+ * this subclass contains special processing logic that sets the page property
+ * of the underlying {@link com.ecyrd.jspwiki.ui.stripes.WikiActionBeanContext}
+ * when the {@link #setPage(WikiPage)} method is called by the Stripes
+ * controller.
  */
 public class AbstractPageActionBean extends AbstractActionBean
 {
     protected WikiPage m_page = null;
-    
+
     /**
      * Returns the WikiPage; defaults to <code>null</code>.
+     * 
      * @return the page
      */
     public WikiPage getPage()
@@ -25,17 +27,17 @@
     }
 
     /**
-     * Sets the WikiPage property for this ActionBean, and also
-     * sets the WikiActionBeanContext's page property to the same
-     * value by calling
+     * Sets the WikiPage property for this ActionBean, and also sets the
+     * WikiActionBeanContext's page property to the same value by calling
      * {@link com.ecyrd.jspwiki.ui.stripes.WikiActionBeanContext#setPage(WikiPage)}.
+     * 
      * @param page the wiki page.
      */
-    @Validate( required = false)
+    @Validate( required = false )
     public void setPage( WikiPage page )
     {
         m_page = page;
         getContext().setPage( page );
     }
-    
+
 }

Modified: incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/action/AttachActionBean.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/action/AttachActionBean.java?rev=724260&r1=724259&r2=724260&view=diff
==============================================================================
--- incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/action/AttachActionBean.java (original)
+++ incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/action/AttachActionBean.java Sun Dec  7
21:07:42 2008
@@ -11,7 +11,7 @@
 import com.ecyrd.jspwiki.ui.stripes.WikiRequestContext;
 
 @UrlBinding("/attach/{page}/{attachment}")
-public class AttachActionBean extends AbstractActionBean
+public class AttachActionBean extends AbstractPageActionBean
 {
     private Attachment m_attachment;
     

Modified: incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/action/CommentActionBean.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/action/CommentActionBean.java?rev=724260&r1=724259&r2=724260&view=diff
==============================================================================
--- incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/action/CommentActionBean.java (original)
+++ incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/action/CommentActionBean.java Sun Dec  7
21:07:42 2008
@@ -9,7 +9,7 @@
 import com.ecyrd.jspwiki.ui.stripes.WikiRequestContext;
 
 @UrlBinding("/Comment.jsp")
-public class CommentActionBean extends AbstractActionBean
+public class CommentActionBean extends AbstractPageActionBean
 {
     @HandlesEvent("comment")
     @HandlerPermission(permissionClass=PagePermission.class, target="${page.name}", actions=PagePermission.COMMENT_ACTION)

Modified: incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/action/DeleteActionBean.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/action/DeleteActionBean.java?rev=724260&r1=724259&r2=724260&view=diff
==============================================================================
--- incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/action/DeleteActionBean.java (original)
+++ incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/action/DeleteActionBean.java Sun Dec  7
21:07:42 2008
@@ -9,7 +9,7 @@
 import com.ecyrd.jspwiki.ui.stripes.WikiRequestContext;
 
 @UrlBinding("/Delete.jsp")
-public class DeleteActionBean extends AbstractActionBean
+public class DeleteActionBean extends AbstractPageActionBean
 {
     @HandlesEvent("delete")
     @HandlerPermission(permissionClass=PagePermission.class, target="${page.name}", actions=PagePermission.DELETE_ACTION)

Modified: incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/action/ErrorActionBean.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/action/ErrorActionBean.java?rev=724260&r1=724259&r2=724260&view=diff
==============================================================================
--- incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/action/ErrorActionBean.java (original)
+++ incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/action/ErrorActionBean.java Sun Dec  7 21:07:42
2008
@@ -5,7 +5,7 @@
 import net.sourceforge.stripes.action.*;
 
 @UrlBinding("/Error.jsp")
-public class ErrorActionBean extends AbstractActionBean
+public class ErrorActionBean extends AbstractPageActionBean
 {
     /**
      * Default event that forwards control to /Message.jsp.

Modified: incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/action/NoneActionBean.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/action/NoneActionBean.java?rev=724260&r1=724259&r2=724260&view=diff
==============================================================================
--- incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/action/NoneActionBean.java (original)
+++ incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/action/NoneActionBean.java Sun Dec  7 21:07:42
2008
@@ -14,7 +14,7 @@
  * 
  * @author Andrew Jaquith
  */
-public class NoneActionBean extends AbstractActionBean
+public class NoneActionBean extends AbstractPageActionBean
 {
     @DefaultHandler
     @HandlesEvent( "none" )

Modified: incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/action/PageInfoActionBean.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/action/PageInfoActionBean.java?rev=724260&r1=724259&r2=724260&view=diff
==============================================================================
--- incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/action/PageInfoActionBean.java (original)
+++ incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/action/PageInfoActionBean.java Sun Dec 
7 21:07:42 2008
@@ -10,7 +10,7 @@
 import com.ecyrd.jspwiki.ui.stripes.WikiRequestContext;
 
 @UrlBinding("/PageInfo.jsp")
-public class PageInfoActionBean extends AbstractActionBean
+public class PageInfoActionBean extends AbstractPageActionBean
 {
     @DefaultHandler
     @HandlesEvent("info")

Modified: incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/action/RenameActionBean.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/action/RenameActionBean.java?rev=724260&r1=724259&r2=724260&view=diff
==============================================================================
--- incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/action/RenameActionBean.java (original)
+++ incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/action/RenameActionBean.java Sun Dec  7
21:07:42 2008
@@ -52,7 +52,7 @@
  * @author Andrew Jaquith
  */
 @UrlBinding( "/Rename.action" )
-public class RenameActionBean extends AbstractActionBean
+public class RenameActionBean extends AbstractPageActionBean
 {
     private static final Logger log = LoggerFactory.getLogger( RenameActionBean.class );
 

Modified: incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/action/ViewActionBean.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/action/ViewActionBean.java?rev=724260&r1=724259&r2=724260&view=diff
==============================================================================
--- incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/action/ViewActionBean.java (original)
+++ incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/action/ViewActionBean.java Sun Dec  7 21:07:42
2008
@@ -42,7 +42,7 @@
      * for one, or a "special page" reference. This method considers
      * special page names from <code>jspwiki.properties</code>, and possible
aliases.
      * To determine whether the page is a special page, this method calls
-     *  {@link com.ecyrd.jspwiki.action.WikiContextFactory#getSpecialPageReference(String)}.
+     *  {@link com.ecyrd.jspwiki.action.WikiContextFactory#getSpecialPageResolution(String)}.
      *  @return a {@link net.sourceforge.stripes.action.RedirectResolution} to the special
      *  page's real URL, if a special page was specified, or <code>null</code>
otherwise
      */
@@ -53,17 +53,26 @@
         ValidationErrors errors = this.getContext().getValidationErrors();
         WikiEngine engine = getContext().getEngine();
         
-        // If user supplied a page that doesn't exist, redirect to the "create pages" ActionBean
+        // The user supplied a page that doesn't exist
         if ( errors.get("page" )!= null )
         {
             for (ValidationError pageParamError : errors.get("page"))
             {
                 if ( "page".equals(pageParamError.getFieldName()) )
                 {
-                    String newPage = pageParamError.getFieldValue();
-                    log.info("User supplied page name '" + newPage + "' that doesn't exist;
redirecting to create pages JSP." );
-                    RedirectResolution resolution = new RedirectResolution(NewPageActionBean.class);
-                    resolution.addParameter("page", newPage);
+                    String pageName = pageParamError.getFieldValue();
+                    
+                    // Is it a special page?
+                    RedirectResolution resolution = getContext().getEngine().getWikiContextFactory().getSpecialPageResolution(
pageName );
+                    if ( resolution != null )
+                    {
+                        return resolution;
+                    }
+
+                    // Ok, it really doesn't exist. Send 'em to the "Create new page?" JSP
+                    log.info("User supplied page name '" + pageName + "' that doesn't exist;
redirecting to create pages JSP." );
+                    resolution = new RedirectResolution(NewPageActionBean.class);
+                    resolution.addParameter("page", pageName);
                     return resolution;
                 }
             }
@@ -95,16 +104,8 @@
             throw new WikiException("Page not supplied, and WikiEngine does not define a
front page! This is highly unusual.") ;
         }
         
-        // Ok, the user supplied a page. That's nice. But is it a special page?
-        String pageName = page.getName();
-        String specialUrl = getContext().getEngine().getWikiContextFactory().getSpecialPageReference(
pageName );
-        if ( specialUrl != null )
-        {
-            return new RedirectResolution( getContext().getViewURL( specialUrl ) );
-        }
-
         // Is there an ALIAS attribute in the wiki pge?
-        specialUrl = (String)page.getAttribute( WikiPage.ALIAS );
+        String specialUrl = (String)page.getAttribute( WikiPage.ALIAS );
         if( specialUrl != null )
         {
             return new RedirectResolution( getContext().getViewURL( specialUrl ) );

Modified: incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/action/WikiContextFactory.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/action/WikiContextFactory.java?rev=724260&r1=724259&r2=724260&view=diff
==============================================================================
--- incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/action/WikiContextFactory.java (original)
+++ incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/action/WikiContextFactory.java Sun Dec 
7 21:07:42 2008
@@ -1,20 +1,22 @@
 package com.ecyrd.jspwiki.action;
 
 import java.lang.reflect.Method;
+import java.net.URI;
+import java.net.URISyntaxException;
 import java.util.*;
 
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 import javax.servlet.jsp.PageContext;
 
-import org.apache.jspwiki.api.WikiException;
-
 import net.sourceforge.stripes.action.RedirectResolution;
 import net.sourceforge.stripes.mock.MockHttpServletRequest;
 import net.sourceforge.stripes.mock.MockHttpServletResponse;
 import net.sourceforge.stripes.mock.MockHttpSession;
 import net.sourceforge.stripes.util.ResolverUtil;
 
+import org.apache.jspwiki.api.WikiException;
+
 import com.ecyrd.jspwiki.*;
 import com.ecyrd.jspwiki.auth.SessionMonitor;
 import com.ecyrd.jspwiki.log.Logger;
@@ -278,27 +280,21 @@
 
     /**
      * <p>
-     * If the page is a special page, this method returns a direct URL to that
-     * page; otherwise, it returns <code>null</code>.
+     * If the page is a special page, this method returns a
+     * {@link net.sourceforge.stripes.action.RedirectResolution} for that page;
+     * otherwise, it returns <code>null</code>.
      * </p>
      * <p>
-     * Special pages are non-existant references to other pages. For example,
+     * Special pages are non-existent references to other pages. For example,
      * you could define a special page reference "RecentChanges" which would
      * always be redirected to "RecentChanges.jsp" instead of trying to find a
      * Wiki page called "RecentChanges".
      * </p>
      * TODO: fix this algorithm
      */
-    public final String getSpecialPageReference( String page )
+    public final RedirectResolution getSpecialPageResolution( String page )
     {
-        RedirectResolution resolution = m_specialRedirects.get( page );
-
-        if( resolution != null )
-        {
-            return resolution.getUrl( Locale.getDefault() );
-        }
-
-        return null;
+        return m_specialRedirects.get( page );
     }
 
     /**
@@ -450,7 +446,28 @@
                 if( specialPage != null && redirectUrl != null )
                 {
                     specialPage = specialPage.trim();
+                    
+                    // Parse the special page
                     redirectUrl = redirectUrl.trim();
+                    try
+                    {
+                        URI uri = new URI( redirectUrl );
+                        if ( uri.getAuthority() == null )
+                        {
+                            // No http:// ftp:// or other authority, so it must be relative
to webapp /
+                            if ( !redirectUrl.startsWith( "/" ) )
+                            {
+                                redirectUrl = "/" + redirectUrl;
+                            }
+                        }
+                    }
+                    catch( URISyntaxException e )
+                    {
+                        // The user supplied a STRANGE reference
+                        log.error( "Strange special page reference: " + redirectUrl );
+                    }
+                    
+                    // Add a new RedirectResolution for the special page
                     RedirectResolution resolution = m_specialRedirects.get( specialPage );
                     if( resolution == null )
                     {

Modified: incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/ui/stripes/GroupTypeConverter.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/ui/stripes/GroupTypeConverter.java?rev=724260&r1=724259&r2=724260&view=diff
==============================================================================
--- incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/ui/stripes/GroupTypeConverter.java (original)
+++ incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/ui/stripes/GroupTypeConverter.java Sun Dec
 7 21:07:42 2008
@@ -49,7 +49,7 @@
      * method will add a validation error to the supplied Collection of errors.
      * The error will be of type
      * {@link net.sourceforge.stripes.validation.LocalizableError} and will have
-     * a message key of <code>pageNotFound</code> and a single parameter
+     * a message key of <code>group.doesnotexist</code> and a single parameter
      * (equal to the value passed for <code>groupName</code>).
      * 
      * @param groupName the name of the WikiPage to retrieve
@@ -70,7 +70,7 @@
         }
         catch( NoSuchPrincipalException e )
         {
-            errors.add( new LocalizableError( "groupNotFound", groupName ) );
+            errors.add( new LocalizableError( "group.doesnotexist", groupName ) );
         }
         return group;
     }

Modified: incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/ui/stripes/HandlerInfo.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/ui/stripes/HandlerInfo.java?rev=724260&r1=724259&r2=724260&view=diff
==============================================================================
--- incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/ui/stripes/HandlerInfo.java (original)
+++ incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/ui/stripes/HandlerInfo.java Sun Dec  7 21:07:42
2008
@@ -57,7 +57,10 @@
      * {@link HandlerPermission} annotation to determine the correct Permission
      * needed to execute the event (if supplied). Finally, attempts to determine
      * the name of the wiki request context by looking for a
-     * {@link WikiRequestContext} annotation.
+     * {@link WikiRequestContext} annotation. If the event handler method does
+     * not contain a WikiRequestContext annotation, a default wiki request
+     * context will be assigned, based on the ActionBean name plus "." plus the
+     * method name.
      * 
      * @param beanClass the ActionBean implementation for which event
      *            information should be created
@@ -325,20 +328,36 @@
     }
 
     /**
-     * Returns the Permission required to execute the method in the context of
-     * the supplied WikiActionBean, based on its {@link HandlerPermission}
-     * annotation. Any EL expressions found in the annotated target or actions
-     * are evaluated. Note that this method returns <code>null</code> if no
-     * Permission is required to execute this method, and
-     * <em>callers should check for nulls</code>.
+     * <p>
+     * Returns a dynamic Permission based on the combination of the handler
+     * method's {@link HandlerPermission} annotation and a supplied object,
+     * which is evaluated to populate the Permission target and/or actions. The
+     * object supplied must be an object with standard bean property accessors
+     * and mutators (get/set methods). Any EL expressions found in the
+     * HandlerPermission's target or actions are evaluated against the object.
+     * Note that this method returns <code>null</code> if no HandlerPermission
+     * annotation was supplied for the handler method;
+     * <em>callers should check for nulls</em>.
+     * </p>
+     * <p>
+     * For example, suppose the HandlerPermission annotation for the
+     * <code>view()</code> handler method is
+     * </p>
+     * <blockquote><code>&#064;HandlerPermission(permissionClass=PagePermission.class,
target="${page.qualifiedName}", actions=PagePermission.VIEW_ACTION)</code></blockquote>
+     * <p>
+     * If <code>object</code> is a ViewActionBean whose <code>getPage()</code>
+     * property returns page "Main" in the wiki named "Default", the returned
+     * Permission will be:
+     * </p>
+     * <blockquote><code>PagePermission "Default:Main", "view"</code></blockquote>
      * 
-     * @param actionBean the ActionBean that will be used as the base for any EL
+     * @param object the Object that will be used as the base for any EL
      *            expressions
      * @return the resolved and instantiated Permission
      * @throws ELException if EL expressions cannot be parsed, or of the
      *             Permission itself cannot be instantiated for any reason
      */
-    public Permission getPermission( WikiActionBean actionBean ) throws ELException
+    public Permission getPermission( Object object ) throws ELException
     {
         if( m_permissionClass == null )
         {
@@ -353,7 +372,7 @@
         // Evaluate the target, if it's an expression
         if( m_permissionTargetExpression != null )
         {
-            PropertyExpressionEvaluation evaluation = new PropertyExpressionEvaluation( m_permissionTargetExpression,
actionBean );
+            PropertyExpressionEvaluation evaluation = new PropertyExpressionEvaluation( m_permissionTargetExpression,
object );
             target = (String) evaluation.getValue();
             if( target == null )
             {
@@ -367,7 +386,7 @@
         // Evaluate the actions, if it's an expression
         if( m_permissionActionExpression != null )
         {
-            PropertyExpressionEvaluation evaluation = new PropertyExpressionEvaluation( m_permissionActionExpression,
actionBean );
+            PropertyExpressionEvaluation evaluation = new PropertyExpressionEvaluation( m_permissionActionExpression,
object );
             actions = (String) evaluation.getValue();
             if( actions == null )
             {

Modified: incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/ui/stripes/WikiActionBeanContext.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/ui/stripes/WikiActionBeanContext.java?rev=724260&r1=724259&r2=724260&view=diff
==============================================================================
--- incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/ui/stripes/WikiActionBeanContext.java (original)
+++ incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/ui/stripes/WikiActionBeanContext.java Sun
Dec  7 21:07:42 2008
@@ -86,8 +86,7 @@
     }
 
     /**
-     *  {@inheritDoc}. Also calls {@link DefaultWikiContext#setHttpRequest(HttpServletRequest)}
on
-     *  the DefaultWikiContext delegate.
+     *  {@inheritDoc}.
      */
     @Override
     public void setEventName( String eventName )

Modified: incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/ui/stripes/WikiInterceptor.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/ui/stripes/WikiInterceptor.java?rev=724260&r1=724259&r2=724260&view=diff
==============================================================================
--- incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/ui/stripes/WikiInterceptor.java (original)
+++ incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/ui/stripes/WikiInterceptor.java Sun Dec
 7 21:07:42 2008
@@ -196,11 +196,18 @@
         // Get the resolved ActionBean and event handler method
         WikiActionBean actionBean = (WikiActionBean) context.getActionBean();
         Method handler = context.getHandler();
+        
+        // Make sure we set the WikiContext request context, while we're at it
+        Map<Method, HandlerInfo> eventinfos = HandlerInfo.getHandlerInfoCollection(
actionBean.getClass() );
+        HandlerInfo eventInfo = eventinfos.get( handler );
+        if ( eventInfo != null )
+        {
+            String requestContext = eventInfo.getRequestContext();
+            actionBean.getContext().setRequestContext( requestContext );
+        }
 
         // Does the event handler have a required permission?
         boolean allowed = true;
-        Map<Method, HandlerInfo> handlerInfos = HandlerInfo.getHandlerInfoCollection(
actionBean.getClass() );
-        HandlerInfo eventInfo = handlerInfos.get( handler );
         if( eventInfo != null )
         {
             Permission requiredPermission = eventInfo.getPermission( actionBean );

Modified: incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/ui/stripes/WikiPageTypeConverter.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/ui/stripes/WikiPageTypeConverter.java?rev=724260&r1=724259&r2=724260&view=diff
==============================================================================
--- incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/ui/stripes/WikiPageTypeConverter.java (original)
+++ incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/ui/stripes/WikiPageTypeConverter.java Sun
Dec  7 21:07:42 2008
@@ -48,7 +48,7 @@
      * exist), this method will add a validation error to the supplied
      * Collection of errors and return <code>null</code>. The error will be
      * of type {@link net.sourceforge.stripes.validation.LocalizableError} and
-     * will have a message key of <code>pageNotFound</code> and a single
+     * will have a message key of <code>common.nopage</code> and a single
      * parameter (equal to the value passed for <code>pageName</code>).
      * 
      * @param pageName the name of the WikiPage to retrieve
@@ -69,7 +69,7 @@
                 String finalName = engine.getWikiContextFactory().getFinalPageName( pageName
);
                 if( finalName == null || engine.getPage( finalName ) == null )
                 {
-                    errors.add( new LocalizableError( "pageNotFound", pageName ) );
+                    errors.add( new LocalizableError( "common.nopage", pageName ) );
                 }
             }
             catch( ProviderException e )

Modified: incubator/jspwiki/trunk/src/webdocs/Wiki.jsp
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/src/webdocs/Wiki.jsp?rev=724260&r1=724259&r2=724260&view=diff
==============================================================================
--- incubator/jspwiki/trunk/src/webdocs/Wiki.jsp (original)
+++ incubator/jspwiki/trunk/src/webdocs/Wiki.jsp Sun Dec  7 21:07:42 2008
@@ -18,14 +18,6 @@
     WikiContext wikiContext = WikiContextFactory.findContext( pageContext );
     String pagereq = wikiContext.getPage().getName();
 
-    // Redirect if the request was for a special page
-    String redirect = wiki.getWikiContextFactory().getSpecialPageReference( pagereq );
-    if( redirect != null )
-    {
-        response.sendRedirect( wikiContext.getViewURL( redirect ) );
-        return;
-    }
-    
     StopWatch sw = new StopWatch();
     sw.start();
     WatchDog w = wiki.getCurrentWatchDog();

Modified: incubator/jspwiki/trunk/tests/com/ecyrd/jspwiki/action/ViewActionBeanTest.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/tests/com/ecyrd/jspwiki/action/ViewActionBeanTest.java?rev=724260&r1=724259&r2=724260&view=diff
==============================================================================
--- incubator/jspwiki/trunk/tests/com/ecyrd/jspwiki/action/ViewActionBeanTest.java (original)
+++ incubator/jspwiki/trunk/tests/com/ecyrd/jspwiki/action/ViewActionBeanTest.java Sun Dec
 7 21:07:42 2008
@@ -29,7 +29,7 @@
         }
     }
     
-    public void testActionBean() throws Exception {
+    public void testView() throws Exception {
         // Save page Main
         m_engine.saveText("Test", "This is a test.");
         WikiPage page = m_engine.getPage("Test");
@@ -48,7 +48,7 @@
         assertEquals("/Wiki.action", trip.getDestination() );
     }
     
-    public void testActionBeanNoParameter() throws Exception {
+    public void testViewNoParameter() throws Exception {
         // Save page Main
         m_engine.saveText("Main", "This is the main page.");
         WikiPage page = m_engine.getPage("Main");
@@ -67,6 +67,21 @@
         assertEquals("/Wiki.action", trip.getDestination() );
     }
     
+    public void testSpecialPage() throws Exception {
+        
+        // Execute the request with a 'special page' reference
+        MockRoundtrip trip = m_engine.guestTrip( "/Wiki.action");
+        trip.addParameter( "page","FindPage" );
+        trip.execute("view");
+
+        // ...we should get a null for the 'page' property
+        ViewActionBean bean = trip.getActionBean(ViewActionBean.class);
+        assertEquals( null, bean.getPage() );
+        
+        // ...and the destination should be Search.jsp
+        assertEquals("/Search.jsp", trip.getDestination() );
+    }
+
     public static Test suite()
     {
         return new TestSuite( ViewActionBeanTest.class );

Modified: incubator/jspwiki/trunk/tests/com/ecyrd/jspwiki/action/WikiContextFactoryTest.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/tests/com/ecyrd/jspwiki/action/WikiContextFactoryTest.java?rev=724260&r1=724259&r2=724260&view=diff
==============================================================================
--- incubator/jspwiki/trunk/tests/com/ecyrd/jspwiki/action/WikiContextFactoryTest.java (original)
+++ incubator/jspwiki/trunk/tests/com/ecyrd/jspwiki/action/WikiContextFactoryTest.java Sun
Dec  7 21:07:42 2008
@@ -4,19 +4,24 @@
  */
 
 package com.ecyrd.jspwiki.action;
+import java.util.Locale;
 import java.util.Properties;
 
-import org.apache.jspwiki.api.WikiException;
-
 import junit.framework.Test;
 import junit.framework.TestCase;
 import junit.framework.TestSuite;
+import net.sourceforge.stripes.action.RedirectResolution;
 import net.sourceforge.stripes.mock.MockHttpServletRequest;
 import net.sourceforge.stripes.mock.MockHttpServletResponse;
 import net.sourceforge.stripes.mock.MockHttpSession;
 import net.sourceforge.stripes.mock.MockRoundtrip;
 
-import com.ecyrd.jspwiki.*;
+import org.apache.jspwiki.api.WikiException;
+
+import com.ecyrd.jspwiki.TestEngine;
+import com.ecyrd.jspwiki.WikiContext;
+import com.ecyrd.jspwiki.WikiEngine;
+import com.ecyrd.jspwiki.WikiPage;
 
 public class WikiContextFactoryTest extends TestCase
 {
@@ -153,16 +158,16 @@
     
     public void testSpecialPageReference()
     {
-        String url;
-        url = resolver.getSpecialPageReference( "RecentChanges" );
-        assertEquals( "RecentChanges.jsp", url );
+        RedirectResolution r;
+        r = resolver.getSpecialPageResolution( "RecentChanges" );
+        assertEquals( "RecentChanges.jsp", r.getUrl( Locale.getDefault() ) );
         
-        url = resolver.getSpecialPageReference( "FindPage" );
-        assertEquals( "Search.jsp", url );
+        r = resolver.getSpecialPageResolution( "FindPage" );
+        assertEquals( "Search.jsp", r.getUrl( Locale.getDefault() ) );
         
         // UserPrefs doesn't exist in our test properties
-        url = resolver.getSpecialPageReference( "UserPrefs" );
-        assertNull( url );
+        r = resolver.getSpecialPageResolution( "UserPrefs" );
+        assertNull( r.getUrl( Locale.getDefault() ) );
     }
 
     public static Test suite()



Mime
View raw message