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 2008/08/03 14:12:49 UTC
svn commit: r682139 [5/6] - in
/incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/src/com/ecyrd/jspwiki:
./ action/
Copied: incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/src/com/ecyrd/jspwiki/action/PrincipalTypeConverter.java (from r643690, incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/src/com/ecyrd/jspwiki/ui/PrincipalTypeConverter.java)
URL: http://svn.apache.org/viewvc/incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/src/com/ecyrd/jspwiki/action/PrincipalTypeConverter.java?p2=incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/src/com/ecyrd/jspwiki/action/PrincipalTypeConverter.java&p1=incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/src/com/ecyrd/jspwiki/ui/PrincipalTypeConverter.java&r1=643690&r2=682139&rev=682139&view=diff
==============================================================================
--- incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/src/com/ecyrd/jspwiki/ui/PrincipalTypeConverter.java (original)
+++ incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/src/com/ecyrd/jspwiki/action/PrincipalTypeConverter.java Sun Aug 3 05:12:47 2008
@@ -12,7 +12,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.ecyrd.jspwiki.ui;
+package com.ecyrd.jspwiki.action;
import java.security.Principal;
import java.util.Collection;
Modified: incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/src/com/ecyrd/jspwiki/action/RSSActionBean.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/src/com/ecyrd/jspwiki/action/RSSActionBean.java?rev=682139&r1=682138&r2=682139&view=diff
==============================================================================
--- incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/src/com/ecyrd/jspwiki/action/RSSActionBean.java (original)
+++ incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/src/com/ecyrd/jspwiki/action/RSSActionBean.java Sun Aug 3 05:12:47 2008
@@ -9,35 +9,33 @@
import com.ecyrd.jspwiki.WikiPage;
import com.ecyrd.jspwiki.auth.permissions.PagePermission;
-@WikiRequestContext("rss")
-@UrlBinding("/rss.action")
+@UrlBinding( "/rss.jsp" )
public class RSSActionBean extends WikiContext
{
/**
* Retrieves a new RSSActionBean for the given WikiPage.
*
- * @param engine
- * The WikiEngine that is handling the request.
- * @param page
- * The WikiPage. If you want to create an RSSActionBean for an older
- * version of a page, you must use this constructor.
+ * @param engine The WikiEngine that is handling the request.
+ * @param page The WikiPage. If you want to create an RSSActionBean for an
+ * older version of a page, you must use this constructor.
*/
- public static RSSActionBean getRSSActionBean(WikiEngine engine, WikiPage page)
+ public static RSSActionBean getRSSActionBean( WikiEngine engine, WikiPage page )
{
- if (engine == null)
+ if( engine == null )
{
- throw new IllegalArgumentException("Parameter engine must not be null.");
+ throw new IllegalArgumentException( "Parameter engine must not be null." );
}
WikiActionBeanContext context = new WikiActionBeanContext();
context.setWikiEngine( engine );
RSSActionBean rssBean = new RSSActionBean();
- rssBean.setContext(context);
- rssBean.setPage(page);
+ rssBean.setContext( context );
+ rssBean.setPage( page );
return rssBean;
}
-
- @HandlesEvent("rss")
- @EventPermission(permissionClass=PagePermission.class, target="${page.qualifiedName}", actions=PagePermission.VIEW_ACTION)
+
+ @HandlesEvent( "rss" )
+ @HandlerPermission( permissionClass = PagePermission.class, target = "${page.name}", actions = PagePermission.VIEW_ACTION )
+ @WikiRequestContext( "rss" )
public Resolution rss()
{
return null;
Modified: incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/src/com/ecyrd/jspwiki/action/RenameActionBean.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/src/com/ecyrd/jspwiki/action/RenameActionBean.java?rev=682139&r1=682138&r2=682139&view=diff
==============================================================================
--- incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/src/com/ecyrd/jspwiki/action/RenameActionBean.java (original)
+++ incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/src/com/ecyrd/jspwiki/action/RenameActionBean.java Sun Aug 3 05:12:47 2008
@@ -48,11 +48,10 @@
*
* @author Andrew Jaquith
*/
-@WikiRequestContext("rename")
-@UrlBinding("/Rename.action")
+@UrlBinding( "/Rename.jsp" )
public class RenameActionBean extends WikiContext
{
- private static final Logger log = Logger.getLogger(RenameActionBean.class);
+ private static final Logger log = Logger.getLogger( RenameActionBean.class );
private boolean m_changeReferences = false;
@@ -86,22 +85,22 @@
* {@link com.ecyrd.jspwiki.WikiException}.
*
* @return a redirection to the renamed wiki page
- * @throws WikiException
- * if the page cannot be renamed
+ * @throws WikiException if the page cannot be renamed
*/
- @HandlesEvent("rename")
- @EventPermission(permissionClass = PagePermission.class, target = "${page.qualifiedName}", actions = PagePermission.RENAME_ACTION)
+ @HandlesEvent( "rename" )
+ @HandlerPermission( permissionClass = PagePermission.class, target = "${page.name}", actions = PagePermission.RENAME_ACTION )
+ @WikiRequestContext( "rename" )
public Resolution rename() throws WikiException
{
WikiEngine engine = this.getEngine();
String renameFrom = getPage().getName();
HttpServletRequest request = getContext().getRequest();
- log.info("Page rename request for page '" + renameFrom + "' to new name '" + m_renameTo + "' from "
- + request.getRemoteAddr() + " by " + request.getRemoteUser());
- String renamedTo = engine.renamePage(this, renameFrom, m_renameTo, m_changeReferences);
- log.info("Page successfully renamed to '" + renamedTo + "'");
- RedirectResolution r = new RedirectResolution(ViewActionBean.class);
- r.addParameter("page", renamedTo);
+ log.info( "Page rename request for page '" + renameFrom + "' to new name '" + m_renameTo + "' from "
+ + request.getRemoteAddr() + " by " + request.getRemoteUser() );
+ String renamedTo = engine.renamePage( this, renameFrom, m_renameTo, m_changeReferences );
+ log.info( "Page successfully renamed to '" + renamedTo + "'" );
+ RedirectResolution r = new RedirectResolution( ViewActionBean.class );
+ r.addParameter( "page", renamedTo );
return r;
}
@@ -110,11 +109,10 @@
* {@link #rename()} handler is executed. If not supplied, defaults to
* <code>false</code>.
*
- * @param changeReferences
- * the decision
+ * @param changeReferences the decision
*/
- @Validate(required = false)
- public void setChangeReferences(boolean changeReferences)
+ @Validate( required = false )
+ public void setChangeReferences( boolean changeReferences )
{
m_changeReferences = changeReferences;
}
@@ -123,11 +121,10 @@
* Sets the new name for the page, which will be set when the
* {@link #rename()} handler is executed.
*
- * @param pageName
- * the new page name
+ * @param pageName the new page name
*/
- @Validate(required = true, minlength = 1, maxlength = 100, expression = "page.name != renameTo")
- public void setRenameTo(String pageName)
+ @Validate( required = true, minlength = 1, maxlength = 100, expression = "page.name != renameTo" )
+ public void setRenameTo( String pageName )
{
m_renameTo = pageName;
}
@@ -137,15 +134,14 @@
* validates that the proposed new name does not collide with an existing
* page.
*
- * @param errors
- * the current set of validation errors for this ActionBean
+ * @param errors the current set of validation errors for this ActionBean
*/
- @ValidationMethod(on = "rename")
- public void validateBeforeRename(ValidationErrors errors)
+ @ValidationMethod( on = "rename" )
+ public void validateBeforeRename( ValidationErrors errors )
{
- if (getContext().getWikiEngine().pageExists(m_renameTo))
+ if( getContext().getWikiEngine().pageExists( m_renameTo ) )
{
- errors.add("renameTo", new SimpleError("The page name '" + m_renameTo + "' already exists. Choose another."));
+ errors.add( "renameTo", new SimpleError( "The page name '" + m_renameTo + "' already exists. Choose another." ) );
}
}
Modified: incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/src/com/ecyrd/jspwiki/action/SearchActionBean.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/src/com/ecyrd/jspwiki/action/SearchActionBean.java?rev=682139&r1=682138&r2=682139&view=diff
==============================================================================
--- incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/src/com/ecyrd/jspwiki/action/SearchActionBean.java (original)
+++ incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/src/com/ecyrd/jspwiki/action/SearchActionBean.java Sun Aug 3 05:12:47 2008
@@ -1,9 +1,15 @@
package com.ecyrd.jspwiki.action;
-import net.sourceforge.stripes.action.UrlBinding;
+import net.sourceforge.stripes.action.*;
-@WikiRequestContext("find")
-@UrlBinding("/Search.action")
+@UrlBinding( "/Search.jsp" )
public class SearchActionBean extends AbstractActionBean
{
+ @DefaultHandler
+ @HandlesEvent( "find" )
+ @WikiRequestContext( "find" )
+ public Resolution view()
+ {
+ return new ForwardResolution( "/Search.jsp" );
+ }
}
Modified: incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/src/com/ecyrd/jspwiki/action/UploadActionBean.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/src/com/ecyrd/jspwiki/action/UploadActionBean.java?rev=682139&r1=682138&r2=682139&view=diff
==============================================================================
--- incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/src/com/ecyrd/jspwiki/action/UploadActionBean.java (original)
+++ incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/src/com/ecyrd/jspwiki/action/UploadActionBean.java Sun Aug 3 05:12:47 2008
@@ -7,12 +7,12 @@
import com.ecyrd.jspwiki.WikiContext;
import com.ecyrd.jspwiki.auth.permissions.PagePermission;
-@WikiRequestContext("upload")
-@UrlBinding("/Upload.action")
+@UrlBinding( "/Upload.jsp" )
public class UploadActionBean extends WikiContext
{
- @HandlesEvent("diff")
- @EventPermission(permissionClass=PagePermission.class, target="${page.qualifiedName}", actions=PagePermission.UPLOAD_ACTION)
+ @HandlesEvent( "upload" )
+ @HandlerPermission( permissionClass = PagePermission.class, target = "${page.name}", actions = PagePermission.UPLOAD_ACTION )
+ @WikiRequestContext( "upload" )
public Resolution upload()
{
return null;
Modified: incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/src/com/ecyrd/jspwiki/action/UserPreferencesActionBean.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/src/com/ecyrd/jspwiki/action/UserPreferencesActionBean.java?rev=682139&r1=682138&r2=682139&view=diff
==============================================================================
--- incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/src/com/ecyrd/jspwiki/action/UserPreferencesActionBean.java (original)
+++ incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/src/com/ecyrd/jspwiki/action/UserPreferencesActionBean.java Sun Aug 3 05:12:47 2008
@@ -16,14 +16,13 @@
/**
* @author Andrew Jaquith
*/
-@WikiRequestContext("prefs")
-@UrlBinding("/UserPreferences.action")
+@UrlBinding( "/UserPreferences.jsp" )
public class UserPreferencesActionBean extends AbstractActionBean
{
private String m_assertedName = null;
private String m_editor = null;
-
+
private String m_redirect = null;
/**
@@ -32,13 +31,13 @@
*
* @return a redirection to the logout page
*/
- @HandlesEvent("clearAssertedName")
- @EventPermission(permissionClass = WikiPermission.class, target = "${engine.applicationName}", actions = WikiPermission.EDIT_PREFERENCES_ACTION)
+ @HandlesEvent( "clearAssertedName" )
+ @HandlerPermission( permissionClass = WikiPermission.class, target = "${engine.applicationName}", actions = WikiPermission.EDIT_PREFERENCES_ACTION )
public Resolution clearAssertedName()
{
HttpServletResponse response = getContext().getResponse();
- CookieAssertionLoginModule.clearUserCookie(response);
- return new RedirectResolution("/Logout.jsp");
+ CookieAssertionLoginModule.clearUserCookie( response );
+ return new RedirectResolution( "/Logout.jsp" );
}
/**
@@ -46,11 +45,12 @@
*
* @return a redirection to the favorites page
*/
- @HandlesEvent("editFavorites")
+ @HandlesEvent( "editFavorites" )
+ @WikiRequestContext( "favorites" )
public Resolution editFavorites()
{
Principal principal = this.getCurrentUser();
- return new RedirectResolution("/Edit.jsp?" + principal.getName() + "Favorites");
+ return new RedirectResolution( "/Edit.jsp?" + principal.getName() + "Favorites" );
}
/**
@@ -61,18 +61,19 @@
* @return a redirection to the front page
*/
@DefaultHandler
- @HandlesEvent("createAssertedName")
- @EventPermission(permissionClass = WikiPermission.class, target = "${engine.applicationName}", actions = WikiPermission.EDIT_PREFERENCES_ACTION)
+ @HandlesEvent( "createAssertedName" )
+ @HandlerPermission( permissionClass = WikiPermission.class, target = "${engine.applicationName}", actions = WikiPermission.EDIT_PREFERENCES_ACTION )
+ @WikiRequestContext( "prefs" )
public Resolution createAssertedName()
{
- if (!getWikiSession().isAuthenticated())
+ if( !getWikiSession().isAuthenticated() )
{
HttpServletRequest request = getContext().getRequest();
HttpServletResponse response = getContext().getResponse();
- String assertedName = request.getParameter("assertedName");
- CookieAssertionLoginModule.setUserCookie(response, assertedName);
+ String assertedName = request.getParameter( "assertedName" );
+ CookieAssertionLoginModule.setUserCookie( response, assertedName );
}
- return new RedirectResolution("/");
+ return new RedirectResolution( "/" );
}
/**
@@ -88,11 +89,10 @@
/**
* Sets the asserted name for the user prefererences.
*
- * @param name
- * the asserted name
+ * @param name the asserted name
*/
- @Validate(required = true, on = "createAssertedName")
- public void setAssertedName(String name)
+ @Validate( required = true, on = "createAssertedName" )
+ public void setAssertedName( String name )
{
m_assertedName = name;
}
@@ -114,32 +114,33 @@
* the editor as an HTTP session attribute.
* <em>Note: this functionality was taken directly from the 2.6 UserPreferences.jsp.</em>
*
- * @param editor
- * the editor
+ * @param editor the editor
*/
- @Validate(required = false)
- public void setEditor(String editor)
+ @Validate( required = false )
+ public void setEditor( String editor )
{
m_editor = editor;
- if (this.getContext() != null && getContext().getRequest() != null)
+ if( getContext().getRequest() != null )
{
HttpSession session = getContext().getRequest().getSession();
- session.setAttribute(EditorManager.PARA_EDITOR, editor);
+ session.setAttribute( EditorManager.PARA_EDITOR, editor );
}
}
-
+
/**
* Sets the URL to redirect to after the event handler methods fire.
+ *
* @param url the URL to redirect to
*/
- @Validate(required=false)
- public void setRedirect(String url)
+ @Validate( required = false )
+ public void setRedirect( String url )
{
m_redirect = url;
}
/**
* Returns the URL to redirect to after the event handler methods fire.
+ *
* @return the URL to redirect to
*/
public String getRedirect()
Modified: incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/src/com/ecyrd/jspwiki/action/UserProfileActionBean.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/src/com/ecyrd/jspwiki/action/UserProfileActionBean.java?rev=682139&r1=682138&r2=682139&view=diff
==============================================================================
--- incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/src/com/ecyrd/jspwiki/action/UserProfileActionBean.java (original)
+++ incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/src/com/ecyrd/jspwiki/action/UserProfileActionBean.java Sun Aug 3 05:12:47 2008
@@ -17,8 +17,7 @@
/**
* @author Andrew Jaquith
*/
-@WikiRequestContext("profile")
-@UrlBinding("/UserProfile.action")
+@UrlBinding("/UserProfile.jsp")
public class UserProfileActionBean extends AbstractActionBean
{
private UserProfile m_profile = null;
@@ -39,7 +38,7 @@
* UserProfile.
* @return <code>null</code>, always
*/
- @Before(LifecycleStage.BindingAndValidation)
+ @Before(stages=LifecycleStage.BindingAndValidation)
public Resolution init()
{
// Retrieve the user profile
@@ -61,7 +60,7 @@
* <code>null</code> otherwise
*/
@HandlesEvent("save")
- @EventPermission(permissionClass=WikiPermission.class, target="${engine.applicationName}", actions=WikiPermission.EDIT_PROFILE_ACTION)
+ @HandlerPermission(permissionClass=WikiPermission.class, target="${engine.applicationName}", actions=WikiPermission.EDIT_PROFILE_ACTION)
public Resolution save()
{
Resolution r = null;
@@ -165,10 +164,10 @@
// Locate the old user profile
UserProfile oldProfile = manager.getUserProfile( session );
- // If container authenticated, and accounts not shared, override the login name and password
+ // If container authenticated, override the login name and password
// The login name should always be the one provided by the container
AuthenticationManager authMgr = engine.getAuthenticationManager();
- if ( authMgr.isContainerAuthenticated() && !manager.getUserDatabase().isSharedWithContainer() )
+ if ( authMgr.isContainerAuthenticated() )
{
m_profile.setLoginName( oldProfile.getLoginName() );
m_profile.setPassword( null );
@@ -206,6 +205,7 @@
*/
@HandlesEvent("view")
@DefaultHandler
+ @WikiRequestContext("profile")
public Resolution view()
{
return new ForwardResolution(ViewActionBean.class);
Modified: incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/src/com/ecyrd/jspwiki/action/ViewActionBean.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/src/com/ecyrd/jspwiki/action/ViewActionBean.java?rev=682139&r1=682138&r2=682139&view=diff
==============================================================================
--- incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/src/com/ecyrd/jspwiki/action/ViewActionBean.java (original)
+++ incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/src/com/ecyrd/jspwiki/action/ViewActionBean.java Sun Aug 3 05:12:47 2008
@@ -20,8 +20,7 @@
* @author Andrew Jaquith
*
*/
-@WikiRequestContext("view")
-@UrlBinding("/Wiki.action")
+@UrlBinding("/Wiki.jsp")
public class ViewActionBean extends WikiContext
{
private Logger log = Logger.getLogger(ViewActionBean.class);
@@ -46,7 +45,7 @@
* @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
*/
- @After(LifecycleStage.BindingAndValidation)
+ @After(stages=LifecycleStage.BindingAndValidation)
public Resolution resolvePage() throws WikiException
{
WikiPage page = getPage();
@@ -135,7 +134,8 @@
*/
@DefaultHandler
@HandlesEvent("view")
- @EventPermission(permissionClass=PagePermission.class, target="${page.qualifiedName}", actions=PagePermission.VIEW_ACTION)
+ @HandlerPermission(permissionClass=PagePermission.class, target="${page.name}", actions=PagePermission.VIEW_ACTION)
+ @WikiRequestContext("view")
public Resolution view()
{
return new ForwardResolution(ViewActionBean.class);
Modified: incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/src/com/ecyrd/jspwiki/action/WikiActionBean.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/src/com/ecyrd/jspwiki/action/WikiActionBean.java?rev=682139&r1=682138&r2=682139&view=diff
==============================================================================
--- incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/src/com/ecyrd/jspwiki/action/WikiActionBean.java (original)
+++ incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/src/com/ecyrd/jspwiki/action/WikiActionBean.java Sun Aug 3 05:12:47 2008
@@ -25,7 +25,7 @@
* Returns the ActionBeanContext for the WikiActionBean, using a co-variant
* return type of WikiActionBeanContext.
*/
- public abstract WikiActionBeanContext getContext();
+ public WikiActionBeanContext getContext();
/**
* Convenience method that gets the current user. Delegates the lookup to
@@ -34,7 +34,7 @@
* system. If the WikiSession has not been set, <em>always</em> returns
* null.
*/
- public abstract Principal getCurrentUser();
+ public Principal getCurrentUser();
/**
* Sets the WikiActionBeanContext for the ActionBean. This method <em>should</em>
@@ -43,12 +43,31 @@
public void setContext(ActionBeanContext context);
/**
+ * Sets the request context. See above for the different request contexts
+ * (VIEW, EDIT, etc.) This argument must correspond exactly to the value of
+ * a Stripes event handler method's
+ * {@link com.ecyrd.jspwiki.action.WikiRequestContext} annotation for the
+ * bean class. For event handlers that do not have an
+ * {@linkplain com.ecyrd.jspwiki.action.WikiRequestContext} annotation,
+ * callers can supply a request context value based on the bean class and
+ * the event name; see the
+ * {@link com.ecyrd.jspwiki.action.HandlerInfo#getRequestContext()}
+ * documentation for more details.
+ *
+ * @param arg The request context (one of the predefined contexts.)
+ * @throws IllegalArgumentException if the supplied request context does not correspond
+ * to a {@linkplain com.ecyrd.jspwiki.action.WikiRequestContext}
+ * annotation, or the automatically request context name
+ */
+ public void setRequestContext( String arg );
+
+ /**
* Returns the WikiEngine, which may be <code>null</code> if this instance
* was created without invoking the WikiActionBeanContext methods
* {@link WikiActionBeanContext#setRequest(HttpServletRequest)} or
* {@link WikiActionBeanContext#setServletContext(javax.servlet.ServletContext)}.
*/
- public abstract WikiEngine getEngine();
+ public WikiEngine getEngine();
/**
* Returns the request context for the WikiActionBean. By convention,
@@ -57,14 +76,14 @@
* classes.
* @deprecated perform <code>instanceof</code> comparisons instead
*/
- public abstract String getRequestContext();
+ public String getRequestContext();
/**
* Returns the "skin" to be used for this ActionBean.
*
* @return the skin
*/
- public abstract String getSkin();
+ public String getSkin();
/**
* <p>
@@ -84,7 +103,7 @@
*
* @since 2.1.15.
*/
- public abstract String getTemplate();
+ public String getTemplate();
/**
* Returns the WikiSession associated with the context. This method is
@@ -92,7 +111,7 @@
* constructed without an associated HttpServletRequest, it will return
* {@link WikiSession#guestSession(WikiEngine)}.
*/
- public abstract WikiSession getWikiSession();
+ public WikiSession getWikiSession();
/**
* Sets the skin to be used with this ActionBean. This value will override
@@ -102,14 +121,14 @@
* @param skin
* the skin to use
*/
- public abstract void setSkin(String skin);
+ public void setSkin(String skin);
/**
* Sets the template to be used for this request.
*
* @since 2.1.15.
*/
- public abstract void setTemplate(String dir);
+ public void setTemplate(String dir);
/**
* Gets a previously set variable.
@@ -132,4 +151,13 @@
// FIXME: This method should really cache the ResourceBundles or something...
public ResourceBundle getBundle( String bundle ) throws MissingResourceException;
+
+ // ------------------------------------ Deprecated methods we are reluctantly pulling up from WikiContext
+
+ /**
+ * @deprecated use Stripes bindings to populate ActionBean properties instead
+ */
+ public String getHttpParameter( String varName );
+
+ public HttpServletRequest getHttpRequest();
}
Modified: incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/src/com/ecyrd/jspwiki/action/WikiActionBeanContext.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/src/com/ecyrd/jspwiki/action/WikiActionBeanContext.java?rev=682139&r1=682138&r2=682139&view=diff
==============================================================================
--- incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/src/com/ecyrd/jspwiki/action/WikiActionBeanContext.java (original)
+++ incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/src/com/ecyrd/jspwiki/action/WikiActionBeanContext.java Sun Aug 3 05:12:47 2008
@@ -1,20 +1,10 @@
package com.ecyrd.jspwiki.action;
-import java.lang.reflect.Method;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Map.Entry;
-
import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import net.sourceforge.stripes.action.ActionBeanContext;
-import net.sourceforge.stripes.action.UrlBinding;
-import net.sourceforge.stripes.util.UrlBuilder;
-
-import org.apache.commons.lang.StringUtils;
-import com.ecyrd.jspwiki.WikiContext;
import com.ecyrd.jspwiki.WikiEngine;
import com.ecyrd.jspwiki.WikiSession;
@@ -31,47 +21,23 @@
public class WikiActionBeanContext extends ActionBeanContext
{
private volatile WikiEngine m_engine = null;
- private Map<Method,EventPermissionInfo> m_methodPermissions = new HashMap<Method,EventPermissionInfo>();
- /**
- * Sets the Permission metadata for an event handler method. If the metadata has already
- * been set for the supplied hander, this method throws an {@linkplain IllegalArgumentException}.
- * @param method the handler method
- * @param permInfo the Permission metadata
- */
- public void addPermissionInfo(Method method, EventPermissionInfo permInfo)
- {
- if ( m_methodPermissions.containsKey(method))
- {
- throw new IllegalArgumentException("Already added permission info for " + method.getName());
- }
- m_methodPermissions.put(method,permInfo);
- }
-
- /**
- * Returns the Permission metdata for a supplied event handler method. If the
- * handler does not have any metadata, this method will return <code>null</code>
- * <em>and calling classes should check for this value</em>.
- * @param method the handler method to look up
- * @return the Permission metadata
- */
- public EventPermissionInfo getPermissionInfo(Method method)
+ public WikiActionBeanContext()
{
- return m_methodPermissions.get(method);
+ super();
}
-
+
public WikiSession getWikiSession()
{
- return WikiSession.getWikiSession(m_engine, getRequest());
+ return WikiSession.getWikiSession( m_engine, getRequest() );
}
/**
* Sets the WikiEngine associated with this WikiActionBeanContext.
*
- * @param engine
- * the wiki engine
+ * @param engine the wiki engine
*/
- public void setWikiEngine(WikiEngine engine)
+ public void setWikiEngine( WikiEngine engine )
{
m_engine = engine;
}
@@ -91,24 +57,23 @@
* {@link ActionBeanContext#setRequest(HttpServletRequest)} and lazily sets
* the internal WikiEngine reference, if still <code>null</code>.
*
- * @param request
- * the HTTP request
+ * @param request the HTTP request
*/
@Override
- public void setRequest(HttpServletRequest request)
+ public void setRequest( HttpServletRequest request )
{
- super.setRequest(request);
- if (request != null)
+ super.setRequest( request );
+ if( request != null )
{
// Lazily set the WikiEngine reference
- if (m_engine == null)
+ if( m_engine == null )
{
ServletContext servletContext = request.getSession().getServletContext();
- m_engine = WikiEngine.getInstance(servletContext, null);
+ m_engine = WikiEngine.getInstance( servletContext, null );
}
}
-
- // Retrieve the WikiSession, which ensures we log the user in (if needed)
+
+ // Retrieve the WikiSession, which executes the login stack (if needed)
WikiSession.getWikiSession( m_engine, request );
}
@@ -117,137 +82,17 @@
* {@link ActionBeanContext#setServletContext(ServletContext)} and lazily
* sets the internal WikiEngine reference, if still <code>null</code>.
*
- * @param servletContext
- * the servlet context
+ * @param servletContext the servlet context
*/
@Override
- public void setServletContext(ServletContext servletContext)
+ public void setServletContext( ServletContext servletContext )
{
- super.setServletContext(servletContext);
- if (m_engine == null)
- {
- WikiEngine engine = WikiEngine.getInstance(servletContext, null);
- setWikiEngine(engine);
- }
- }
-
- /**
- * Returns the URL for accessing a named wiki page via a particular ActionBean,
- * with a set of appended parameters. The URL will be <em>not</em> be encoded via
- * the HttpServletResponse object, so callers that need URL re-writing should
- * use {@link WikiContext#getURL(Class, String, String, boolean)} instead. If the
- * ActionBean class is not a WikiContext subclass, the value of the
- * <code>page</code> parameter is ignored.
- * @param beanClass the WikiActionBean subclass to use
- * @param page the wiki page; if <code>null</code>, the front page will be used
- * @param params the query parameters to append to the end of the URL; may be <code>null</code> if no parameters
- * @param absolute If <code>true</code>, will generate an absolute URL regardless of properties setting.
- * @return the URL
- */
- public String getURL( Class<? extends WikiActionBean> beanClass, String page, Map<String,String> params, boolean absolute )
- {
- // Set the page to the default (front page) if not supplied
- if( page == null )
- {
- page = m_engine.getFrontPage();
- }
-
- // Get the path prefix
- String pathPrefix;
- if ( absolute | m_engine.useAbsoluteUrls() )
- {
- pathPrefix = m_engine.getBaseURL();
- }
- else
- {
- pathPrefix = m_engine.getWikiActionBeanFactory().getPathPrefix();
- }
- boolean addParams = false;
-
- // Get the relative URL
- String url;
- if (AttachActionBean.class.equals(beanClass)) // Is this an attachment?
- {
- url = "attach/" + page;
- }
- else if (NoneActionBean.class.equals(beanClass)) // Is this a 'none' context?
- {
- url = page;
- }
- else // Otherwise, chop off the .action and add .jsp
- {
- url = beanClass.getAnnotation(UrlBinding.class).value();
- if ( url.endsWith(".action") )
- {
- url = url.substring( 1, url.length() - 7 ) + ".jsp";
- }
- addParams = true;
- }
-
- // Build the URL with any parameters we need
- UrlBuilder urlBuilder = new UrlBuilder( pathPrefix + url, false );
-
- if ( addParams )
- {
- // If the ActionBean is a WikiContext, add a page parameter
- if ( WikiContext.class.isAssignableFrom( beanClass ) && page != null )
- {
- urlBuilder.addParameter( "page", page + "" );
- }
-
- // Append the other parameters
- if ( params != null )
- {
- for ( Entry<String,String> param : params.entrySet() )
- {
- urlBuilder.addParameter( param.getKey(), param.getValue() );
- }
- }
- }
- url = urlBuilder.toString();
- url = StringUtils.replace( url, "+", "%20" );
- url = StringUtils.replace( url, "%2F", "/" );
-
- // Encode the URL via the response object, if the response was set
- if ( getResponse() != null )
+ super.setServletContext( servletContext );
+ if( m_engine == null )
{
- return getResponse().encodeURL( url );
+ WikiEngine engine = WikiEngine.getInstance( servletContext, null );
+ setWikiEngine( engine );
}
- return url;
- }
-
- /**
- * Returns the URL for accessing a named wiki page via a particular ActionBean,
- * without parameters. The URL will be encoded via the HttpServletResponse object,
- * which means that any outbound filters will be able to transform
- * it as needed. The URL returned will be absolute if the WikiEngine
- * was configured to return absolute URLs; otherwise, the URL will be
- * relative to the webapp context root. If the ActionBean class is not a
- * WikiContext subclass, the value of the <code>page</code> parameter is
- * ignored.
- * @param beanClass the WikiActionBean subclass to use
- * @param page the wiki page; if <code>null</code>, the front page will be used
- * @return the URL
- */
- public String getURL( Class<? extends WikiActionBean> beanClass, String page )
- {
- return getURL( beanClass, page, null, m_engine.useAbsoluteUrls() );
- }
-
- /**
- * Returns the URL for accessing a named wiki page via a particular ActionBean,
- * without parameters. The URL will be encoded via the HttpServletResponse object,
- * which means that any outbound filters will be able to transform it as needed.
- * If the ActionBean class is not a WikiContext subclass, the value of the
- * <code>page</code> parameter is ignored.
- * @param beanClass the WikiActionBean subclass to use
- * @param page the wiki page; if <code>null</code>, the front page will be used.
- * @param params the query parameters to append to the end of the URL; may be <code>null</code> if no parameters
- * @return the URL
- */
- public String getURL( Class<? extends WikiActionBean> beanClass, String page, Map<String,String> params )
- {
- return getURL( beanClass, page, params, m_engine.useAbsoluteUrls() );
}
}
Modified: incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/src/com/ecyrd/jspwiki/action/WikiActionBeanFactory.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/src/com/ecyrd/jspwiki/action/WikiActionBeanFactory.java?rev=682139&r1=682138&r2=682139&view=diff
==============================================================================
--- incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/src/com/ecyrd/jspwiki/action/WikiActionBeanFactory.java (original)
+++ incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/src/com/ecyrd/jspwiki/action/WikiActionBeanFactory.java Sun Aug 3 05:12:47 2008
@@ -1,23 +1,29 @@
package com.ecyrd.jspwiki.action;
-import java.net.MalformedURLException;
-import java.net.URL;
+import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
+import java.util.Set;
+import javax.servlet.ServletRequest;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.jsp.PageContext;
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.log4j.Logger;
import com.ecyrd.jspwiki.*;
import com.ecyrd.jspwiki.parser.MarkupParser;
import com.ecyrd.jspwiki.providers.ProviderException;
-import com.ecyrd.jspwiki.ui.WikiInterceptor;
+import com.ecyrd.jspwiki.tags.WikiTagBase;
+import com.ecyrd.jspwiki.url.StripesURLConstructor;
/**
* <p>
@@ -55,105 +61,158 @@
* </p>
*
* @author Andrew Jaquith
- * @param <T>
* @since 2.4.22
*/
public final class WikiActionBeanFactory
{
- private static final Logger log = Logger.getLogger(WikiActionBeanFactory.class);
-
+ private static final Logger log = Logger.getLogger( WikiActionBeanFactory.class );
+
private static final long serialVersionUID = 1L;
/** Prefix in jspwiki.properties signifying special page keys. */
private static final String PROP_SPECIALPAGE = "jspwiki.specialPage.";
+ /** Default list of packages to search for WikiActionBean implementations. */
+ private static final String DEFAULT_ACTIONBEAN_PACKAGES = "com.ecyrd.jspwiki.action";
+
+ /** Property in jspwiki.properties that specifies packages to search for WikiActionBean implementations. */
+ private static final String PROPS_ACTIONBEAN_PACKAGES = "jspwiki.actionBean.packages";
+
/** Private map with JSPs as keys, Resolutions as values */
private final Map<String, RedirectResolution> m_specialRedirects;
private final WikiEngine m_engine;
+ private String m_mockContextPath;
+
/** If true, we'll also consider english plurals (+s) a match. */
private boolean m_matchEnglishPlurals;
+ /** Maps (pre-3.0) request contexts map to WikiActionBeans. */
+ private final Map<String, HandlerInfo> m_contextMap = new HashMap<String, HandlerInfo>();
+
/**
- * Contains the absolute path of the JSPWiki Web application without the
- * actual servlet; in other words, the absolute or relative path to
- * this webapp's root path. If no base URL is specified in
- * <code>jspwiki.properties</code>, the value will be an empty string.
+ * Initializes the internal map that matches wiki request contexts with HandlerInfo objects.
+ * @param properties
*/
- private final String m_pathPrefix;
+ private void initRequestContextMap( Properties properties )
+ {
+ // Look up all classes that are WikiActionBeans.
+ String beanPackagesProp = properties.getProperty( PROPS_ACTIONBEAN_PACKAGES, DEFAULT_ACTIONBEAN_PACKAGES ).trim();
+ String[] beanPackages = beanPackagesProp.split( "," );
+ Set<Class<? extends WikiActionBean>> beanClasses = findBeanClasses( beanPackages);
+
+ // Stash the contexts and corresponding classes into a Map.
+ for( Class<? extends WikiActionBean> beanClass : beanClasses )
+ {
+ Map<Method, HandlerInfo> handlerMethods = HandlerInfo.getHandlerInfoCollection( beanClass );
+ for( HandlerInfo handler : handlerMethods.values() )
+ {
+ String requestContext = handler.getRequestContext();
+ if( m_contextMap.containsKey( requestContext ) )
+ {
+ HandlerInfo duplicateHandler = m_contextMap.get( requestContext );
+ log.error( "Bean class " + beanClass.getCanonicalName() + " contains @WikiRequestContext annotation '"
+ + requestContext + "' that duplicates one already declared for "
+ + duplicateHandler.getActionBeanClass() );
+ }
+ else
+ {
+ m_contextMap.put( requestContext, handler );
+ log.info( "Discovered request context '" + requestContext + "' for WikiActionBean="
+ + beanClass.getCanonicalName() + ",event=" + handler.getEventName() );
+ }
+ }
+ }
+ }
+
+ /**
+ * Searches a set of named packages for WikiActionBean implementations, and returns any it finds.
+ * @param beanPackages the packages to search on the current classpath, separated by commas
+ * @return the discovered classes
+ */
+ private Set<Class<? extends WikiActionBean>> findBeanClasses( String[] beanPackages )
+ {
+ ResolverUtil<WikiActionBean> resolver = new ResolverUtil<WikiActionBean>();
+ resolver.findImplementations( WikiActionBean.class, beanPackages );
+ return resolver.getClasses();
+ }
+
+ /**
+ * Looks up and returns the correct HandlerInfo class corresponding to a
+ * supplied wiki context. The supplied context name is matched against the
+ * values annotated using
+ * {@link com.ecyrd.jspwiki.action.WikiRequestContext}. If a match is not
+ * found, this method throws an IllegalArgumentException.
+ *
+ * @param context the context to look up
+ * @return the WikiActionBean event handler info
+ */
+ public HandlerInfo findEventHandler( String context )
+ {
+ HandlerInfo handler = m_contextMap.get( context );
+ if( handler == null )
+ {
+ throw new IllegalArgumentException( "No HandlerInfo found for request context '" + context + "'!" );
+ }
+ return handler;
+ }
/**
* Constructs a WikiActionBeanResolver for a given WikiEngine. This
* constructor will extract the special page references for this wiki and
* store them in a cache used for resolution.
*
- * @param engine
- * the wiki engine
- * @param properties
- * the properties used to initialize the wiki
+ * @param engine the wiki engine
+ * @param properties the properties used to initialize the wiki
*/
- public WikiActionBeanFactory(WikiEngine engine, Properties properties)
+ public WikiActionBeanFactory( WikiEngine engine, Properties properties )
{
super();
m_engine = engine;
m_specialRedirects = new HashMap<String, RedirectResolution>();
- // Skim through the properties and look for anything with
- // the "special page" prefix. Create maps that allow us
- // look up the correct ActionBean based on special page name.
- // If a matching command isn't found, create a RedirectCommand.
- for (Map.Entry entry : properties.entrySet())
+ initRequestContextMap( properties );
+ initSpecialPageRedirects( properties );
+
+ // Do we match plurals?
+ m_matchEnglishPlurals = TextUtil.getBooleanProperty( properties, WikiEngine.PROP_MATCHPLURALS, true );
+
+ // Set the path prefix for constructing synthetic Stripes mock requests;
+ // trailing slash is removed.
+ m_mockContextPath = StripesURLConstructor.getContextPath( engine );
+
+ // TODO: make packages to search in ActionBeanResolver configurable
+ // (currently hard-coded)
+ }
+
+ /**
+ * Skims through a supplied set of Properties and looks for anything with the "special page"
+ * prefix, and creates Stripes {@link net.sourceforge.stripes.action.RedirectResolution} objects
+ * for any that are found.
+ */
+ private void initSpecialPageRedirects( Properties properties )
+ {
+ for( Map.Entry entry : properties.entrySet() )
{
String key = (String) entry.getKey();
- if (key.startsWith(PROP_SPECIALPAGE))
+ if( key.startsWith( PROP_SPECIALPAGE ) )
{
- String specialPage = key.substring(PROP_SPECIALPAGE.length());
+ String specialPage = key.substring( PROP_SPECIALPAGE.length() );
String redirectUrl = (String) entry.getValue();
- if (specialPage != null && redirectUrl != null)
+ if( specialPage != null && redirectUrl != null )
{
specialPage = specialPage.trim();
redirectUrl = redirectUrl.trim();
- RedirectResolution resolution = m_specialRedirects.get(specialPage);
- if (resolution == null)
+ RedirectResolution resolution = m_specialRedirects.get( specialPage );
+ if( resolution == null )
{
- resolution = new RedirectResolution(redirectUrl);
- m_specialRedirects.put(specialPage, resolution);
+ resolution = new RedirectResolution( redirectUrl );
+ m_specialRedirects.put( specialPage, resolution );
}
}
}
}
-
- // Do we match plurals?
- m_matchEnglishPlurals = TextUtil.getBooleanProperty(properties, WikiEngine.PROP_MATCHPLURALS, true);
-
- // Initialize the path prefix for building URLs
- // NB this was stolen and adapted from the old URLConstructor code...
- String baseurl = engine.getBaseURL();
- String tempPath = "";
- if( baseurl != null && baseurl.length() > 0 )
- {
- try
- {
- URL url = new URL( baseurl );
- tempPath = url.getPath();
- }
- catch( MalformedURLException e )
- {
- tempPath = "/JSPWiki"; // Just a guess.
- }
- }
- m_pathPrefix = tempPath;
- }
-
- /**
- * Returns the path prefix for building URLs. Should be deprecated as we move
- * to Stripes for URL generation.
- * @return
- */
- public String getPathPrefix()
- {
- return m_pathPrefix;
}
/**
@@ -174,47 +233,46 @@
* </p>
*
* @since 2.4.20
- * @param page
- * the page name.
+ * @param page the page name.
* @return The rewritten page name, or <code>null</code>, if the page
* does not exist.
*/
- public final String getFinalPageName(String page) throws ProviderException
+ public final String getFinalPageName( String page ) throws ProviderException
{
- boolean isThere = simplePageExists(page);
+ boolean isThere = simplePageExists( page );
String finalName = page;
- if (!isThere && m_matchEnglishPlurals)
+ if( !isThere && m_matchEnglishPlurals )
{
- if (page.endsWith("s"))
+ if( page.endsWith( "s" ) )
{
- finalName = page.substring(0, page.length() - 1);
+ finalName = page.substring( 0, page.length() - 1 );
}
else
{
finalName += "s";
}
- isThere = simplePageExists(finalName);
+ isThere = simplePageExists( finalName );
}
- if (!isThere)
+ if( !isThere )
{
- finalName = MarkupParser.wikifyLink(page);
- isThere = simplePageExists(finalName);
+ finalName = MarkupParser.wikifyLink( page );
+ isThere = simplePageExists( finalName );
- if (!isThere && m_matchEnglishPlurals)
+ if( !isThere && m_matchEnglishPlurals )
{
- if (finalName.endsWith("s"))
+ if( finalName.endsWith( "s" ) )
{
- finalName = finalName.substring(0, finalName.length() - 1);
+ finalName = finalName.substring( 0, finalName.length() - 1 );
}
else
{
finalName += "s";
}
- isThere = simplePageExists(finalName);
+ isThere = simplePageExists( finalName );
}
}
@@ -234,11 +292,11 @@
* </p>
* TODO: fix this algorithm
*/
- public final String getSpecialPageReference(String page)
+ public final String getSpecialPageReference( String page )
{
- RedirectResolution resolution = m_specialRedirects.get(page);
+ RedirectResolution resolution = m_specialRedirects.get( page );
- if (resolution != null)
+ if( resolution != null )
{
return resolution.getUrl();
}
@@ -258,8 +316,10 @@
* This method will <em>always</em>return a WikiActionBean that is
* properly instantiated. It will also create a new {@WikiActionBeanContext}
* and associate it with the action bean. The supplied request and response
- * objects will be associated with the WikiActionBeanContext. All three
- * parameters are required, and may not be <code>null</code>.
+ * objects will be associated with the WikiActionBeanContext. The
+ * <code>beanClass</code>is required. If either the <code>request</code>
+ * or <code>response</code> parameters are <code>null</code>,
+ * appropriate mock objects will be substituted instead.
* </p>
* <p>
* This method performs a similar role to the <stripes:useActionBean>
@@ -273,120 +333,59 @@
* instead.
* </p>
*
- * @param request
- * the HTTP request
- * @param response
- * the HTTP request
- * @param beanClass
- * the request context to use by default</code>
+ * @param request the HTTP request
+ * @param response the HTTP request
+ * @param beanClass the request context to use by default</code>
* @return the resolved wiki action bean
+ * @see net.sourceforge.stripes.tag.UseActionBeanTag
*/
- public WikiActionBean newActionBean(HttpServletRequest request, HttpServletResponse response,
- Class<? extends WikiActionBean> beanClass) throws WikiException
+ public WikiActionBean newActionBean( HttpServletRequest request, HttpServletResponse response,
+ Class<? extends WikiActionBean> beanClass ) throws WikiException
{
- if (request == null || response == null)
- {
- throw new IllegalArgumentException("Request or response cannot be null");
- }
-
- // Try creating a new ActionBean by looking up the request context
- WikiActionBean bean = newInstance(beanClass);
-
- // OK: we have the correct AbstractActionBean; inject into request scope
- WikiActionBeanContext actionBeanContext = new WikiActionBeanContext();
- actionBeanContext.setRequest(request);
- actionBeanContext.setResponse(response);
- actionBeanContext.setWikiEngine(m_engine);
- bean.setContext(actionBeanContext);
-
- // If the ActionBean is a WikiContext, extract and set the page (if not
- // null)
- if (bean instanceof WikiContext)
- {
- String page = extractPageFromParameter(request);
-
- // For view action, default to front page
- if (page == null && bean instanceof ViewActionBean)
- {
- page = m_engine.getFrontPage();
- }
- if (page != null)
- {
- WikiPage wikiPage = resolvePage(request, page);
- ((WikiContext) bean).setPage(wikiPage);
- }
- }
- return bean;
+ return newInstance( beanClass, request, response, null );
}
/**
* Creates a new ViewActionBean for the given WikiEngine, WikiPage and
- * HttpServletRequest.
+ * HttpServletRequest. This method performs a similar role to the
+ * <stripes:useActionBean> tag, in the sense that it will instantiate
+ * an arbitrary WikiActionBean class and, in the case of WikiContext
+ * subclasses, bind a WikiPage to it. However, it lacks some of the
+ * capabilities the JSP tag possesses. For example, although this method
+ * will correctly identity the page requested by the user (by inspecting
+ * request parameters), it will not do anything special if the page is a
+ * "special page." If special page resolution and redirection is required,
+ * use the <stripes:useActionBean> JSP tag instead.
*
- * @param request
- * The HttpServletRequest that should be associated with this
- * context. This parameter may be <code>null</code>.
- * @param response
- * The HttpServletResponse that should be associated with this
+ * @param request The HttpServletRequest that should be associated with this
* context. This parameter may be <code>null</code>.
- * @param page
- * The WikiPage. If you want to create a WikiContext for an older
- * version of a page, you must supply this parameter
+ * @param response The HttpServletResponse that should be associated with
+ * this context. This parameter may be <code>null</code>.
+ * @param page The WikiPage. If you want to create a WikiContext for an
+ * older version of a page, you must supply this parameter
+ * @see net.sourceforge.stripes.tag.UseActionBeanTag
*/
- public WikiContext newViewActionBean(HttpServletRequest request, HttpServletResponse response, WikiPage page)
+ public ViewActionBean newViewActionBean( HttpServletRequest request, HttpServletResponse response, WikiPage page )
{
- // Create a new WikiActionBean and set its sevlet context; this will set
- // the WikiEngine too
- WikiActionBeanContext context = new WikiActionBeanContext();
- context.setServletContext(m_engine.getServletContext());
-
- // If a request or response was passed along, set these references also
- if (request != null)
- {
- context.setRequest(request);
- }
- if (response != null)
- {
- context.setResponse(response);
- }
-
- // Create a 'view' ActionBean and set the wiki page if passed
- ViewActionBean bean = new ViewActionBean();
- bean.setContext(context);
-
- // If the page supplied was blank, default to the front page to avoid
- // NPEs
- if (page == null)
+ // Create a new "view" ActionBean, and swallow any exceptions
+ ViewActionBean bean = null;
+ try
{
- page = m_engine.getPage(m_engine.getFrontPage());
-
- // Front page does not exist?
- if (page == null)
+ bean = (ViewActionBean) newInstance( ViewActionBean.class, request, response, page );
+ if( bean == null )
{
- page = new WikiPage(m_engine, m_engine.getFrontPage());
+ throw new IllegalStateException( "Could not create new ViewActionBean! This indicates a bug..." );
}
}
-
- if (page != null)
+ catch( WikiException e )
{
- bean.setPage(page);
+ e.printStackTrace();
+ log.error( e.getMessage() );
}
return bean;
}
/**
- * Create a new ViewActionBean for the given WikiPage.
- *
- * @param page
- * The WikiPage. If you want to create a WikiContext for an older
- * version of a page, you must use this constructor.
- */
- public WikiContext newViewActionBean(WikiPage page)
- {
- return newViewActionBean(null, null, page);
- }
-
- /**
* <p>
* Determines the correct wiki page based on a supplied HTTP request. This
* method attempts to determine the page requested by a user, taking into
@@ -401,35 +400,34 @@
* this method returns <code>null</code>
* </p>.
*
- * @param request
- * the HTTP request
+ * @param request the HTTP request
* @return the resolved page name
*/
- protected final String extractPageFromParameter(HttpServletRequest request)
+ protected final String extractPageFromParameter( HttpServletRequest request )
{
// Corner case when request == null
- if (request == null)
+ if( request == null )
{
return null;
}
// Extract the page name from the URL directly
- String[] pages = request.getParameterValues("page");
+ String[] pages = request.getParameterValues( "page" );
String page = null;
- if (pages != null && pages.length > 0)
+ if( pages != null && pages.length > 0 )
{
page = pages[0];
try
{
// Look for singular/plural variants; if one
// not found, take the one the user supplied
- String finalPage = getFinalPageName(page);
- if (finalPage != null)
+ String finalPage = getFinalPageName( page );
+ if( finalPage != null )
{
page = finalPage;
}
}
- catch (ProviderException e)
+ catch( ProviderException e )
{
// FIXME: Should not ignore!
}
@@ -441,27 +439,90 @@
}
/**
- * Given an instance of an ActionBean, this method returns a new instance of
- * the same class.
+ * Creates and returns a new WikiActionBean based on a supplied class, with
+ * an instantiated {@link WikiActionBeanContext}. The
+ * WikiActionBeanContext's request and response properties will be set to
+ * those supplied by the caller; if not supplied, synthetic instances will
+ * be substituted.
*
- * @param beanClass
- * the bean class that should be newly instantiated
+ * @param beanClass the bean class that should be newly instantiated
+ * @param request
+ * @param response
* @return the newly instantiated bean
*/
- protected WikiActionBean newInstance(Class<? extends WikiActionBean> beanClass) throws WikiException
+ protected WikiActionBean newInstance( Class<? extends WikiActionBean> beanClass, HttpServletRequest request,
+ HttpServletResponse response, WikiPage page ) throws WikiException
{
- if (beanClass != null)
+ // Instantiate the ActionBean first
+ WikiActionBean bean = null;
+ if( beanClass == null )
+ {
+ throw new IllegalArgumentException( "Bean class cannot be null!" );
+ }
{
try
{
- return beanClass.newInstance();
+ bean = beanClass.newInstance();
}
- catch (Exception e)
+ catch( Exception e )
{
- throw new WikiException("Could not create ActionBean: " + e.getMessage());
+ throw new WikiException( "Could not create ActionBean: " + e.getMessage() );
}
}
- return null;
+
+ // Create synthetic request if not supplied
+ if( request == null )
+ {
+ request = new MockHttpServletRequest( m_mockContextPath, "/Wiki.jsp" );
+ MockHttpSession session = new MockHttpSession( m_engine.getServletContext() );
+ ((MockHttpServletRequest) request).setSession( session );
+ }
+
+ // Create synthetic response if not supplied
+ if( response == null )
+ {
+ response = new MockHttpServletResponse();
+ }
+
+ // Create the WikiActionBeanContext
+ WikiActionBeanContext actionBeanContext = new WikiActionBeanContext();
+ bean.setContext( actionBeanContext );
+ actionBeanContext.setRequest( request );
+ actionBeanContext.setResponse( response );
+ actionBeanContext.setWikiEngine( m_engine );
+ actionBeanContext.setServletContext( m_engine.getServletContext() );
+
+ // Set the event name for this action bean to the default handler
+ actionBeanContext.setEventName( HandlerInfo.getDefaultHandlerInfo( beanClass ).getEventName() );
+
+ // If ActionBean is a WikiContext, extract and set the WikiPage
+ if( bean instanceof WikiContext )
+ {
+ if( page == null )
+ {
+ String pageName = extractPageFromParameter( request );
+
+ // For view action, default to front page
+ if( pageName == null && bean instanceof ViewActionBean )
+ {
+ pageName = m_engine.getFrontPage();
+ }
+
+ // Make sure the page is resolved properly (taking into account
+ // funny plurals)
+ if( pageName != null )
+ {
+ page = resolvePage( request, pageName );
+ }
+ }
+
+ if( page != null )
+ {
+ ((WikiContext) bean).setPage( page );
+ }
+ }
+
+ return bean;
}
/**
@@ -470,31 +531,29 @@
* request. If the <code>version</code> parameter does not exist in the
* request, the latest version is returned.
*
- * @param request
- * the HTTP request
- * @param page
- * the name of the page to look up; this page <em>must</em>
+ * @param request the HTTP request
+ * @param page the name of the page to look up; this page <em>must</em>
* exist
* @return the wiki page
*/
- protected final WikiPage resolvePage(HttpServletRequest request, String page)
+ protected final WikiPage resolvePage( HttpServletRequest request, String page )
{
// See if the user included a version parameter
WikiPage wikipage;
int version = WikiProvider.LATEST_VERSION;
- String rev = request.getParameter("version");
+ String rev = request.getParameter( "version" );
- if (rev != null)
+ if( rev != null )
{
- version = Integer.parseInt(rev);
+ version = Integer.parseInt( rev );
}
- wikipage = m_engine.getPage(page, version);
+ wikipage = m_engine.getPage( page, version );
- if (wikipage == null)
+ if( wikipage == null )
{
- page = MarkupParser.cleanLink(page);
- wikipage = new WikiPage(m_engine, page);
+ page = MarkupParser.cleanLink( page );
+ wikipage = new WikiPage( m_engine, page );
}
return wikipage;
}
@@ -503,44 +562,44 @@
* Determines whether a "page" exists by examining the list of special pages
* and querying the page manager.
*
- * @param page
- * the page to seek
+ * @param page the page to seek
* @return <code>true</code> if the page exists, <code>false</code>
* otherwise
*/
- protected final boolean simplePageExists(String page) throws ProviderException
+ protected final boolean simplePageExists( String page ) throws ProviderException
{
- if (m_specialRedirects.containsKey(page))
+ if( m_specialRedirects.containsKey( page ) )
{
return true;
}
- return m_engine.getPageManager().pageExists(page);
+ return m_engine.getPageManager().pageExists( page );
}
/**
* Returns the WikiActionBean associated with the current
- * {@link javax.servlet.jsp.PageContext}, in request scope. The ActionBean
- * will be retrieved from attribute {@link WikiInterceptor#ATTR_ACTIONBEAN}.
+ * {@link javax.servlet.http.HttpServletRequest}. The ActionBean will be
+ * retrieved from attribute {@link WikiInterceptor#ATTR_ACTIONBEAN}.
*
- * @param pageContext
- * the
+ * @param pageContext the
* @return the WikiActionBean, or <code>null</code> if not found in the
* current tag's PageContext
*/
- public static WikiActionBean findActionBean(PageContext pageContext)
+ public static WikiActionBean findActionBean( ServletRequest request )
{
- return (WikiActionBean) pageContext.getAttribute(WikiInterceptor.ATTR_ACTIONBEAN, PageContext.REQUEST_SCOPE);
+ return (WikiActionBean) request.getAttribute( WikiInterceptor.ATTR_ACTIONBEAN );
}
/**
* <p>
* Saves the supplied WikiActionBean and its associated WikiPage as
- * PageContext attributes, in request scope. The action bean and wiki page
- * are saved as attributes named {@link WikiInterceptor#ATTR_ACTIONBEAN} and
- * {@link WikiInterceptor#ATTR_WIKIPAGE}. Among other things, by saving these items as
- * attributes, they can be accessed via JSP Expression Language variables,
- * in this case <code>${wikiActionBean}</code> and
- * <code>${wikiPage}</code> respectively..
+ * PageContext attributes, in request scope. The action bean is saved as an
+ * attribute named {@link WikiInterceptor#ATTR_ACTIONBEAN}. If the action
+ * bean was also a WikiContext instance, it is saved as an attribute named
+ * {@link com.ecyrd.jspwiki.tags.WikiTagBase#ATTR_CONTEXT}. Among other
+ * things, by saving these items as attributes, they can be accessed via JSP
+ * Expression Language variables, in this case
+ * <code>${wikiActionBean}</code> and <code>${wikiContext}</code>
+ * respectively.
* </p>
* <p>
* Note: the WikiPage set by this method is guaranteed to be non-null. If
@@ -550,47 +609,51 @@
* and that page will be used.
* </p>
*
- * @param pageContext
- * the page context
- * @param actionBean
- * the WikiActionBean to save
+ * @param pageContext the page context
+ * @param actionBean the WikiActionBean to save
*/
- public static void saveActionBean(PageContext pageContext, WikiActionBean actionBean)
+ public static void saveActionBean( PageContext pageContext, WikiActionBean actionBean )
{
// Stash the WikiActionBean
- pageContext.setAttribute(WikiInterceptor.ATTR_ACTIONBEAN, actionBean, PageContext.REQUEST_SCOPE);
-
- // Stash the WikiPage
- WikiPage page = null;
- if (actionBean instanceof WikiContext)
- {
- page = ((WikiContext) actionBean).getPage();
- }
- if (page == null)
- {
- // If the page supplied was blank, default to the front page to
- // avoid NPEs
- WikiEngine engine = actionBean.getEngine();
- page = engine.getPage(engine.getFrontPage());
- // Front page does not exist?
- if (page == null)
- {
- page = new WikiPage(engine, engine.getFrontPage());
+ WikiEngine engine = actionBean.getEngine();
+ pageContext.setAttribute( WikiInterceptor.ATTR_ACTIONBEAN, actionBean, PageContext.REQUEST_SCOPE );
+
+ // Stash it again as a WikiContext (or synthesize a fake one)
+ WikiContext wikiContext;
+ WikiPage page;
+ if( actionBean instanceof WikiContext )
+ {
+ wikiContext = (WikiContext) actionBean;
+ page = wikiContext.getPage();
+ if( page == null )
+ {
+ // If the page supplied was blank, default to the front page to
+ // avoid NPEs
+ page = engine.getPage( engine.getFrontPage() );
+ // Front page does not exist?
+ if( page == null )
+ {
+ page = new WikiPage( engine, engine.getFrontPage() );
+ }
+ wikiContext.setPage( page );
}
}
- if (actionBean instanceof WikiContext)
+ else
{
- ((WikiContext) actionBean).setPage(page);
+ HttpServletRequest request = actionBean.getContext().getRequest();
+ HttpServletResponse response = actionBean.getContext().getResponse();
+ page = engine.getPage( engine.getFrontPage() );
+ wikiContext = engine.getWikiActionBeanFactory().newViewActionBean( request, response, page );
}
- pageContext.setAttribute(WikiInterceptor.ATTR_WIKIPAGE, page, PageContext.REQUEST_SCOPE);
-
+ pageContext.setAttribute( WikiTagBase.ATTR_CONTEXT, actionBean, PageContext.REQUEST_SCOPE );
+
// Debug messages
- if (log.isDebugEnabled())
+ if( log.isDebugEnabled() )
{
- log.debug("Stashed WikiActionBean '" + actionBean + "' in page scope.");
- log.debug("Stashed WikiPage '" + page.getName() + "' in page scope.");
+ log.debug( "Stashed WikiActionBean '" + actionBean + "' in page scope." );
+ log.debug( "Stashed WikiPage '" + page.getName() + "' in page scope." );
}
-
+
}
}
Copied: incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/src/com/ecyrd/jspwiki/action/WikiExceptionHandler.java (from r643690, incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/src/com/ecyrd/jspwiki/ui/WikiExceptionHandler.java)
URL: http://svn.apache.org/viewvc/incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/src/com/ecyrd/jspwiki/action/WikiExceptionHandler.java?p2=incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/src/com/ecyrd/jspwiki/action/WikiExceptionHandler.java&p1=incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/src/com/ecyrd/jspwiki/ui/WikiExceptionHandler.java&r1=643690&r2=682139&rev=682139&view=diff
==============================================================================
--- incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/src/com/ecyrd/jspwiki/ui/WikiExceptionHandler.java (original)
+++ incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/src/com/ecyrd/jspwiki/action/WikiExceptionHandler.java Sun Aug 3 05:12:47 2008
@@ -1,15 +1,26 @@
-package com.ecyrd.jspwiki.ui;
+package com.ecyrd.jspwiki.action;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import net.sourceforge.stripes.action.Resolution;
-import net.sourceforge.stripes.exception.AutoExceptionHandler;
+import net.sourceforge.stripes.exception.DefaultExceptionHandler;
-public class WikiExceptionHandler implements AutoExceptionHandler
+/**
+ * Stripes ExceptionHandler that catches exceptions of various types and returns appropriate
+ * Resolutions.
+ */
+public class WikiExceptionHandler extends DefaultExceptionHandler
{
- public Resolution handle(Throwable exception, HttpServletRequest req, HttpServletResponse res)
+ /**
+ * Catches any Exceptions not handled by other methods in this class, and prints a stack trace.
+ * @param exception the exception caught by StripesFilter
+ * @param req the current HTTP request
+ * @param res the current HTTP response
+ * @return always returns <code>null</code> (that is, it does not redirect)
+ */
+ public Resolution catchAll(Throwable exception, HttpServletRequest req, HttpServletResponse res)
{
exception.printStackTrace();
return null;
Copied: incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/src/com/ecyrd/jspwiki/action/WikiInterceptor.java (from r643690, incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/src/com/ecyrd/jspwiki/ui/WikiInterceptor.java)
URL: http://svn.apache.org/viewvc/incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/src/com/ecyrd/jspwiki/action/WikiInterceptor.java?p2=incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/src/com/ecyrd/jspwiki/action/WikiInterceptor.java&p1=incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/src/com/ecyrd/jspwiki/ui/WikiInterceptor.java&r1=643690&r2=682139&rev=682139&view=diff
==============================================================================
--- incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/src/com/ecyrd/jspwiki/ui/WikiInterceptor.java (original)
+++ incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/src/com/ecyrd/jspwiki/action/WikiInterceptor.java Sun Aug 3 05:12:47 2008
@@ -1,4 +1,4 @@
-package com.ecyrd.jspwiki.ui;
+package com.ecyrd.jspwiki.action;
import java.lang.reflect.Method;
import java.security.Permission;
@@ -15,7 +15,6 @@
import com.ecyrd.jspwiki.WikiEngine;
import com.ecyrd.jspwiki.WikiSession;
-import com.ecyrd.jspwiki.action.*;
import com.ecyrd.jspwiki.auth.AuthorizationManager;
import com.ecyrd.jspwiki.auth.SessionMonitor;
@@ -23,10 +22,10 @@
* <p>
* Stripes {@link net.sourceforge.stripes.controller.Interceptor} that
* instantiates the correct WikiContext associated with JSPs, checks for access,
- * and redirects users if necessary. The interceptor executes during two stages:
- * after the second lifecycle stage, <em>aka</em>
+ * and redirects users if necessary. The interceptor executes after the second
+ * lifecycle stage, <em>aka</em>
* {@link net.sourceforge.stripes.controller.LifecycleStage#HandlerResolution},
- * and around (before and after) the third stage,
+ * but before the third stage,
* {@link net.sourceforge.stripes.controller.LifecycleStage#BindingAndValidation}.
* </p>
* <p>
@@ -47,8 +46,9 @@
* </ul>
* <p>
* After the intercept method fires, calling classes can obtain the saved
- * WikiActionBean by calling {@link WikiActionBeanFactory#findActionBean(PageContext)}. This is,
- * indeed, the recommended method for JSP scriptlet code.
+ * WikiActionBean by calling
+ * {@link WikiActionBeanFactory#findActionBean(javax.servlet.ServletRequest)}. This is
+ * the recommended method that JSP scriptlet code should use.
* </p>
* <p>
* Because these objects are saved as attributes, they are available to JSPs as
@@ -59,7 +59,7 @@
*
* @author Andrew Jaquith
*/
-@Intercepts( { LifecycleStage.HandlerResolution, LifecycleStage.BindingAndValidation })
+@Intercepts( { LifecycleStage.HandlerResolution } )
public class WikiInterceptor implements Interceptor
{
/**
@@ -68,9 +68,6 @@
*/
public static final String ATTR_ACTIONBEAN = "wikiActionBean";
- /** The PageContext attribute name of the WikiPage stored by WikiInterceptor. */
- public static final String ATTR_WIKIPAGE = "wikiPage";
-
/**
* The PageContext attribute name of the WikiEngine stored by
* WikiInterceptor.
@@ -83,33 +80,7 @@
*/
public static final String ATTR_WIKISESSION = "wikiSession";
- private static final Logger log = Logger.getLogger(WikiInterceptor.class);
-
- /**
- * Facade method that forwards execution to
- * {@link #interceptHandlerResolution(ExecutionContext)} or
- * {@link #interceptBindingAndValidation(ExecutionContext)}, depending on
- * the Stripes {@link net.sourceforge.stripes.controller.LifecycleStage}.
- *
- * @param context
- * the current Stripes execution context
- * @return a Resolution if the delgate intercept method returns one;
- * otherwise, <code>null</code>
- */
- public Resolution intercept(ExecutionContext context) throws Exception
- {
- switch (context.getLifecycleStage())
- {
- case HandlerResolution: {
- return interceptHandlerResolution(context);
- }
- case BindingAndValidation: {
- return interceptBindingAndValidation(context);
- }
- default:
- return null;
- }
- }
+ private static final Logger log = Logger.getLogger( WikiInterceptor.class );
/**
* <p>
@@ -124,7 +95,7 @@
* <p>
* To determine if the user is allowed to access the target event method,
* the method is examined to see if contains a
- * {@link com.ecyrd.jspwiki.action.EventPermission}) annotation that
+ * {@link com.ecyrd.jspwiki.action.HandlerPermission}) annotation that
* specifies the required {@link java.security.Permission}. If the user
* does not possess the Permission -- that is,
* {@link com.ecyrd.jspwiki.auth.AuthorizationManager#checkPermission(WikiSession, Permission)}
@@ -139,21 +110,19 @@
* can also be accessed as variables using the JSP Expression Language
* (example: <code>${wikiPage}</code>).
*
- * @param context
- * the current execution context
+ * @param context the current execution context
* @return a Resolution if the
* {@link net.sourceforge.stripes.controller.LifecycleStage#HandlerResolution}
* lifecycle stage's normal execution returns one; <code>null</code>
* otherwise
- * @throws Exception
- * if the underlying lifcycle stage's execution throws an
+ * @throws Exception if the underlying lifcycle stage's execution throws an
* Exception
*/
- protected Resolution interceptBindingAndValidation(ExecutionContext context) throws Exception
+ public Resolution intercept( ExecutionContext context ) throws Exception
{
// Did the handler resolution stage return a Resolution? If so, bail.
Resolution r = context.proceed();
- if (r != null)
+ if( r != null )
{
return r;
}
@@ -165,46 +134,47 @@
// Does the event handler have a required permission?
boolean allowed = true;
- EventPermissionInfo permInfo = beanContext.getPermissionInfo(handler);
- if (permInfo != null)
+ Map<Method, HandlerInfo> handlerInfos = HandlerInfo.getHandlerInfoCollection( actionBean.getClass() );
+ HandlerInfo eventInfo = handlerInfos.get( handler );
+ if( eventInfo != null )
{
- Permission requiredPermission = permInfo.getPermission(actionBean);
- if (requiredPermission != null)
+ Permission requiredPermission = eventInfo.getPermission( actionBean );
+ if( requiredPermission != null )
{
WikiEngine engine = actionBean.getEngine();
AuthorizationManager mgr = engine.getAuthorizationManager();
WikiSession wikiSession = actionBean.getWikiSession();
- allowed = mgr.checkPermission(wikiSession, requiredPermission);
+ allowed = mgr.checkPermission( wikiSession, requiredPermission );
}
}
// If not allowed, redirect to login page with all parameters intact;
// otherwise proceed
- if (!allowed)
+ if( !allowed )
{
- r = new RedirectResolution(LoginActionBean.class);
- ((RedirectResolution) r).includeRequestParameters(true);
- if (log.isDebugEnabled())
+ r = new RedirectResolution( LoginActionBean.class );
+ ((RedirectResolution) r).includeRequestParameters( true );
+ if( log.isDebugEnabled() )
{
- log.debug("WikiInterceptor rejected access to ActionBean: " + actionBean + ", method " + handler.getName());
+ log.debug( "WikiInterceptor rejected access to ActionBean=" + actionBean.getClass().getCanonicalName() + ", method=" + handler.getName() );
}
return r;
}
- if (log.isDebugEnabled())
+ if( log.isDebugEnabled() )
{
- log.debug("WikiInterceptor resolved ActionBean: " + actionBean);
+ log.debug( "WikiInterceptor resolved ActionBean: " + actionBean );
}
// If not already set, inject WikiEngine as a request attribute (can be
// used later as ${wikiEngine} in EL markup)
WikiEngine engine = beanContext.getWikiEngine();
HttpServletRequest httpRequest = beanContext.getRequest();
- httpRequest.setAttribute(ATTR_WIKIENGINE, engine);
+ httpRequest.setAttribute( ATTR_WIKIENGINE, engine );
// If not already set, Inject the WikiSession as a request attribute
- WikiSession wikiSession = SessionMonitor.getInstance(engine).find(httpRequest.getSession());
- httpRequest.setAttribute(ATTR_WIKISESSION, wikiSession);
+ WikiSession wikiSession = SessionMonitor.getInstance( engine ).find( httpRequest.getSession() );
+ httpRequest.setAttribute( ATTR_WIKISESSION, wikiSession );
// Stash the WikiActionBean and WikiPage in the PageContext
// Note: it probably seems a bit tricky that we're grabbing the
@@ -217,53 +187,10 @@
// case.
// So, the PageContext safe to grab, and boy are we glad that we can!
PageContext pageContext = DispatcherHelper.getPageContext();
- if (pageContext != null)
+ if( pageContext != null )
{
// Save ActionBean to the current context
- WikiActionBeanFactory.saveActionBean(pageContext, actionBean);
- }
-
- return null;
- }
-
- /**
- * Intercepts the
- * {@link net.sourceforge.stripes.controller.LifecycleStage#HandlerResolution}
- * lifecycle stage and injects
- * {@link com.ecyrd.jspwiki.action.EventPermissionInfo} objects into the
- * WikiActionBeanContext if indicated by
- * {@link com.ecyrd.jspwiki.action.EventPermission} annotations on the
- * current ActionBean.
- *
- * @param context
- * the current execution context
- * @return a Resolution if the
- * {@link net.sourceforge.stripes.controller.LifecycleStage#HandlerResolution}
- * lifecycle stage's normal execution returns one; <code>null</code>
- * otherwise
- * @throws Exception
- * if the underlying lifcycle stage's execution throws an
- * Exception
- */
- protected Resolution interceptHandlerResolution(ExecutionContext context) throws Exception
- {
- // Did the handler resolution stage return a Resolution? If so, bail.
- Resolution r = context.proceed();
- if (r != null)
- {
- return r;
- }
-
- // Get the ActionBean and ActionBeanContext
- WikiActionBean actionBean = (WikiActionBean) context.getActionBean();
- WikiActionBeanContext beanContext = actionBean.getContext();
-
- // Stash the EventPermissionInfo items for this ActionBean's event
- // handlers
- Map<Method, EventPermissionInfo> permMap = EventPermissionInfo.getEventPermissionInfo(actionBean.getClass());
- for (Map.Entry<Method, EventPermissionInfo> entry : permMap.entrySet())
- {
- beanContext.addPermissionInfo(entry.getKey(), entry.getValue());
+ WikiActionBeanFactory.saveActionBean( pageContext, actionBean );
}
return null;
Copied: incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/src/com/ecyrd/jspwiki/action/WikiPageTypeConverter.java (from r643690, incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/src/com/ecyrd/jspwiki/ui/WikiPageTypeConverter.java)
URL: http://svn.apache.org/viewvc/incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/src/com/ecyrd/jspwiki/action/WikiPageTypeConverter.java?p2=incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/src/com/ecyrd/jspwiki/action/WikiPageTypeConverter.java&p1=incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/src/com/ecyrd/jspwiki/ui/WikiPageTypeConverter.java&r1=643690&r2=682139&rev=682139&view=diff
==============================================================================
--- incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/src/com/ecyrd/jspwiki/ui/WikiPageTypeConverter.java (original)
+++ incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/src/com/ecyrd/jspwiki/action/WikiPageTypeConverter.java Sun Aug 3 05:12:47 2008
@@ -12,7 +12,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.ecyrd.jspwiki.ui;
+package com.ecyrd.jspwiki.action;
import java.util.Collection;
import java.util.Locale;
Modified: incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/src/com/ecyrd/jspwiki/action/WikiRequestContext.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/src/com/ecyrd/jspwiki/action/WikiRequestContext.java?rev=682139&r1=682138&r2=682139&view=diff
==============================================================================
--- incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/src/com/ecyrd/jspwiki/action/WikiRequestContext.java (original)
+++ incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/src/com/ecyrd/jspwiki/action/WikiRequestContext.java Sun Aug 3 05:12:47 2008
@@ -5,20 +5,25 @@
import java.lang.annotation.*;
+import net.sourceforge.stripes.action.HandlesEvent;
+
/**
- * WikiActionBean annotation that specifies the request context for an ActionBean (e.g., <code>edit</code>).
+ * WikiActionBean method annotation that maps a Stripes ActionBean event name to
+ * a JSPWiki request context (e.g., <code>edit</code>). The method containing
+ * the WikiRequestContext annotation must also have a {@link HandlesEvent}
+ * annotation. The values returned by both annotations do not need to match.
+ *
+ * @see {@link HandlerInfo#getRequestContext(Class, String)}.
* @author Andrew Jaquith
*/
-@Retention(RetentionPolicy.RUNTIME)
-@Target({ElementType.TYPE})
+@Retention( RetentionPolicy.RUNTIME )
+@Target( { ElementType.METHOD } )
@Documented
@Inherited
public @interface WikiRequestContext
{
/**
- * The request context for looking up an ActionBean.
- * If not supplied and the class is a subclass of {@link AbstractActionBean}
- * the superclass default value will be inherited ("none").
+ * The request context associated with an ActionBean event handler method.
*/
String value();
}
Copied: incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/src/com/ecyrd/jspwiki/action/WikiRuntimeConfiguration.java (from r643690, incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/src/com/ecyrd/jspwiki/ui/WikiRuntimeConfiguration.java)
URL: http://svn.apache.org/viewvc/incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/src/com/ecyrd/jspwiki/action/WikiRuntimeConfiguration.java?p2=incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/src/com/ecyrd/jspwiki/action/WikiRuntimeConfiguration.java&p1=incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/src/com/ecyrd/jspwiki/ui/WikiRuntimeConfiguration.java&r1=643690&r2=682139&rev=682139&view=diff
==============================================================================
--- incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/src/com/ecyrd/jspwiki/ui/WikiRuntimeConfiguration.java (original)
+++ incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/src/com/ecyrd/jspwiki/action/WikiRuntimeConfiguration.java Sun Aug 3 05:12:47 2008
@@ -1,9 +1,8 @@
-package com.ecyrd.jspwiki.ui;
+package com.ecyrd.jspwiki.action;
import javax.servlet.ServletContext;
import net.sourceforge.stripes.config.RuntimeConfiguration;
-import net.sourceforge.stripes.validation.TypeConverterFactory;
import org.apache.log4j.Logger;
@@ -52,17 +51,4 @@
{
return m_engine;
}
-
- /**
- * Initializes the Stripes type converter factory, using a special
- * {@link WikiTypeConverterFactory} that knows about JSPWiki object types.
- */
- @Override
- protected TypeConverterFactory initTypeConverterFactory()
- {
- WikiTypeConverterFactory factory = new WikiTypeConverterFactory();
- factory.init(this);
- return factory;
- }
-
}