Return-Path: Delivered-To: apmail-struts-dev-archive@www.apache.org Received: (qmail 25499 invoked from network); 21 Jan 2006 00:25:15 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 21 Jan 2006 00:25:15 -0000 Received: (qmail 22437 invoked by uid 500); 21 Jan 2006 00:22:27 -0000 Delivered-To: apmail-struts-dev-archive@struts.apache.org Received: (qmail 22318 invoked by uid 500); 21 Jan 2006 00:22:27 -0000 Mailing-List: contact dev-help@struts.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Help: List-Post: List-Id: "Struts Developers List" Reply-To: "Struts Developers List" Delivered-To: mailing list dev@struts.apache.org Received: (qmail 22242 invoked by uid 500); 21 Jan 2006 00:22:26 -0000 Received: (qmail 21997 invoked by uid 99); 21 Jan 2006 00:22:24 -0000 Received: from asf.osuosl.org (HELO asf.osuosl.org) (140.211.166.49) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 20 Jan 2006 16:22:24 -0800 X-ASF-Spam-Status: No, hits=-9.4 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received: from [209.237.227.194] (HELO minotaur.apache.org) (209.237.227.194) by apache.org (qpsmtpd/0.29) with SMTP; Fri, 20 Jan 2006 16:22:06 -0800 Received: (qmail 23420 invoked by uid 65534); 21 Jan 2006 00:21:45 -0000 Message-ID: <20060121002145.23418.qmail@minotaur.apache.org> Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r370938 [9/50] - in /struts: action/trunk/ action/trunk/conf/java/ action/trunk/src/java/org/apache/struts/ action/trunk/src/java/org/apache/struts/action/ action/trunk/src/java/org/apache/struts/chain/ action/trunk/src/java/org/apache/stru... Date: Sat, 21 Jan 2006 00:21:00 -0000 To: commits@struts.apache.org From: husted@apache.org X-Mailer: svnmailer-1.0.5 X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N Modified: struts/action/trunk/src/java/org/apache/struts/chain/commands/servlet/SetContentType.java URL: http://svn.apache.org/viewcvs/struts/action/trunk/src/java/org/apache/struts/chain/commands/servlet/SetContentType.java?rev=370938&r1=370937&r2=370938&view=diff ============================================================================== --- struts/action/trunk/src/java/org/apache/struts/chain/commands/servlet/SetContentType.java (original) +++ struts/action/trunk/src/java/org/apache/struts/chain/commands/servlet/SetContentType.java Fri Jan 20 16:19:02 2006 @@ -13,38 +13,27 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.apache.struts.chain.commands.servlet; - -import javax.servlet.http.HttpServletResponse; - import org.apache.struts.chain.commands.AbstractSetContentType; import org.apache.struts.chain.contexts.ActionContext; import org.apache.struts.chain.contexts.ServletActionContext; +import javax.servlet.http.HttpServletResponse; /** *

Check to see if the content type is set, and if so, set it for this * response.

* - * @version $Rev$ $Date$ + * @version $Rev$ $Date: 2005-06-04 10:58:46 -0400 (Sat, 04 Jun 2005) + * $ */ - public class SetContentType extends AbstractSetContentType { - - // ------------------------------------------------------- Protected Methods - - protected void setContentType(ActionContext context, String contentType) { - ServletActionContext swcontext = (ServletActionContext) context; HttpServletResponse response = swcontext.getResponse(); response.setContentType(contentType); - } - - } Modified: struts/action/trunk/src/java/org/apache/struts/chain/commands/servlet/SetOriginalURI.java URL: http://svn.apache.org/viewcvs/struts/action/trunk/src/java/org/apache/struts/chain/commands/servlet/SetOriginalURI.java?rev=370938&r1=370937&r2=370938&view=diff ============================================================================== --- struts/action/trunk/src/java/org/apache/struts/chain/commands/servlet/SetOriginalURI.java (original) +++ struts/action/trunk/src/java/org/apache/struts/chain/commands/servlet/SetOriginalURI.java Fri Jan 20 16:19:02 2006 @@ -1,51 +1,40 @@ -/* - * Copyright 2003,2004 The Apache Software Foundation. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.struts.chain.commands.servlet; - - -import javax.servlet.http.HttpServletRequest; - -import org.apache.struts.Globals; -import org.apache.struts.chain.commands.AbstractSetOriginalURI; -import org.apache.struts.chain.contexts.ActionContext; -import org.apache.struts.chain.contexts.ServletActionContext; - - -/** - *

Set the servlet path.

- * - * @version $Rev: 179995 $ $Date: 2005-06-04 07:58:46 -0700 (Sat, 04 Jun 2005) $ - */ - -public class SetOriginalURI extends AbstractSetOriginalURI { - - - // ------------------------------------------------------- Protected Methods - - - protected void setOriginalURI(ActionContext context) { - - ServletActionContext swcontext = (ServletActionContext) context; - HttpServletRequest request = swcontext.getRequest(); - - request.setAttribute( - Globals.ORIGINAL_URI_KEY, request.getServletPath()); - - } - - -} +/* + * Copyright 2003,2004 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.struts.chain.commands.servlet; + +import org.apache.struts.Globals; +import org.apache.struts.chain.commands.AbstractSetOriginalURI; +import org.apache.struts.chain.contexts.ActionContext; +import org.apache.struts.chain.contexts.ServletActionContext; + +import javax.servlet.http.HttpServletRequest; + +/** + *

Set the servlet path.

+ * + * @version $Rev: 179995 $ $Date: 2005-06-04 07:58:46 -0700 (Sat, 04 Jun 2005) + * $ + */ +public class SetOriginalURI extends AbstractSetOriginalURI { + // ------------------------------------------------------- Protected Methods + protected void setOriginalURI(ActionContext context) { + ServletActionContext swcontext = (ServletActionContext) context; + HttpServletRequest request = swcontext.getRequest(); + + request.setAttribute(Globals.ORIGINAL_URI_KEY, + request.getServletPath()); + } +} Modified: struts/action/trunk/src/java/org/apache/struts/chain/commands/servlet/ValidateActionForm.java URL: http://svn.apache.org/viewcvs/struts/action/trunk/src/java/org/apache/struts/chain/commands/servlet/ValidateActionForm.java?rev=370938&r1=370937&r2=370938&view=diff ============================================================================== --- struts/action/trunk/src/java/org/apache/struts/chain/commands/servlet/ValidateActionForm.java (original) +++ struts/action/trunk/src/java/org/apache/struts/chain/commands/servlet/ValidateActionForm.java Fri Jan 20 16:19:02 2006 @@ -13,10 +13,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.apache.struts.chain.commands.servlet; - import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.struts.action.ActionErrors; @@ -27,56 +25,48 @@ import org.apache.struts.chain.contexts.ServletActionContext; import org.apache.struts.config.ActionConfig; - /** *

Validate the properties of the form bean for this request. If there are * any validation errors, execute the child commands in our chain; otherwise, * proceed normally. Also, if any errors are found and the request is a * multipart request, rollback the MultipartRequestHandler.

* - * @version $Rev$ $Date$ + * @version $Rev$ $Date: 2005-06-04 10:58:46 -0400 (Sat, 04 Jun 2005) + * $ */ - public class ValidateActionForm extends AbstractValidateActionForm { - // ------------------------------------------------------ Instance Variables - - private static final Log log = - LogFactory.getLog(ValidateActionForm.class); - + LogFactory.getLog(ValidateActionForm.class); // ------------------------------------------------------- Protected Methods - /** *

Call the validate() method of the specified form bean, * and return the resulting ActionErrors object.

* - * @param context The context for this request + * @param context The context for this request * @param actionForm The form bean for this request */ protected ActionErrors validate(ActionContext context, ActionConfig actionConfig, ActionForm actionForm) { - ServletActionContext saContext = (ServletActionContext) context; - ActionErrors errors = (actionForm.validate((ActionMapping) actionConfig, - saContext.getRequest())); + ActionErrors errors = + (actionForm.validate((ActionMapping) actionConfig, + saContext.getRequest())); // Special handling for multipart request - if (errors != null && !errors.isEmpty()) { + if ((errors != null) && !errors.isEmpty()) { if (actionForm.getMultipartRequestHandler() != null) { if (log.isTraceEnabled()) { log.trace(" Rolling back multipart request"); } + actionForm.getMultipartRequestHandler().rollback(); } } return errors; - } - - } Modified: struts/action/trunk/src/java/org/apache/struts/chain/commands/util/ClassUtils.java URL: http://svn.apache.org/viewcvs/struts/action/trunk/src/java/org/apache/struts/chain/commands/util/ClassUtils.java?rev=370938&r1=370937&r2=370938&view=diff ============================================================================== --- struts/action/trunk/src/java/org/apache/struts/chain/commands/util/ClassUtils.java (original) +++ struts/action/trunk/src/java/org/apache/struts/chain/commands/util/ClassUtils.java Fri Jan 20 16:19:02 2006 @@ -13,69 +13,56 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.apache.struts.chain.commands.util; + /** *

Utility methods to load application classes and create instances.

* - * @version $Rev$ $Date$ + * @version $Rev$ $Date: 2005-11-12 13:01:44 -0500 (Sat, 12 Nov 2005) + * $ */ - public final class ClassUtils { - - // ---------------------------------------------------------- Static Methods - /** *

Return the Class object for the specified fully * qualified class name, from this web application's class loader. * * @param className Fully qualified class name - * - * @exception ClassNotFoundException if the specified class cannot - * be loaded + * @throws ClassNotFoundException if the specified class cannot be loaded */ public static Class getApplicationClass(String className) - throws ClassNotFoundException { - + throws ClassNotFoundException { if (className == null) { throw new NullPointerException( "getApplicationClass called with null className"); } ClassLoader classLoader = - Thread.currentThread().getContextClassLoader(); + Thread.currentThread().getContextClassLoader(); + if (classLoader == null) { classLoader = ClassUtils.class.getClassLoader(); } - return (classLoader.loadClass(className)); + return (classLoader.loadClass(className)); } - /** *

Return a new instance of the specified fully qualified class name, * after loading the class (if necessary) from this web application's * class loader.

* * @param className Fully qualified class name - * - * @exception ClassNotFoundException if the specified class cannot - * be loaded - * @exception IllegalAccessException if this class is not concrete - * @exception InstantiationException if this class has no zero-arguments - * constructor + * @throws ClassNotFoundException if the specified class cannot be loaded + * @throws IllegalAccessException if this class is not concrete + * @throws InstantiationException if this class has no zero-arguments + * constructor */ public static Object getApplicationInstance(String className) - throws ClassNotFoundException, IllegalAccessException, - InstantiationException { - + throws ClassNotFoundException, IllegalAccessException, + InstantiationException { return (getApplicationClass(className).newInstance()); - } - - - } Modified: struts/action/trunk/src/java/org/apache/struts/chain/contexts/ActionContext.java URL: http://svn.apache.org/viewcvs/struts/action/trunk/src/java/org/apache/struts/chain/contexts/ActionContext.java?rev=370938&r1=370937&r2=370938&view=diff ============================================================================== --- struts/action/trunk/src/java/org/apache/struts/chain/contexts/ActionContext.java (original) +++ struts/action/trunk/src/java/org/apache/struts/chain/contexts/ActionContext.java Fri Jan 20 16:19:02 2006 @@ -1,474 +1,427 @@ -/* - * $Id$ - * - * Copyright 2005 The Apache Software Foundation. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.struts.chain.contexts; - -import java.util.Locale; -import java.util.Map; - -import org.apache.commons.chain.Context; -import org.apache.struts.action.ActionMessages; -import org.apache.struts.util.MessageResources; -import org.apache.struts.action.ActionForm; -import org.apache.struts.config.ActionConfig; -import org.apache.struts.config.ForwardConfig; -import org.apache.struts.config.ModuleConfig; -import org.apache.struts.action.Action; - - -/** - *

An ActionContext represents a view of a commons-chain - * Context which encapsulates access to request - * and session-scoped resources and services

- */ -public interface ActionContext extends Context { - - public static final String APPLICATION_SCOPE = "application"; - - public static final String SESSION_SCOPE = "session"; - - public static final String REQUEST_SCOPE = "request"; - - // ------------------------------- - // General Application Support - // ------------------------------- - /** - * Signal to the instance that it will not be used any more, - * so that any resources which should be cleaned up can be cleaned up. - */ - void release(); - - /** - *

Return a Map of Application scoped values.

- * - *

This is implemented in analogy with the Application scope in - * the Servlet API, but it seems reasonable to expect that any - * Struts implementation will have an equivalent concept.

- * - *

The ultimate meaning of "application scope" is an implementation - * detail left unspecified by Struts.

- * @return A Map of "application scope" attributes. - */ - Map getApplicationScope(); - - /** - *

Return a Map of Session scoped values. A session - * is understood as a sequence of requests made by the same user.

- * - *

This is implemented in analogy with the Session scope in - * the Servlet API, but it seems reasonable to expect that any - * Struts implementation will have an equivalent concept.

- * - *

The ultimate meaning of "session scope" is an implementation detail - * left unspecified by Struts.

- * @return A Map of "session scope" attributes. - */ - Map getSessionScope(); - - /** - *

Return a Map of request scoped values. A - * request is understood as the fundamental motivation for any - * particular instance of an ActionContext.

- * - *

This is implemented in analogy with the Request Context in - * the Servlet API, but it seems reasonable to expect that any - * Struts implementation will have an equivalent concept.

- * - *

The ultimate meaning of "request scope" is an implementation detail - * left unspecified by Struts.

- * @return a Map of "request scope" attributes. - */ - Map getRequestScope(); - - /** - * Return the Map representing the scope identified by - * scopeName. - * Implementations should support at minimum the names associated with - * the constants - * APPLICATION_SCOPE, SESSION_SCOPE, and - * REQUEST_SCOPE, but are permitted to support others - * as well. - * @param scopeName A token identifying a scope, including but not - * limited to APPLICATION_SCOPE, SESSION_SCOPE, - * REQUEST_SCOPE. - * @return A Map of attributes for the specified scope. - */ - Map getScope(String scopeName); - - /** - *

Return a Map of parameters submitted by the user - * as part of this request. The keys to this map will be request - * parameter names (of type String), and the values will be - * String[].

- * - *

This is implemented in analogy with the Request parameters of - * the Servlet API, but it seems reasonable to expect that any - * Struts implementation will have an equivalent concept.

- * @return A map of the request parameter attributes - */ - Map getParameterMap(); - - // ------------------------------- - // General Struts properties - // ------------------------------- - - /** - *

- * Set the action which has been identified to be executed as part - * of processing this request. - *

- * @param action - */ - void setAction(Action action); - - /** - *

- * Get the action which has been identified to be executed as part - * of processing this request. - *

- * @return The action to be executed with this request - */ - Action getAction(); - - /** - *

- * Set the ActionForm instance which will carry any data submitted - * as part of this request. - *

- * @param form The ActionForm instance to use with this request - */ - void setActionForm(ActionForm form); - - /** - *

- * Get the ActionForm instance which will carry any data submitted as - * part of this request. - *

- * @return The ActionForm being used with this request - */ - ActionForm getActionForm(); - - /** - *

- * Set the ActionConfig class contains the details - * for processing this request. - *

- * @param config The ActionConfig class to use with this request - */ - void setActionConfig(ActionConfig config); - - /** - *

- * Get the ActionConfig which contains the details for processing this - * request. - * @return The ActionConfig class being used with this request - *

- */ - ActionConfig getActionConfig(); - - /** - *

- * Set the ForwardConfig which should be used as the basis of the view - * segment of the overall processing. - * This is the primary method of "communication" with - * the "view" sub-chain. - *

- * @param forward The ForwardConfig to use with this request - */ - void setForwardConfig(ForwardConfig forward); - - /** - *

- * Get the ForwardConfig which has been identified as the basis for - * view-processing. - *

- * @return The ForwardConfig being used with this request - */ - ForwardConfig getForwardConfig(); - - /** - *

- * Set the include path which should be processed as part of processing - * this request. - *

- * @param include The include path to be used with this request - */ - void setInclude(String include); - - /** - *

- * Get the include path which should be processed as part of processing - * this request. - *

- * @return The include path being used with this request - */ - String getInclude(); - - /** - *

- * Set the ModuleConfig which is operative for the current request. - *

- * @param config The ModuleConfig to be used with this request - */ - void setModuleConfig(ModuleConfig config); - - /** - *

- * Get the ModuleConfig which is operative for the current request. - *

- * @return The MooduleConfig being used with this request - */ - ModuleConfig getModuleConfig(); - - /** - *

- * Is the ActionForm for this context valid? - * This method does not actually perform form validation. - * It is simply a holder property where processes which perform validation - * can store the results of the validation for other processes' benefit. - *

- * @return Boolean.TRUE if the form passed validation; - * Boolean.FALSE if the form failed validation; - * null if the form has not yet been validated - */ - Boolean getFormValid(); - - /** - *

- * Store the result of the validation of the Context's ActionForm. - *

- * @param valid Whether the ActionForm for this request passes validation - */ - void setFormValid(Boolean valid); - - /** - *

- * Retrieve an exception which may have been caught by some code using - * this ActionContext, usually by an exception handler. - *

- * @return Any exception that may have been caught by this ActionContext - */ - Exception getException(); - - /** - *

- * Store an exception in this context for use by other handling code. - *

- * @param e An exception to be stored for handling by another member - */ - void setException(Exception e); - - // ------------------------------- - // ActionMessage Processing - // ------------------------------- - - /** - *

- * Append the given messages keys to an internal cache, - * creating the cache if one is not already present. - *

- * @param messages New ActionMessages to cache - */ - void addMessages(ActionMessages messages); - - /** - *

- * Append the given errors keys to an internal cache, - * creating the cache if one is not already present. - *

- * @param errors New ActionMessages to cache as errors - */ - void addErrors(ActionMessages errors); - - /** - *

- * Retrieve error messages from an internal cache, - * creating an empty cache if one is not already present. - *

- * @return The ActionMessage cache for errors - */ - ActionMessages getErrors(); - - /** - *

- * Retrieve messages from an internal cache, - * creating an empty cache if one is not already present. - *

- * @return The ActionMessage cache for errors - */ - ActionMessages getMessages(); - - /** - *

- * Save the given error messages to the internal cache, - * clearing any previous messages in the cache. - *

- *

- * If the parameter is null or empty, the internal cache is removed. - *

- * @param errors ActionMesssages to cache as errors - */ - void saveErrors(ActionMessages errors); - - - /** - *

- * Save the given messages to the internal cache, - * clearing any previous messages in the cache. - *

- *

- * If the parameter is null or empty, the internal cache is removed. - *

- * @param messages ActionMesssages to cache - */ - void saveMessages(ActionMessages messages); - - - /** - *

- * Save the given messages to the internal cache, - * clearing any previous messages in the cache, - * but only for the specified scope. - *

- *

- * If the parameter is null or empty, the internal cache is removed. - *

- * @param scope The scope for the internal cache - * @param messages ActionMesssages to cache - */ - void saveMessages(String scope, ActionMessages messages); - - // ------------------------------- - // Token Processing - // ------------------------------- - - /** - *

Generate a new transaction token, to be used for enforcing a single - * request for a particular transaction.

- * - */ - String generateToken(); - - /** - *

- * Indicate whether a transaction token for this context is valid. - *

- *

- * A typical implementation will place a transaction token in the - * session" scope Map and a matching value in the "parameter" Map. - * If the "session" token does not match the "parameter" attribute, - * or the session token is missing, - * then the transactional token is deemed invalid. - *

- */ - boolean isTokenValid(); - - - /** - *

- * Indicate whether a transaction token is stored in the "session" - * scope for this context, optionally clearing the token, - * so that the next check would return false. - *

- * @param reset On true, clear the transactional token - */ - boolean isTokenValid(boolean reset); - - - /** - *

- * Clear any transactional token stored in the "session" scope for - * this context, so that the next check would return false. - *

- */ - void resetToken(); - - - /** - *

- * Save a new transaction token in the "session" scope for this context, - * creating new resources, if needed. - *

- */ - void saveToken(); - - - // ------------------------------- - // Cancel Processing - // ------------------------------- - - /** - *

- * Indicate if the "cancel event" state is set for for this context, - *

- * @see ActionContextBase.CANCEL_KEY - */ - Boolean getCancelled(); - - /** - *

- * Set the "cancel event" state for this context. - *

- *

- * @see ActionContextBase.CANCEL_KEY - * @param cancelled On true, set the cancel event state to true. - * On false, set the cancel event state to false. - */ - void setCancelled(Boolean cancelled); - - - // ------------------------------- - // MessageResources Processing - // ------------------------------- - - /** - *

Return the default message resources for the current module.

- */ - MessageResources getMessageResources(); - - /** - *

Set the default message resources for the current module.

- */ - void setMessageResources(MessageResources resources); - - - /** - *

Return the specified message resources for the current module.

- * @param key The key specified in the - * <message-resources> element for the - * requested bundle - */ - MessageResources getMessageResources(String key); - - // ------------------------------- - // Locale Processing - // ------------------------------- - - /** - *

Return the user's currently selected Locale.

- */ - Locale getLocale(); - - - - /** - *

Set the user's currently selected Locale.

- * @param locale The user's selected Locale to be set, or null - * to select the server's default Locale - */ - void setLocale(Locale locale); -} +/* + * $Id$ + * + * Copyright 2005 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.struts.chain.contexts; + +import org.apache.commons.chain.Context; +import org.apache.struts.action.Action; +import org.apache.struts.action.ActionForm; +import org.apache.struts.action.ActionMessages; +import org.apache.struts.config.ActionConfig; +import org.apache.struts.config.ForwardConfig; +import org.apache.struts.config.ModuleConfig; +import org.apache.struts.util.MessageResources; + +import java.util.Locale; +import java.util.Map; + +/** + *

An ActionContext represents a view of a commons-chain + * Context which encapsulates access to request and + * session-scoped resources and services

+ */ +public interface ActionContext extends Context { + public static final String APPLICATION_SCOPE = "application"; + public static final String SESSION_SCOPE = "session"; + public static final String REQUEST_SCOPE = "request"; + + // ------------------------------- + // General Application Support + // ------------------------------- + + /** + * Signal to the instance that it will not be used any more, so that any + * resources which should be cleaned up can be cleaned up. + */ + void release(); + + /** + *

Return a Map of Application scoped values.

+ * + *

This is implemented in analogy with the Application scope in the + * Servlet API, but it seems reasonable to expect that any Struts + * implementation will have an equivalent concept.

+ * + *

The ultimate meaning of "application scope" is an implementation + * detail left unspecified by Struts.

+ * + * @return A Map of "application scope" attributes. + */ + Map getApplicationScope(); + + /** + *

Return a Map of Session scoped values. A session is + * understood as a sequence of requests made by the same user.

+ * + *

This is implemented in analogy with the Session scope in the Servlet + * API, but it seems reasonable to expect that any Struts implementation + * will have an equivalent concept.

+ * + *

The ultimate meaning of "session scope" is an implementation detail + * left unspecified by Struts.

+ * + * @return A Map of "session scope" attributes. + */ + Map getSessionScope(); + + /** + *

Return a Map of request scoped values. A request is + * understood as the fundamental motivation for any particular instance of + * an ActionContext.

+ * + *

This is implemented in analogy with the Request Context in the + * Servlet API, but it seems reasonable to expect that any Struts + * implementation will have an equivalent concept.

+ * + *

The ultimate meaning of "request scope" is an implementation detail + * left unspecified by Struts.

+ * + * @return a Map of "request scope" attributes. + */ + Map getRequestScope(); + + /** + * Return the Map representing the scope identified by + * scopeName. Implementations should support at minimum the + * names associated with the constants APPLICATION_SCOPE, + * SESSION_SCOPE, and REQUEST_SCOPE, but are + * permitted to support others as well. + * + * @param scopeName A token identifying a scope, including but not limited + * to APPLICATION_SCOPE, SESSION_SCOPE, + * REQUEST_SCOPE. + * @return A Map of attributes for the specified scope. + */ + Map getScope(String scopeName); + + /** + *

Return a Map of parameters submitted by the user as + * part of this request. The keys to this map will be request parameter + * names (of type String), and the values will be + * String[].

+ * + *

This is implemented in analogy with the Request parameters of the + * Servlet API, but it seems reasonable to expect that any Struts + * implementation will have an equivalent concept.

+ * + * @return A map of the request parameter attributes + */ + Map getParameterMap(); + + // ------------------------------- + // General Struts properties + // ------------------------------- + + /** + *

Set the action which has been identified to be executed as part of + * processing this request.

+ * + * @param action + */ + void setAction(Action action); + + /** + *

Get the action which has been identified to be executed as part of + * processing this request.

+ * + * @return The action to be executed with this request + */ + Action getAction(); + + /** + *

Set the ActionForm instance which will carry any data submitted as + * part of this request.

+ * + * @param form The ActionForm instance to use with this request + */ + void setActionForm(ActionForm form); + + /** + *

Get the ActionForm instance which will carry any data submitted as + * part of this request.

+ * + * @return The ActionForm being used with this request + */ + ActionForm getActionForm(); + + /** + *

Set the ActionConfig class contains the details for processing this + * request.

+ * + * @param config The ActionConfig class to use with this request + */ + void setActionConfig(ActionConfig config); + + /** + *

Get the ActionConfig which contains the details for processing this + * request. + * + * @return The ActionConfig class being used with this request

+ */ + ActionConfig getActionConfig(); + + /** + *

Set the ForwardConfig which should be used as the basis of the view + * segment of the overall processing. This is the primary method of + * "communication" with the "view" sub-chain.

+ * + * @param forward The ForwardConfig to use with this request + */ + void setForwardConfig(ForwardConfig forward); + + /** + *

Get the ForwardConfig which has been identified as the basis for + * view-processing.

+ * + * @return The ForwardConfig being used with this request + */ + ForwardConfig getForwardConfig(); + + /** + *

Set the include path which should be processed as part of + * processing this request.

+ * + * @param include The include path to be used with this request + */ + void setInclude(String include); + + /** + *

Get the include path which should be processed as part of + * processing this request.

+ * + * @return The include path being used with this request + */ + String getInclude(); + + /** + *

Set the ModuleConfig which is operative for the current request. + *

+ * + * @param config The ModuleConfig to be used with this request + */ + void setModuleConfig(ModuleConfig config); + + /** + *

Get the ModuleConfig which is operative for the current request. + *

+ * + * @return The MooduleConfig being used with this request + */ + ModuleConfig getModuleConfig(); + + /** + *

Is the ActionForm for this context valid? This method does + * not actually perform form validation. It is simply a holder + * property where processes which perform validation can store the results + * of the validation for other processes' benefit.

+ * + * @return Boolean.TRUE if the form passed validation; + * Boolean.FALSE if the form failed validation; null + * if the form has not yet been validated + */ + Boolean getFormValid(); + + /** + *

Store the result of the validation of the Context's ActionForm. + *

+ * + * @param valid Whether the ActionForm for this request passes validation + */ + void setFormValid(Boolean valid); + + /** + *

Retrieve an exception which may have been caught by some code using + * this ActionContext, usually by an exception handler.

+ * + * @return Any exception that may have been caught by this ActionContext + */ + Exception getException(); + + /** + *

Store an exception in this context for use by other handling code. + *

+ * + * @param e An exception to be stored for handling by another member + */ + void setException(Exception e); + + // ------------------------------- + // ActionMessage Processing + // ------------------------------- + + /** + *

Append the given messages keys to an internal cache, creating the + * cache if one is not already present.

+ * + * @param messages New ActionMessages to cache + */ + void addMessages(ActionMessages messages); + + /** + *

Append the given errors keys to an internal cache, creating the + * cache if one is not already present.

+ * + * @param errors New ActionMessages to cache as errors + */ + void addErrors(ActionMessages errors); + + /** + *

Retrieve error messages from an internal cache, creating an empty + * cache if one is not already present.

+ * + * @return The ActionMessage cache for errors + */ + ActionMessages getErrors(); + + /** + *

Retrieve messages from an internal cache, creating an empty cache + * if one is not already present.

+ * + * @return The ActionMessage cache for errors + */ + ActionMessages getMessages(); + + /** + *

Save the given error messages to the internal cache, clearing any + * previous messages in the cache.

If the parameter is null or + * empty, the internal cache is removed.

+ * + * @param errors ActionMesssages to cache as errors + */ + void saveErrors(ActionMessages errors); + + /** + *

Save the given messages to the internal cache, clearing any + * previous messages in the cache.

If the parameter is null or + * empty, the internal cache is removed.

+ * + * @param messages ActionMesssages to cache + */ + void saveMessages(ActionMessages messages); + + /** + *

Save the given messages to the internal cache, clearing any + * previous messages in the cache, but only for the specified scope.

+ *

If the parameter is null or empty, the internal cache is removed. + *

+ * + * @param scope The scope for the internal cache + * @param messages ActionMesssages to cache + */ + void saveMessages(String scope, ActionMessages messages); + + // ------------------------------- + // Token Processing + // ------------------------------- + + /** + *

Generate a new transaction token, to be used for enforcing a single + * request for a particular transaction.

+ */ + String generateToken(); + + /** + *

Indicate whether a transaction token for this context is valid. + *

A typical implementation will place a transaction token in the + * session" scope Map and a matching value in the "parameter" Map. If the + * "session" token does not match the "parameter" attribute, or the + * session token is missing, then the transactional token is deemed + * invalid.

+ */ + boolean isTokenValid(); + + /** + *

Indicate whether a transaction token is stored in the "session" + * scope for this context, optionally clearing the token, so that the next + * check would return false.

+ * + * @param reset On true, clear the transactional token + */ + boolean isTokenValid(boolean reset); + + /** + *

Clear any transactional token stored in the "session" scope for + * this context, so that the next check would return false.

+ */ + void resetToken(); + + /** + *

Save a new transaction token in the "session" scope for this + * context, creating new resources, if needed.

+ */ + void saveToken(); + + // ------------------------------- + // Cancel Processing + // ------------------------------- + + /** + *

Indicate if the "cancel event" state is set for for this context, + *

+ * + * @see ActionContextBase.CANCEL_KEY + */ + Boolean getCancelled(); + + /** + *

Set the "cancel event" state for this context.

+ * + * @param cancelled On true, set the cancel event state to true. On false, + * set the cancel event state to false. + * @see ActionContextBase.CANCEL_KEY + */ + void setCancelled(Boolean cancelled); + + // ------------------------------- + // MessageResources Processing + // ------------------------------- + + /** + *

Return the default message resources for the current module.

+ */ + MessageResources getMessageResources(); + + /** + *

Set the default message resources for the current module.

+ */ + void setMessageResources(MessageResources resources); + + /** + *

Return the specified message resources for the current module.

+ * + * @param key The key specified in the <message-resources> + * element for the requested bundle + */ + MessageResources getMessageResources(String key); + + // ------------------------------- + // Locale Processing + // ------------------------------- + + /** + *

Return the user's currently selected Locale.

+ */ + Locale getLocale(); + + /** + *

Set the user's currently selected Locale.

+ * + * @param locale The user's selected Locale to be set, or null to select + * the server's default Locale + */ + void setLocale(Locale locale); +} Modified: struts/action/trunk/src/java/org/apache/struts/chain/contexts/ActionContextBase.java URL: http://svn.apache.org/viewcvs/struts/action/trunk/src/java/org/apache/struts/chain/contexts/ActionContextBase.java?rev=370938&r1=370937&r2=370938&view=diff ============================================================================== --- struts/action/trunk/src/java/org/apache/struts/chain/contexts/ActionContextBase.java (original) +++ struts/action/trunk/src/java/org/apache/struts/chain/contexts/ActionContextBase.java Fri Jan 20 16:19:02 2006 @@ -1,567 +1,554 @@ -/* - * $Id$ - * - * Copyright 2005 The Apache Software Foundation. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.struts.chain.contexts; - -import java.util.Locale; -import java.util.Map; - -import org.apache.commons.chain.Context; -import org.apache.commons.chain.impl.ContextBase; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.apache.struts.action.Action; -import org.apache.struts.action.ActionForm; -import org.apache.struts.action.ActionMessages; -import org.apache.struts.chain.Constants; -import org.apache.struts.config.ActionConfig; -import org.apache.struts.config.FormBeanConfig; -import org.apache.struts.config.ForwardConfig; -import org.apache.struts.config.ModuleConfig; -import org.apache.struts.util.MessageResources; -import org.apache.struts.util.TokenProcessor; - - -/** - *

- * Provide an abstract but semi-complete implementation of ActionContext - * to serve as the base for concrete implementations. - *

- *

- * The abstract methods to implement are the accessors for the named states, - * getApplicationScope, - * getRequestScope, and - * getSessionScope. - *

- */ -public abstract class ActionContextBase - extends ContextWrapper - implements ActionContext { - - /** - * @see Constants.ACTION_KEY - */ - public static final String ACTION_KEY = Constants.ACTION_KEY; - - /** - * @see - */ - public static final String ACTION_CONFIG_KEY = Constants.ACTION_CONFIG_KEY; - - /** - * @see Constants.ACTION_FORM_KEY - */ - public static final String ACTION_FORM_KEY = Constants.ACTION_FORM_KEY; - - /** - * @see Constants.FORWARD_CONFIG_KEY - */ - public static final String FORWARD_CONFIG_KEY = - Constants.FORWARD_CONFIG_KEY; - - /** - * @see Constants.MODULE_CONFIG_KEY - */ - public static final String MODULE_CONFIG_KEY = Constants.MODULE_CONFIG_KEY; - - /** - * @see Constants.EXCEPTION_KEY - */ - public static final String EXCEPTION_KEY = Constants.EXCEPTION_KEY; - - /** - *

- * Provide the default context attribute under which to store - * the ActionMessage cache for errors. - *

- */ - public static final String ERROR_ACTION_MESSAGES_KEY = "errors"; - - /** - *

- * Provide the default context attribute under which to store - * the ActionMessage cache. - *

- */ - public static final String MESSAGE_ACTION_MESSAGES_KEY = "messages"; - - /** - * @see Constants.MESSAGE_RESOURCES_KEY - */ - public static final String MESSAGE_RESOURCES_KEY = - Constants.MESSAGE_RESOURCES_KEY; - - /** - * @see Constants.INCLUDE_KEY - */ - public static final String INCLUDE_KEY = Constants.INCLUDE_KEY; - - /** - * @see Constants.LOCALE_KEY - */ - public static final String LOCALE_KEY = Constants.LOCALE_KEY; - - /** - * @see Constants.CANCEL_KEY - */ - public static final String CANCEL_KEY = Constants.CANCEL_KEY; - - /** - * @see Constants.VALID_KEY - */ - public static final String VALID_KEY = Constants.VALID_KEY; - - /** - * Provide the default context attribute under which to store - * the transaction token key. - */ - public static final String TRANSACTION_TOKEN_KEY = "TRANSACTION_TOKEN_KEY"; - - /** - * Provide the default context attribute under which to store - * the token key. - */ - public static final String TOKEN_KEY = "TOKEN_KEY"; - - /** - * Store the TokenProcessor instance for this Context. - */ - protected TokenProcessor token = null; - - /** - * Store the Log instance for this Context. - */ - private Log logger = null; - - /** - * Instantiate ActionContextBase, wrapping the given Context. - * @param context Context to wrap - */ - public ActionContextBase(Context context) { - super(context); - token = TokenProcessor.getInstance(); - logger = LogFactory.getLog(this.getClass()); - } - - /** - * Instantiate ActionContextBase, wrapping a default ContextBase instance. - */ - public ActionContextBase() { - this(new ContextBase()); - } - - // ------------------------------- - // General Application Support - // ------------------------------- - - public void release() { - this.token = null; - } - - public abstract Map getApplicationScope(); - - public abstract Map getRequestScope(); - - public abstract Map getSessionScope(); - - public Map getScope(String scopeName) { - if (REQUEST_SCOPE.equals(scopeName)) { - return this.getRequestScope(); - } - if (SESSION_SCOPE.equals(scopeName)) { - return this.getSessionScope(); - } - if (APPLICATION_SCOPE.equals(scopeName)) { - return this.getApplicationScope(); - } - throw new IllegalArgumentException("Invalid scope: " + scopeName); - } - - // ------------------------------- - // General Struts properties - // ------------------------------- - public void setAction(Action action) { - this.put(ACTION_KEY, action); - } - - public Action getAction() { - return (Action) this.get(ACTION_KEY); - } - - public void setActionForm(ActionForm form) { - this.put(ACTION_FORM_KEY, form); - } - - public ActionForm getActionForm() { - return (ActionForm) this.get(ACTION_FORM_KEY); - } - - public void setActionConfig(ActionConfig config) { - this.put(ACTION_CONFIG_KEY, config); - } - - public ActionConfig getActionConfig() { - return (ActionConfig) this.get(ACTION_CONFIG_KEY); - } - - public void setForwardConfig(ForwardConfig forward) { - this.put(FORWARD_CONFIG_KEY, forward); - } - - public ForwardConfig getForwardConfig() { - return (ForwardConfig) this.get(FORWARD_CONFIG_KEY); - } - - public void setInclude(String include) { - this.put(INCLUDE_KEY, include); - } - - public String getInclude() { - return (String) this.get(INCLUDE_KEY); - } - - public Boolean getFormValid() { - return (Boolean) this.get(VALID_KEY); - } - - public void setFormValid(Boolean valid) { - this.put(VALID_KEY, valid); - } - - public ModuleConfig getModuleConfig() { - return (ModuleConfig) this.get(MODULE_CONFIG_KEY); - } - - public void setModuleConfig(ModuleConfig config) { - this.put(MODULE_CONFIG_KEY, config); - } - - public Exception getException() { - return (Exception) this.get(EXCEPTION_KEY); - } - - public void setException(Exception e) { - this.put(EXCEPTION_KEY, e); - } - - // ------------------------------- - // ActionMessage Processing - // ------------------------------- - - public void addMessages(ActionMessages messages) { - this.addActionMessages(MESSAGE_ACTION_MESSAGES_KEY, messages); - } - - public void addErrors(ActionMessages errors) { - this.addActionMessages(ERROR_ACTION_MESSAGES_KEY, errors); - } - - public ActionMessages getErrors() { - return (ActionMessages) this.get(ERROR_ACTION_MESSAGES_KEY); - } - - public ActionMessages getMessages() { - return (ActionMessages) this.get(MESSAGE_ACTION_MESSAGES_KEY); - } - - public void saveErrors(ActionMessages errors) { - this.saveActionMessages(ERROR_ACTION_MESSAGES_KEY, errors); - } - - public void saveMessages(ActionMessages messages) { - this.saveActionMessages(MESSAGE_ACTION_MESSAGES_KEY, messages); - } - - // ISSUE: do we want to add this to the public API? - - /** - *

- * Add the given messages to a cache stored in this Context, under key. - *

- * @param key The attribute name for the message cache - * @param messages The ActionMessages to add - */ - public void addActionMessages(String key, ActionMessages messages) { - - if (messages == null) { - // bad programmer! *slap* - return; - } - - // get any existing messages from the request, or make a new one - ActionMessages requestMessages = (ActionMessages) this.get(key); - if (requestMessages == null) { - requestMessages = new ActionMessages(); - } - // add incoming messages - requestMessages.add(messages); - - // if still empty, just wipe it out from the request - this.remove(key); - - // save the messages - this.saveActionMessages(key, requestMessages); - } - - // ISSUE: do we want to add this to the public API? - - /** - *

- * Save the given ActionMessages into the request scope under the given key, - * clearing the attribute if the messages are empty or null. - *

- * @param key The attribute name for the message cache - * @param messages The ActionMessages to add - */ - public void saveActionMessages(String key, ActionMessages messages) { - this.saveActionMessages(REQUEST_SCOPE, key, messages); - } - - /** - *

Save the given messages into the map identified by the - * given scopeId under the given key.

- * @param scopeId - * @param key - * @param messages - */ - public void saveActionMessages(String scopeId, - String key, - ActionMessages messages) { - Map scope = getScope(scopeId); - if ((messages == null) || messages.isEmpty()) { - scope.remove(key); - return; - } - scope.put(key, messages); - } - - // ISSUE: Should we deprecate this method, since it is misleading? - // Do we need it for backward compatibility? - - /** - *

- * Adapt a legacy form of SaveMessages to the ActionContext API - * by storing the ActoinMessages under the default scope. - * @param scope The scope for the internal cache - * @param messages ActionMesssages to cache - */ - public void saveMessages(String scope, ActionMessages messages) { - this.saveMessages(messages); - } - - - // ------------------------------- - // Token Processing - // ------------------------------- - - // ISSUE: Should there be a getToken method? - // Is there a problem trying to map this method from Action - // to ActionContext when we aren't necessarily sure how token - // processing maps into a context with an ill-defined "session"? - // There's no getToken() method, but maybe there should be. * - - public void saveToken() { - String token = this.generateToken(); - this.put(TRANSACTION_TOKEN_KEY, token); - } - - public String generateToken() { - return token.generateToken(getTokenGeneratorId()); - - } - - // ISSUE: The original implementation was based on the HttpSession - // identifier; what would be a way to do that without depending on the - // Servlet API? - // REPLY: uuid's - // http://java.sun.com/products/jini/2.0/doc/specs/api/net/jini/id/Uuid.html - - protected String getTokenGeneratorId() { - return ""; - - } - - public boolean isTokenValid() { - return this.isTokenValid(false); - } - - public boolean isTokenValid(boolean reset) { - - // Retrieve the transaction token from this session, and - // reset it if requested - String saved = (String) this.get(TRANSACTION_TOKEN_KEY); - if (saved == null) { - return false; - } - - if (reset) { - this.resetToken(); - } - - // Retrieve the transaction token included in this request - String token = (String) this.get(TOKEN_KEY); - if (token == null) { - return false; - } - - return saved.equals(token); - } - - public void resetToken() { - this.remove(TRANSACTION_TOKEN_KEY); - } - - // ------------------------------- - // Cancel Processing - // ------------------------------- - - public Boolean getCancelled() { - return (Boolean) this.get(CANCEL_KEY); - } - - public void setCancelled(Boolean cancelled) { - this.put(CANCEL_KEY, cancelled); - } - - // ------------------------------- - // MessageResources Processing - // ------------------------------- - - public void setMessageResources(MessageResources messageResources) { - this.put(MESSAGE_RESOURCES_KEY, messageResources); - } - - public MessageResources getMessageResources() { - return (MessageResources) this.get(MESSAGE_RESOURCES_KEY); - } - - public MessageResources getMessageResources(String key) { - return (MessageResources) this.get(key); - } - - // ------------------------------- - // Locale Processing - // ------------------------------- - - public void setLocale(Locale locale) { - this.put(LOCALE_KEY, locale); - } - - - public Locale getLocale() { - return (Locale) this.get(LOCALE_KEY); - } - - // ------------------------------- - // Convenience Methods: these are not part of the formal ActionContext API, - // but are likely to be commonly useful. - // ------------------------------- - - /** - *

- * Provide the currently configured commons-logging Log - * instance. - *

- * @return Log instance for this context - */ - public Log getLogger() { - return this.logger; - } - - /** - *

- * Set the commons-logging Log instance which should be - * used to log messages. - * This is initialized at instantiation time but may be overridden. - * Be advised not to set the value to null, - * as ActionContextBase uses the logger for some of its own - * operations. - *

- */ - public void setLogger(Log logger) { - this.logger = logger; - } - - /** - *

- * Using this ActionContext's default - * ModuleConfig, return an existing - * ActionForm in the specified scope, - * or create a new one and add it to the specified scope. - *

- * @param formName The name attribute of our ActionForm - * @param scopeName The scope identier (request, session) - * @return The ActionForm for this request - * @throws IllegalAccessException - * @throws InstantiationException - * @see this.findOrCreateActionForm(String, String, ModuleConfig) - */ - public ActionForm findOrCreateActionForm(String formName, - String scopeName) throws - IllegalAccessException, InstantiationException { - return this.findOrCreateActionForm(formName, scopeName, - this.getModuleConfig()); - } - - /** - *

- * In the context of the given ModuleConfig - * and this ActionContext, - * look for an existing ActionForm in the specified scope. - * If one is found, return it; - * otherwise, create a new instance, add it to that scope, - * and then return it. - *

- * @param formName The name attribute of our ActionForm - * @param scopeName The scope identier (request, session) - * @return The ActionForm for this request - * @throws IllegalAccessException If object cannot be created - * @throws InstantiationException If object cannot be created - * @throws IllegalArgumentException If form config is missing from module - * or scopeName is invalid - */ - public ActionForm findOrCreateActionForm(String formName, String - scopeName, ModuleConfig moduleConfig) throws - IllegalAccessException, InstantiationException { - Map scope = this.getScope(scopeName); - - ActionForm instance; - FormBeanConfig formBeanConfig = - moduleConfig.findFormBeanConfig(formName); - - if (formBeanConfig == null) { - throw new IllegalArgumentException("No form config found under " + - formName + " in module " + moduleConfig.getPrefix() ); - } - - instance = (ActionForm) scope.get(formName); - // ISSUE: Can we recycle the existing instance (if any)? - if (instance != null) { - getLogger().trace("Found an instance in scope " + scopeName + - "; test for reusability"); - if (formBeanConfig.canReuse(instance)) { - return instance; - } - } - - ActionForm form = formBeanConfig.createActionForm(this); - // ISSUE: Should we check this call to put? - scope.put(formName, form); - return form; - } - -} +/* + * $Id$ + * + * Copyright 2005 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.struts.chain.contexts; + +import org.apache.commons.chain.Context; +import org.apache.commons.chain.impl.ContextBase; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.apache.struts.action.Action; +import org.apache.struts.action.ActionForm; +import org.apache.struts.action.ActionMessages; +import org.apache.struts.chain.Constants; +import org.apache.struts.config.ActionConfig; +import org.apache.struts.config.FormBeanConfig; +import org.apache.struts.config.ForwardConfig; +import org.apache.struts.config.ModuleConfig; +import org.apache.struts.util.MessageResources; +import org.apache.struts.util.TokenProcessor; + +import java.util.Locale; +import java.util.Map; + +/** + *

Provide an abstract but semi-complete implementation of ActionContext + * to serve as the base for concrete implementations.

The abstract + * methods to implement are the accessors for the named states, + * getApplicationScope, getRequestScope, and + * getSessionScope.

+ */ +public abstract class ActionContextBase extends ContextWrapper + implements ActionContext { + /** + * @see Constants.ACTION_KEY + */ + public static final String ACTION_KEY = Constants.ACTION_KEY; + + /** + * @see + */ + public static final String ACTION_CONFIG_KEY = + Constants.ACTION_CONFIG_KEY; + + /** + * @see Constants.ACTION_FORM_KEY + */ + public static final String ACTION_FORM_KEY = Constants.ACTION_FORM_KEY; + + /** + * @see Constants.FORWARD_CONFIG_KEY + */ + public static final String FORWARD_CONFIG_KEY = + Constants.FORWARD_CONFIG_KEY; + + /** + * @see Constants.MODULE_CONFIG_KEY + */ + public static final String MODULE_CONFIG_KEY = + Constants.MODULE_CONFIG_KEY; + + /** + * @see Constants.EXCEPTION_KEY + */ + public static final String EXCEPTION_KEY = Constants.EXCEPTION_KEY; + + /** + *

Provide the default context attribute under which to store the + * ActionMessage cache for errors.

+ */ + public static final String ERROR_ACTION_MESSAGES_KEY = "errors"; + + /** + *

Provide the default context attribute under which to store the + * ActionMessage cache.

+ */ + public static final String MESSAGE_ACTION_MESSAGES_KEY = "messages"; + + /** + * @see Constants.MESSAGE_RESOURCES_KEY + */ + public static final String MESSAGE_RESOURCES_KEY = + Constants.MESSAGE_RESOURCES_KEY; + + /** + * @see Constants.INCLUDE_KEY + */ + public static final String INCLUDE_KEY = Constants.INCLUDE_KEY; + + /** + * @see Constants.LOCALE_KEY + */ + public static final String LOCALE_KEY = Constants.LOCALE_KEY; + + /** + * @see Constants.CANCEL_KEY + */ + public static final String CANCEL_KEY = Constants.CANCEL_KEY; + + /** + * @see Constants.VALID_KEY + */ + public static final String VALID_KEY = Constants.VALID_KEY; + + /** + * Provide the default context attribute under which to store the + * transaction token key. + */ + public static final String TRANSACTION_TOKEN_KEY = + "TRANSACTION_TOKEN_KEY"; + + /** + * Provide the default context attribute under which to store the token + * key. + */ + public static final String TOKEN_KEY = "TOKEN_KEY"; + + /** + * Store the TokenProcessor instance for this Context. + */ + protected TokenProcessor token = null; + + /** + * Store the Log instance for this Context. + */ + private Log logger = null; + + /** + * Instantiate ActionContextBase, wrapping the given Context. + * + * @param context Context to wrap + */ + public ActionContextBase(Context context) { + super(context); + token = TokenProcessor.getInstance(); + logger = LogFactory.getLog(this.getClass()); + } + + /** + * Instantiate ActionContextBase, wrapping a default ContextBase + * instance. + */ + public ActionContextBase() { + this(new ContextBase()); + } + + // ------------------------------- + // General Application Support + // ------------------------------- + public void release() { + this.token = null; + } + + public abstract Map getApplicationScope(); + + public abstract Map getRequestScope(); + + public abstract Map getSessionScope(); + + public Map getScope(String scopeName) { + if (REQUEST_SCOPE.equals(scopeName)) { + return this.getRequestScope(); + } + + if (SESSION_SCOPE.equals(scopeName)) { + return this.getSessionScope(); + } + + if (APPLICATION_SCOPE.equals(scopeName)) { + return this.getApplicationScope(); + } + + throw new IllegalArgumentException("Invalid scope: " + scopeName); + } + + // ------------------------------- + // General Struts properties + // ------------------------------- + public void setAction(Action action) { + this.put(ACTION_KEY, action); + } + + public Action getAction() { + return (Action) this.get(ACTION_KEY); + } + + public void setActionForm(ActionForm form) { + this.put(ACTION_FORM_KEY, form); + } + + public ActionForm getActionForm() { + return (ActionForm) this.get(ACTION_FORM_KEY); + } + + public void setActionConfig(ActionConfig config) { + this.put(ACTION_CONFIG_KEY, config); + } + + public ActionConfig getActionConfig() { + return (ActionConfig) this.get(ACTION_CONFIG_KEY); + } + + public void setForwardConfig(ForwardConfig forward) { + this.put(FORWARD_CONFIG_KEY, forward); + } + + public ForwardConfig getForwardConfig() { + return (ForwardConfig) this.get(FORWARD_CONFIG_KEY); + } + + public void setInclude(String include) { + this.put(INCLUDE_KEY, include); + } + + public String getInclude() { + return (String) this.get(INCLUDE_KEY); + } + + public Boolean getFormValid() { + return (Boolean) this.get(VALID_KEY); + } + + public void setFormValid(Boolean valid) { + this.put(VALID_KEY, valid); + } + + public ModuleConfig getModuleConfig() { + return (ModuleConfig) this.get(MODULE_CONFIG_KEY); + } + + public void setModuleConfig(ModuleConfig config) { + this.put(MODULE_CONFIG_KEY, config); + } + + public Exception getException() { + return (Exception) this.get(EXCEPTION_KEY); + } + + public void setException(Exception e) { + this.put(EXCEPTION_KEY, e); + } + + // ------------------------------- + // ActionMessage Processing + // ------------------------------- + public void addMessages(ActionMessages messages) { + this.addActionMessages(MESSAGE_ACTION_MESSAGES_KEY, messages); + } + + public void addErrors(ActionMessages errors) { + this.addActionMessages(ERROR_ACTION_MESSAGES_KEY, errors); + } + + public ActionMessages getErrors() { + return (ActionMessages) this.get(ERROR_ACTION_MESSAGES_KEY); + } + + public ActionMessages getMessages() { + return (ActionMessages) this.get(MESSAGE_ACTION_MESSAGES_KEY); + } + + public void saveErrors(ActionMessages errors) { + this.saveActionMessages(ERROR_ACTION_MESSAGES_KEY, errors); + } + + public void saveMessages(ActionMessages messages) { + this.saveActionMessages(MESSAGE_ACTION_MESSAGES_KEY, messages); + } + + // ISSUE: do we want to add this to the public API? + + /** + *

Add the given messages to a cache stored in this Context, under + * key.

+ * + * @param key The attribute name for the message cache + * @param messages The ActionMessages to add + */ + public void addActionMessages(String key, ActionMessages messages) { + if (messages == null) { + // bad programmer! *slap* + return; + } + + // get any existing messages from the request, or make a new one + ActionMessages requestMessages = (ActionMessages) this.get(key); + + if (requestMessages == null) { + requestMessages = new ActionMessages(); + } + + // add incoming messages + requestMessages.add(messages); + + // if still empty, just wipe it out from the request + this.remove(key); + + // save the messages + this.saveActionMessages(key, requestMessages); + } + + // ISSUE: do we want to add this to the public API? + + /** + *

Save the given ActionMessages into the request scope under the + * given key, clearing the attribute if the messages are empty or null. + *

+ * + * @param key The attribute name for the message cache + * @param messages The ActionMessages to add + */ + public void saveActionMessages(String key, ActionMessages messages) { + this.saveActionMessages(REQUEST_SCOPE, key, messages); + } + + /** + *

Save the given messages into the map identified by the + * given scopeId under the given key.

+ * + * @param scopeId + * @param key + * @param messages + */ + public void saveActionMessages(String scopeId, String key, + ActionMessages messages) { + Map scope = getScope(scopeId); + + if ((messages == null) || messages.isEmpty()) { + scope.remove(key); + + return; + } + + scope.put(key, messages); + } + + // ISSUE: Should we deprecate this method, since it is misleading? + // Do we need it for backward compatibility? + + /** + *

Adapt a legacy form of SaveMessages to the ActionContext API by + * storing the ActoinMessages under the default scope. + * + * @param scope The scope for the internal cache + * @param messages ActionMesssages to cache + */ + public void saveMessages(String scope, ActionMessages messages) { + this.saveMessages(messages); + } + + // ------------------------------- + // Token Processing + // ------------------------------- + // ISSUE: Should there be a getToken method? + // Is there a problem trying to map this method from Action + // to ActionContext when we aren't necessarily sure how token + // processing maps into a context with an ill-defined "session"? + // There's no getToken() method, but maybe there should be. * + public void saveToken() { + String token = this.generateToken(); + + this.put(TRANSACTION_TOKEN_KEY, token); + } + + public String generateToken() { + return token.generateToken(getTokenGeneratorId()); + } + + // ISSUE: The original implementation was based on the HttpSession + // identifier; what would be a way to do that without depending on the + // Servlet API? + // REPLY: uuid's + // http://java.sun.com/products/jini/2.0/doc/specs/api/net/jini/id/Uuid.html + protected String getTokenGeneratorId() { + return ""; + } + + public boolean isTokenValid() { + return this.isTokenValid(false); + } + + public boolean isTokenValid(boolean reset) { + // Retrieve the transaction token from this session, and + // reset it if requested + String saved = (String) this.get(TRANSACTION_TOKEN_KEY); + + if (saved == null) { + return false; + } + + if (reset) { + this.resetToken(); + } + + // Retrieve the transaction token included in this request + String token = (String) this.get(TOKEN_KEY); + + if (token == null) { + return false; + } + + return saved.equals(token); + } + + public void resetToken() { + this.remove(TRANSACTION_TOKEN_KEY); + } + + // ------------------------------- + // Cancel Processing + // ------------------------------- + public Boolean getCancelled() { + return (Boolean) this.get(CANCEL_KEY); + } + + public void setCancelled(Boolean cancelled) { + this.put(CANCEL_KEY, cancelled); + } + + // ------------------------------- + // MessageResources Processing + // ------------------------------- + public void setMessageResources(MessageResources messageResources) { + this.put(MESSAGE_RESOURCES_KEY, messageResources); + } + + public MessageResources getMessageResources() { + return (MessageResources) this.get(MESSAGE_RESOURCES_KEY); + } + + public MessageResources getMessageResources(String key) { + return (MessageResources) this.get(key); + } + + // ------------------------------- + // Locale Processing + // ------------------------------- + public void setLocale(Locale locale) { + this.put(LOCALE_KEY, locale); + } + + public Locale getLocale() { + return (Locale) this.get(LOCALE_KEY); + } + + // ------------------------------- + // Convenience Methods: these are not part of the formal ActionContext API, + // but are likely to be commonly useful. + // ------------------------------- + + /** + *

Provide the currently configured commons-logging Log + * instance.

+ * + * @return Log instance for this context + */ + public Log getLogger() { + return this.logger; + } + + /** + *

Set the commons-logging Log instance which should be + * used to log messages. This is initialized at instantiation time but may + * be overridden. Be advised not to set the value to null, as + * ActionContextBase uses the logger for some of its own + * operations.

+ */ + public void setLogger(Log logger) { + this.logger = logger; + } + + /** + *

Using this ActionContext's default + * ModuleConfig, return an existing ActionForm + * in the specified scope, or create a new one and add it to the specified + * scope.

+ * + * @param formName The name attribute of our ActionForm + * @param scopeName The scope identier (request, session) + * @return The ActionForm for this request + * @throws IllegalAccessException + * @throws InstantiationException + * @see this.findOrCreateActionForm(String, String, ModuleConfig) + */ + public ActionForm findOrCreateActionForm(String formName, + String scopeName) + throws IllegalAccessException, InstantiationException { + return this.findOrCreateActionForm(formName, scopeName, + this.getModuleConfig()); + } + + /** + *

In the context of the given ModuleConfig and this + * ActionContext, look for an existing + * ActionForm in the specified scope. If one is found, return + * it; otherwise, create a new instance, add it to that scope, and then + * return it.

+ * + * @param formName The name attribute of our ActionForm + * @param scopeName The scope identier (request, session) + * @return The ActionForm for this request + * @throws IllegalAccessException If object cannot be created + * @throws InstantiationException If object cannot be created + * @throws IllegalArgumentException If form config is missing from module + * or scopeName is invalid + */ + public ActionForm findOrCreateActionForm(String formName, + String scopeName, + ModuleConfig moduleConfig) + throws IllegalAccessException, InstantiationException { + Map scope = this.getScope(scopeName); + + ActionForm instance; + FormBeanConfig formBeanConfig = + moduleConfig.findFormBeanConfig(formName); + + if (formBeanConfig == null) { + throw new IllegalArgumentException("No form config found under " + + formName + " in module " + moduleConfig.getPrefix()); + } + + instance = (ActionForm) scope.get(formName); + + // ISSUE: Can we recycle the existing instance (if any)? + if (instance != null) { + getLogger().trace("Found an instance in scope " + scopeName + + "; test for reusability"); + + if (formBeanConfig.canReuse(instance)) { + return instance; + } + } + + ActionForm form = formBeanConfig.createActionForm(this); + + // ISSUE: Should we check this call to put? + scope.put(formName, form); + + return form; + } +} Modified: struts/action/trunk/src/java/org/apache/struts/chain/contexts/ContextWrapper.java URL: http://svn.apache.org/viewcvs/struts/action/trunk/src/java/org/apache/struts/chain/contexts/ContextWrapper.java?rev=370938&r1=370937&r2=370938&view=diff ============================================================================== --- struts/action/trunk/src/java/org/apache/struts/chain/contexts/ContextWrapper.java (original) +++ struts/action/trunk/src/java/org/apache/struts/chain/contexts/ContextWrapper.java Fri Jan 20 16:19:02 2006 @@ -1,111 +1,105 @@ -/* - * $Id$ - * - * Copyright 2005 The Apache Software Foundation. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.struts.chain.contexts; - -import org.apache.commons.chain.Context; -import java.util.Set; -import java.util.Collection; -import java.util.Map; - -/** - *

- * Provide a base class for any Context Implementation which is primarily - * intended for use in a subchain. - *

- *

- * Classes which extend ContextWrapper may implement typesafe - * property methods which also leave their values in the underlying context. - *

- */ -public class ContextWrapper implements Context { - - /** - *

- * Instantiate object as a composite around the given Context. - *

- * @param context Context instance to wrap - */ - public ContextWrapper(Context context) { - this.base = context; - } - - private Context base; - - /** - * Provide the underlying Context for this composite. - * @return The undelrying Context - */ - protected Context getBaseContext() { - return this.base; - } - - // ------------------------------- - // Map interface methods - // ------------------------------- - - public Set entrySet() { - return this.base.entrySet(); - } - - public Set keySet() { - return this.base.keySet(); - } - - public Collection values() { - return this.base.values(); - } - - public void clear() { - this.base.clear(); - } - - public void putAll(Map map) { - // ISSUE: Should we check this call to putAll? - this.base.putAll(map); - } - - public Object remove(Object key) { - return this.base.remove(key); - } - - public Object put(Object key, Object value) { - // ISSUE: Should we check this call to put? - return this.base.put(key, value); - } - - public Object get(Object key) { - return this.base.get(key); - } - - public boolean containsValue(Object o) { - return this.base.containsValue(o); - } - - public boolean containsKey(Object o) { - return this.base.containsKey(o); - } - - public boolean isEmpty() { - return this.base.isEmpty(); - } - - public int size() { - return this.base.size(); - } - -} \ No newline at end of file +/* + * $Id$ + * + * Copyright 2005 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.struts.chain.contexts; + +import org.apache.commons.chain.Context; + +import java.util.Collection; +import java.util.Map; +import java.util.Set; + +/** + *

Provide a base class for any Context Implementation which is primarily + * intended for use in a subchain.

Classes which extend + * ContextWrapper may implement typesafe property methods which + * also leave their values in the underlying context.

+ */ +public class ContextWrapper implements Context { + private Context base; + + /** + *

Instantiate object as a composite around the given Context.

+ * + * @param context Context instance to wrap + */ + public ContextWrapper(Context context) { + this.base = context; + } + + /** + * Provide the underlying Context for this composite. + * + * @return The undelrying Context + */ + protected Context getBaseContext() { + return this.base; + } + + // ------------------------------- + // Map interface methods + // ------------------------------- + public Set entrySet() { + return this.base.entrySet(); + } + + public Set keySet() { + return this.base.keySet(); + } + + public Collection values() { + return this.base.values(); + } + + public void clear() { + this.base.clear(); + } + + public void putAll(Map map) { + // ISSUE: Should we check this call to putAll? + this.base.putAll(map); + } + + public Object remove(Object key) { + return this.base.remove(key); + } + + public Object put(Object key, Object value) { + // ISSUE: Should we check this call to put? + return this.base.put(key, value); + } + + public Object get(Object key) { + return this.base.get(key); + } + + public boolean containsValue(Object o) { + return this.base.containsValue(o); + } + + public boolean containsKey(Object o) { + return this.base.containsKey(o); + } + + public boolean isEmpty() { + return this.base.isEmpty(); + } + + public int size() { + return this.base.size(); + } +} Modified: struts/action/trunk/src/java/org/apache/struts/chain/contexts/MockActionContext.java URL: http://svn.apache.org/viewcvs/struts/action/trunk/src/java/org/apache/struts/chain/contexts/MockActionContext.java?rev=370938&r1=370937&r2=370938&view=diff ============================================================================== --- struts/action/trunk/src/java/org/apache/struts/chain/contexts/MockActionContext.java (original) +++ struts/action/trunk/src/java/org/apache/struts/chain/contexts/MockActionContext.java Fri Jan 20 16:19:02 2006 @@ -1,65 +1,67 @@ -/* - * $Id$ - * - * Copyright 2005 The Apache Software Foundation. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.struts.chain.contexts; - -import java.util.HashMap; -import java.util.Map; - -// ISSUE: Are there any useful "assert" type methods we could add to this? - -/** - *

- * Implement ActionContext with empty maps for - * applicationScope, sessionScope, - * requestScope, - * and parameterMap properties. - *

- */ -public class MockActionContext extends ActionContextBase { - private Map applicationScope = new HashMap(); - private Map requestScope = new HashMap(); - private Map sessionScope = new HashMap(); - private Map parameterMap = new HashMap(); - - public Map getApplicationScope() { - return applicationScope; - } - public void setApplicationScope(Map applicationScope) { - this.applicationScope = applicationScope; - } - public Map getParameterMap() { - return parameterMap; - } - public void setParameterMap(Map parameterMap) { - this.parameterMap = parameterMap; - } - public Map getRequestScope() { - return requestScope; - } - public void setRequestScope(Map requestScope) { - this.requestScope = requestScope; - } - public Map getSessionScope() { - return sessionScope; - } - public void setSessionScope(Map sessionScope) { - this.sessionScope = sessionScope; - } -} - - +/* + * $Id$ + * + * Copyright 2005 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.struts.chain.contexts; + +import java.util.HashMap; +import java.util.Map; + +// ISSUE: Are there any useful "assert" type methods we could add to this? + +/** + *

Implement ActionContext with empty maps for + * applicationScope, sessionScope, + * requestScope, and parameterMap properties.

+ */ +public class MockActionContext extends ActionContextBase { + private Map applicationScope = new HashMap(); + private Map requestScope = new HashMap(); + private Map sessionScope = new HashMap(); + private Map parameterMap = new HashMap(); + + public Map getApplicationScope() { + return applicationScope; + } + + public void setApplicationScope(Map applicationScope) { + this.applicationScope = applicationScope; + } + + public Map getParameterMap() { + return parameterMap; + } + + public void setParameterMap(Map parameterMap) { + this.parameterMap = parameterMap; + } + + public Map getRequestScope() { + return requestScope; + } + + public void setRequestScope(Map requestScope) { + this.requestScope = requestScope; + } + + public Map getSessionScope() { + return sessionScope; + } + + public void setSessionScope(Map sessionScope) { + this.sessionScope = sessionScope; + } +} --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscribe@struts.apache.org For additional commands, e-mail: dev-help@struts.apache.org