You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@struts.apache.org by hu...@apache.org on 2006/01/21 01:21:00 UTC
svn commit: r370938 [10/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/str...
Modified: struts/action/trunk/src/java/org/apache/struts/chain/contexts/ServletActionContext.java
URL: http://svn.apache.org/viewcvs/struts/action/trunk/src/java/org/apache/struts/chain/contexts/ServletActionContext.java?rev=370938&r1=370937&r2=370938&view=diff
==============================================================================
--- struts/action/trunk/src/java/org/apache/struts/chain/contexts/ServletActionContext.java (original)
+++ struts/action/trunk/src/java/org/apache/struts/chain/contexts/ServletActionContext.java Fri Jan 20 16:19:02 2006
@@ -17,10 +17,6 @@
*/
package org.apache.struts.chain.contexts;
-import javax.servlet.ServletContext;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-
import org.apache.commons.chain.web.servlet.ServletWebContext;
import org.apache.struts.Globals;
import org.apache.struts.action.ActionMessages;
@@ -29,18 +25,18 @@
import org.apache.struts.config.ActionConfig;
import org.apache.struts.util.MessageResources;
+import javax.servlet.ServletContext;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
/**
- * <p>
- * Implement ActionContext interface while making Servlet API-specific
- * values available.
- * </p>
+ * <p> Implement ActionContext interface while making Servlet API-specific
+ * values available. </p>
*/
public class ServletActionContext extends WebActionContext {
-
/**
- * <p>
- * Instantiate this composite by wrapping a ServletWebContext.
- * </p>
+ * <p> Instantiate this composite by wrapping a ServletWebContext. </p>
+ *
* @param context The ServletWebContext to wrap
*/
public ServletActionContext(ServletWebContext context) {
@@ -48,12 +44,11 @@
}
/**
- * <p>
- * Instantiate this Context for a given ServletContext,
- * HttpServletRequest, and HttpServletResponse.
- * </p>
- * @param context The instant ServletContext
- * @param request The instant HttpServletRequest
+ * <p> Instantiate this Context for a given ServletContext,
+ * HttpServletRequest, and HttpServletResponse. </p>
+ *
+ * @param context The instant ServletContext
+ * @param request The instant HttpServletRequest
* @param response The instant HttpServletResponse
*/
public ServletActionContext(ServletContext context,
@@ -63,9 +58,8 @@
}
/**
- * <p>
- * Provide the ServletWebContext for this composite.
- * </p>
+ * <p> Provide the ServletWebContext for this composite. </p>
+ *
* @return Our ServletWebContext
*/
protected ServletWebContext servletWebContext() {
@@ -82,9 +76,8 @@
// -------------------------------
/**
- * <p>
- * Return the ServletContext for this context.
- * </p>
+ * <p> Return the ServletContext for this context. </p>
+ *
* @return Our ServletContext
*/
public ServletContext getContext() {
@@ -92,9 +85,8 @@
}
/**
- * <p>
- * Return the HttpServletRequest for this context.
- * </p>
+ * <p> Return the HttpServletRequest for this context. </p>
+ *
* @return Our HttpServletRequest
*/
public HttpServletRequest getRequest() {
@@ -102,9 +94,8 @@
}
/**
- * <p>
- * Return the HttpServletResponse for this context.
- * </p>
+ * <p> Return the HttpServletResponse for this context. </p>
+ *
* @return Our HttpServletResponse
*/
public HttpServletResponse getResponse() {
@@ -112,9 +103,8 @@
}
/**
- * <p>
- * Return the ActionServlet for this context.
- * </p>
+ * <p> Return the ActionServlet for this context. </p>
+ *
* @return Our ActionServlet
*/
public ActionServlet getActionServlet() {
@@ -122,9 +112,8 @@
}
/**
- * <p>
- * Set the ActionServlet instance for this context.
- * </p>
+ * <p> Set the ActionServlet instance for this context. </p>
+ *
* @param servlet Our ActionServlet instance
*/
public void setActionServlet(ActionServlet servlet) {
@@ -134,28 +123,27 @@
// -------------------------------
// Servlet specific modifications to base properties.
// -------------------------------
-
public void setActionConfig(ActionConfig actionConfig) {
super.setActionConfig(actionConfig);
this.getRequestScope().put(Globals.MAPPING_KEY, actionConfig);
+
// ISSUE: Should we check this call to put?
}
public MessageResources getMessageResources() {
- return ((MessageResources)
- getRequest().getAttribute(Globals.MESSAGES_KEY));
-
+ return ((MessageResources) getRequest()
+ .getAttribute(Globals.MESSAGES_KEY));
}
// ISSUE: This method would probably be better handled by a "Struts"
// object which encapsulated the servler (Application) scope.
-
public MessageResources getMessageResources(String key) {
// Identify the current module
ServletContext context = getActionServlet().getServletContext();
+
// Return the requested message resources instance
- return (MessageResources) context.getAttribute(key +
- getModuleConfig().getPrefix());
+ return (MessageResources) context.getAttribute(key
+ + getModuleConfig().getPrefix());
}
public void setMessageResources(MessageResources resources) {
@@ -164,11 +152,10 @@
}
/**
- * <p>
- * Store the mesasage resources for the current module under the given
- * request attribute key.
- * </p>
- * @param key Request attribute key
+ * <p> Store the mesasage resources for the current module under the given
+ * request attribute key. </p>
+ *
+ * @param key Request attribute key
* @param resources Message resouces to store
*/
public void setMessageResources(String key, MessageResources resources) {
@@ -179,64 +166,66 @@
// -------------------------------
// ActionMessage Processing
// -------------------------------
-
public void saveErrors(ActionMessages errors) {
// Remove any error messages attribute if none are required
if ((errors == null) || errors.isEmpty()) {
getRequest().removeAttribute(Globals.ERROR_KEY);
+
return;
}
+
// Save the error messages we need
getRequest().setAttribute(Globals.ERROR_KEY, errors);
-
}
public void saveMessages(ActionMessages messages) {
-
if ((messages == null) || messages.isEmpty()) {
getRequest().removeAttribute(Globals.MESSAGE_KEY);
+
return;
}
+
getRequest().setAttribute(Globals.MESSAGE_KEY, messages);
}
public void addMessages(ActionMessages messages) {
+ if (messages == null) {
+ return;
+ }
- if (messages == null) {
- return;
- }
-
- ActionMessages requestMessages = getMessages();
- if (requestMessages == null) {
- requestMessages = new ActionMessages();
- }
- requestMessages.add(messages);
- saveMessages(requestMessages);
- }
+ ActionMessages requestMessages = getMessages();
+
+ if (requestMessages == null) {
+ requestMessages = new ActionMessages();
+ }
+ requestMessages.add(messages);
+ saveMessages(requestMessages);
+ }
public void addErrors(ActionMessages errors) {
+ if (errors == null) {
+ return;
+ }
+
+ ActionMessages requestErrors = getErrors();
+
+ if (requestErrors == null) {
+ requestErrors = new ActionMessages();
+ }
- if (errors == null) {
- return;
- }
-
- ActionMessages requestErrors = getErrors();
- if (requestErrors == null) {
- requestErrors = new ActionMessages();
- }
- requestErrors.add(errors);
- saveErrors(requestErrors);
+ requestErrors.add(errors);
+ saveErrors(requestErrors);
}
public ActionMessages getErrors() {
- return (ActionMessages)
- this.getRequest().getAttribute(Globals.ERROR_KEY);
+ return (ActionMessages) this.getRequest()
+ .getAttribute(Globals.ERROR_KEY);
}
public ActionMessages getMessages() {
- return (ActionMessages)
- this.getRequest().getAttribute(Globals.MESSAGE_KEY);
+ return (ActionMessages) this.getRequest()
+ .getAttribute(Globals.MESSAGE_KEY);
}
// -------------------------------
@@ -245,14 +234,12 @@
// TokenProcessor class
// directly should ensure greater compatibility.
// -------------------------------
-
public void saveToken() {
token.saveToken(getRequest());
}
public String generateToken() {
return token.generateToken(getRequest());
-
}
public boolean isTokenValid(boolean reset) {
@@ -262,5 +249,4 @@
public void resetToken() {
token.resetToken(getRequest());
}
-
}
Modified: struts/action/trunk/src/java/org/apache/struts/chain/contexts/WebActionContext.java
URL: http://svn.apache.org/viewcvs/struts/action/trunk/src/java/org/apache/struts/chain/contexts/WebActionContext.java?rev=370938&r1=370937&r2=370938&view=diff
==============================================================================
--- struts/action/trunk/src/java/org/apache/struts/chain/contexts/WebActionContext.java (original)
+++ struts/action/trunk/src/java/org/apache/struts/chain/contexts/WebActionContext.java Fri Jan 20 16:19:02 2006
@@ -1,184 +1,178 @@
-/*
- * $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.Map;
-
-import org.apache.commons.chain.web.WebContext;
-import org.apache.struts.Globals;
-import org.apache.struts.config.ModuleConfig;
-
-/**
- * <p>
- * Provide a Subclass of ActionContextBase which is understood to be wrapping
- * an instance of <code>org.apache.commons.chain.web.WebContext</code>.
- * </p>
- */
-public class WebActionContext extends ActionContextBase {
-
- /**
- * Instantiate this composite by wrapping an instance of WebContext.
- * @param context The WebContext to wrap
- */
- public WebActionContext(WebContext context) {
- super(context);
- }
-
-
- /**
- * Provide the wrapped WebContext for this composite.
- * @return The wrapped WebContext
- */
- protected WebContext webContext() {
- return (WebContext) this.getBaseContext();
- }
-
- public void release() {
- super.release();
- }
-
- // -------------------------------
- // WebContext property wrappers
- // -------------------------------
-
- /**
- * <p>
- * Return an immutable Map that maps header names to the first
- * (or only) header value (as a String).
- * </p>
- * @return A immutable Map of web request header names
- */
- public Map getHeader() {
- return webContext().getHeader();
- }
-
- /**
- * <p>
- * Return an immutable Map that maps header names to the set of all
- * values specified in the request (as a String array).
- * Header names must be matched in a case-insensitive manner.
- * </p>
- * @return An immutable Map of web request header values
- */
- public Map getHeaderValues() {
- return webContext().getHeaderValues();
- }
-
- /***
- * <p>
- * Return an immutable Map that maps context application initialization
- * parameters to their values.
- * </p>
- * @return An immutable Map of web context initialization parameters
- */
- public Map getInitParam() {
- return webContext().getInitParam();
- }
-
- /**
- * <p>
- * Return a map whose keys are <code>String</code> request parameter names
- * and whose values are <code>String</code> values.
- * </p>
- * <p>
- * For parameters which were submitted with more than one value,
- * only one value will be returned, as if one called
- * <code>ServletRequest.getParameter(String)</code>
- * </p>
- * @return A map of web request parameters
- */
- public Map getParam() {
- return webContext().getParam();
- }
-
- /**
- * <p>
- * Return a map whose keys are <code>String</code> request parameter names
- * and whose values are <code>String[]</code> values.
- * </p>
- * @return A map of web request parameter values (as an array)
- */
- public Map getParamValues() {
- return webContext().getParamValues();
- }
-
- public Map getApplicationScope() {
- return webContext().getApplicationScope();
- }
-
- public Map getRequestScope() {
- return webContext().getRequestScope();
- }
-
- public Map getParameterMap() {
- return getParamValues();
- }
-
- public Map getSessionScope() {
- return webContext().getSessionScope();
- }
-
- // ISSUE: AbstractSelectModule set the precedent of doing this at the
- // "web context" level instead of the ServletWebContext level.
- // Consider whether that's how we want to do it universally for other
- // manipulations of the RequestScope or not...
-
- public void setModuleConfig(ModuleConfig moduleConfig) {
- super.setModuleConfig(moduleConfig);
- this.getRequestScope().put(Globals.MODULE_KEY, moduleConfig);
- }
-
- /**
- * @see org.apache.struts.chain.contexts.ActionContext#getModuleConfig()
- */
- public ModuleConfig getModuleConfig() {
- ModuleConfig mc = super.getModuleConfig();
- if (mc == null) {
- mc = (ModuleConfig) this.getRequestScope().get(Globals.MODULE_KEY);
- }
- return mc;
- }
-
- // ISSUE: AbstractSelectModule set the precedent of doing this at the
- // "web context" level instead of the ServletWebContext level. Consider
- // whether that's how we want to do it universally for other manipulations
- // of the RequestScope or not...
-
- public void setCancelled(Boolean cancelled) {
- super.setCancelled(cancelled);
- // historic semantics of "isCancelled" are to consider any non-null
- // value in the request under Globals.CANCEL_KEY as "yes, this was
- // cancelled."
- if (cancelled != null && cancelled.booleanValue()) {
- this.getRequestScope().put(Globals.CANCEL_KEY, cancelled);
- } else {
- this.getRequestScope().remove(Globals.CANCEL_KEY);
- }
-
- }
-
- public Boolean getCancelled() {
- Boolean cancelled = super.getCancelled();
- if (cancelled == null) {
- cancelled = (Boolean) this.getRequestScope()
- .get(Globals.CANCEL_KEY);
- }
- return cancelled;
- }
-}
\ 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.web.WebContext;
+import org.apache.struts.Globals;
+import org.apache.struts.config.ModuleConfig;
+
+import java.util.Map;
+
+/**
+ * <p> Provide a Subclass of ActionContextBase which is understood to be
+ * wrapping an instance of <code>org.apache.commons.chain.web.WebContext</code>.
+ * </p>
+ */
+public class WebActionContext extends ActionContextBase {
+ /**
+ * Instantiate this composite by wrapping an instance of WebContext.
+ *
+ * @param context The WebContext to wrap
+ */
+ public WebActionContext(WebContext context) {
+ super(context);
+ }
+
+ /**
+ * Provide the wrapped WebContext for this composite.
+ *
+ * @return The wrapped WebContext
+ */
+ protected WebContext webContext() {
+ return (WebContext) this.getBaseContext();
+ }
+
+ public void release() {
+ super.release();
+ }
+
+ // -------------------------------
+ // WebContext property wrappers
+ // -------------------------------
+
+ /**
+ * <p> Return an immutable Map that maps header names to the first (or
+ * only) header value (as a String). </p>
+ *
+ * @return A immutable Map of web request header names
+ */
+ public Map getHeader() {
+ return webContext().getHeader();
+ }
+
+ /**
+ * <p> Return an immutable Map that maps header names to the set of all
+ * values specified in the request (as a String array). Header names must
+ * be matched in a case-insensitive manner. </p>
+ *
+ * @return An immutable Map of web request header values
+ */
+ public Map getHeaderValues() {
+ return webContext().getHeaderValues();
+ }
+
+ /**
+ * <p> Return an immutable Map that maps context application
+ * initialization parameters to their values. </p>
+ *
+ * @return An immutable Map of web context initialization parameters
+ */
+ public Map getInitParam() {
+ return webContext().getInitParam();
+ }
+
+ /**
+ * <p> Return a map whose keys are <code>String</code> request parameter
+ * names and whose values are <code>String</code> values. </p> <p> For
+ * parameters which were submitted with more than one value, only one
+ * value will be returned, as if one called <code>ServletRequest.getParameter(String)</code>
+ * </p>
+ *
+ * @return A map of web request parameters
+ */
+ public Map getParam() {
+ return webContext().getParam();
+ }
+
+ /**
+ * <p> Return a map whose keys are <code>String</code> request parameter
+ * names and whose values are <code>String[]</code> values. </p>
+ *
+ * @return A map of web request parameter values (as an array)
+ */
+ public Map getParamValues() {
+ return webContext().getParamValues();
+ }
+
+ public Map getApplicationScope() {
+ return webContext().getApplicationScope();
+ }
+
+ public Map getRequestScope() {
+ return webContext().getRequestScope();
+ }
+
+ public Map getParameterMap() {
+ return getParamValues();
+ }
+
+ public Map getSessionScope() {
+ return webContext().getSessionScope();
+ }
+
+ // ISSUE: AbstractSelectModule set the precedent of doing this at the
+ // "web context" level instead of the ServletWebContext level.
+ // Consider whether that's how we want to do it universally for other
+ // manipulations of the RequestScope or not...
+ public void setModuleConfig(ModuleConfig moduleConfig) {
+ super.setModuleConfig(moduleConfig);
+ this.getRequestScope().put(Globals.MODULE_KEY, moduleConfig);
+ }
+
+ /**
+ * @see org.apache.struts.chain.contexts.ActionContext#getModuleConfig()
+ */
+ public ModuleConfig getModuleConfig() {
+ ModuleConfig mc = super.getModuleConfig();
+
+ if (mc == null) {
+ mc = (ModuleConfig) this.getRequestScope()
+ .get(Globals.MODULE_KEY);
+ }
+
+ return mc;
+ }
+
+ // ISSUE: AbstractSelectModule set the precedent of doing this at the
+ // "web context" level instead of the ServletWebContext level. Consider
+ // whether that's how we want to do it universally for other manipulations
+ // of the RequestScope or not...
+ public void setCancelled(Boolean cancelled) {
+ super.setCancelled(cancelled);
+
+ // historic semantics of "isCancelled" are to consider any non-null
+ // value in the request under Globals.CANCEL_KEY as "yes, this was
+ // cancelled."
+ if ((cancelled != null) && cancelled.booleanValue()) {
+ this.getRequestScope().put(Globals.CANCEL_KEY, cancelled);
+ } else {
+ this.getRequestScope().remove(Globals.CANCEL_KEY);
+ }
+ }
+
+ public Boolean getCancelled() {
+ Boolean cancelled = super.getCancelled();
+
+ if (cancelled == null) {
+ cancelled =
+ (Boolean) this.getRequestScope().get(Globals.CANCEL_KEY);
+ }
+
+ return cancelled;
+ }
+}
Modified: struts/action/trunk/src/java/org/apache/struts/config/ActionConfig.java
URL: http://svn.apache.org/viewcvs/struts/action/trunk/src/java/org/apache/struts/config/ActionConfig.java?rev=370938&r1=370937&r2=370938&view=diff
==============================================================================
--- struts/action/trunk/src/java/org/apache/struts/config/ActionConfig.java (original)
+++ struts/action/trunk/src/java/org/apache/struts/config/ActionConfig.java Fri Jan 20 16:19:02 2006
@@ -15,59 +15,191 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
package org.apache.struts.config;
-import org.apache.struts.util.RequestUtils;
import org.apache.commons.beanutils.BeanUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.apache.struts.util.RequestUtils;
+import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.HashMap;
-import java.util.Properties;
-import java.util.Enumeration;
-import java.lang.reflect.InvocationTargetException;
-
/**
* <p>A JavaBean representing the configuration information of an
- * <code><action></code> element from a Struts
- * module configuration file.</p>
+ * <code><action></code> element from a Struts module configuration
+ * file.</p>
*
- * @version $Rev$ $Date$
+ * @version $Rev$ $Date: 2005-08-06 04:12:10 -0400 (Sat, 06 Aug 2005)
+ * $
* @since Struts 1.1
*/
public class ActionConfig extends BaseConfig {
-
private static final Log log = LogFactory.getLog(ActionConfig.class);
// ----------------------------------------------------- Instance Variables
-
/**
- * The set of exception handling configurations for this
- * action, if any, keyed by the <code>type</code> property.
+ * The set of exception handling configurations for this action, if any,
+ * keyed by the <code>type</code> property.
*/
protected HashMap exceptions = new HashMap();
-
/**
- * The set of local forward configurations for this action, if any,
- * keyed by the <code>name</code> property.
+ * The set of local forward configurations for this action, if any, keyed
+ * by the <code>name</code> property.
*/
protected HashMap forwards = new HashMap();
-
// ------------------------------------------------------------- Properties
-
/**
* The module configuration with which we are associated.
*/
protected ModuleConfig moduleConfig = null;
/**
+ * The request-scope or session-scope attribute name under which our form
+ * bean is accessed, if it is different from the form bean's specified
+ * <code>name</code>.
+ */
+ protected String attribute = null;
+
+ /**
+ * <p>The path of the ActionConfig that this object should inherit
+ * properties from.</p>
+ */
+ protected String inherit = null;
+
+ /**
+ * Have the inheritance values for this class been applied?
+ */
+ protected boolean extensionProcessed = false;
+
+ /**
+ * Context-relative path of the web application resource that will process
+ * this request via RequestDispatcher.forward(), instead of instantiating
+ * and calling the <code>Action</code> class specified by "type". Exactly
+ * one of <code>forward</code>, <code>include</code>, or <code>type</code>
+ * must be specified.
+ */
+ protected String forward = null;
+
+ /**
+ * Context-relative path of the web application resource that will process
+ * this request via RequestDispatcher.include(), instead of instantiating
+ * and calling the <code>Action</code> class specified by "type". Exactly
+ * one of <code>forward</code>, <code>include</code>, or <code>type</code>
+ * must be specified.
+ */
+ protected String include = null;
+
+ /**
+ * Context-relative path of the input form to which control should be
+ * returned if a validation error is encountered. Required if "name" is
+ * specified and the input bean returns validation errors.
+ */
+ protected String input = null;
+
+ /**
+ * Fully qualified Java class name of the <code>MultipartRequestHandler</code>
+ * implementation class used to process multi-part request data for this
+ * Action.
+ */
+ protected String multipartClass = null;
+
+ /**
+ * Name of the form bean, if any, associated with this Action.
+ */
+ protected String name = null;
+
+ /**
+ * General purpose configuration parameter that can be used to pass extra
+ * information to the Action instance selected by this Action. Struts does
+ * not itself use this value in any way.
+ */
+ protected String parameter = null;
+
+ /**
+ * Context-relative path of the submitted request, starting with a slash
+ * ("/") character, and omitting any filename extension if extension
+ * mapping is being used.
+ */
+ protected String path = null;
+
+ /**
+ * Prefix used to match request parameter names to form bean property
+ * names, if any.
+ */
+ protected String prefix = null;
+
+ /**
+ * Comma-delimited list of security role names allowed to request this
+ * Action.
+ */
+ protected String roles = null;
+
+ /**
+ * The set of security role names used to authorize access to this Action,
+ * as an array for faster access.
+ */
+ protected String[] roleNames = new String[0];
+
+ /**
+ * Identifier of the scope ("request" or "session") within which our form
+ * bean is accessed, if any.
+ */
+ protected String scope = "session";
+
+ /**
+ * Suffix used to match request parameter names to form bean property
+ * names, if any.
+ */
+ protected String suffix = null;
+
+ /**
+ * Fully qualified Java class name of the <code>Action</code> class to be
+ * used to process requests for this mapping if the <code>forward</code>
+ * and <code>include</code> properties are not set. Exactly one of
+ * <code>forward</code>, <code>include</code>, or <code>type</code> must
+ * be specified.
+ */
+ protected String type = null;
+
+ /**
+ * Indicates Action be configured as the default one for this module, when
+ * true.
+ */
+ protected boolean unknown = false;
+
+ /**
+ * Should the <code>validate()</code> method of the form bean associated
+ * with this action be called?
+ */
+ protected boolean validate = true;
+
+ /**
+ * The name of a <code>commons-chain</code> command which should be
+ * executed as part of the processing of this action.
+ *
+ * @since Struts 1.3.0
+ */
+ protected String command = null;
+
+ /**
+ * The name of a <code>commons-chain</code> catalog in which
+ * <code>command</code> should be sought. If a <code>command</code> is
+ * defined and this property is undefined, the "default" catalog will be
+ * used. This is likely to be infrequently used after a future release of
+ * <code>commons-chain</code> supports a one-string expression of a
+ * catalog/chain combination.
+ *
+ * @since Struts 1.3.0
+ */
+ protected String catalog = null;
+
+ /**
* The module configuration with which we are associated.
*/
public ModuleConfig getModuleConfig() {
@@ -85,19 +217,12 @@
this.moduleConfig = moduleConfig;
}
-
- /**
- * The request-scope or session-scope attribute name under which our
- * form bean is accessed, if it is different from the form bean's
- * specified <code>name</code>.
- */
- protected String attribute = null;
-
/**
- * Returns the request-scope or session-scope attribute name under which our
- * form bean is accessed, if it is different from the form bean's
+ * Returns the request-scope or session-scope attribute name under which
+ * our form bean is accessed, if it is different from the form bean's
* specified <code>name</code>.
- * @return attribute name under which our form bean is accessed.
+ *
+ * @return attribute name under which our form bean is accessed.
*/
public String getAttribute() {
if (this.attribute == null) {
@@ -111,29 +236,24 @@
* Set the request-scope or session-scope attribute name under which our
* form bean is accessed, if it is different from the form bean's
* specified <code>name</code>.
- * @param attribute the request-scope or session-scope attribute name under which our
- * form bean is access.
+ *
+ * @param attribute the request-scope or session-scope attribute name
+ * under which our form bean is access.
*/
public void setAttribute(String attribute) {
if (configured) {
throw new IllegalStateException("Configuration is frozen");
}
+
this.attribute = attribute;
}
-
- /**
- * <p>The path of the ActionConfig that this object should inherit
- * properties from.</p>
- */
- protected String inherit = null;
-
/**
* <p>Returns the path of the ActionConfig that this object should inherit
* properties from.</p>
*
- * @return the path of the ActionConfig that this object should inherit
- * properties from.
+ * @return the path of the ActionConfig that this object should inherit
+ * properties from.
*/
public String getExtends() {
return (this.inherit);
@@ -144,135 +264,101 @@
* properties from.</p>
*
* @param inherit the path of the ActionConfig that this object should
- * inherit properties from.
+ * inherit properties from.
*/
public void setExtends(String inherit) {
if (configured) {
throw new IllegalStateException("Configuration is frozen");
}
+
this.inherit = inherit;
}
-
- /**
- * Have the inheritance values for this class been applied?
- */
- protected boolean extensionProcessed = false;
-
public boolean isExtensionProcessed() {
return extensionProcessed;
}
-
- /**
- * Context-relative path of the web application resource that will process
- * this request via RequestDispatcher.forward(), instead of instantiating
- * and calling the <code>Action</code> class specified by "type".
- * Exactly one of <code>forward</code>, <code>include</code>, or
- * <code>type</code> must be specified.
- */
- protected String forward = null;
-
/**
- * Returns context-relative path of the web application resource that will process
- * this request.
- * @return context-relative path of the web application resource that will process
- * this request.
+ * Returns context-relative path of the web application resource that will
+ * process this request.
+ *
+ * @return context-relative path of the web application resource that will
+ * process this request.
*/
public String getForward() {
return (this.forward);
}
/**
- * Set the context-relative path of the web application resource that will process
- * this request.
- * Exactly one of <code>forward</code>, <code>include</code>, or
- * <code>type</code> must be specified.
- * @param forward context-relative path of the web application resource that will process
- * this request.
+ * Set the context-relative path of the web application resource that will
+ * process this request. Exactly one of <code>forward</code>,
+ * <code>include</code>, or <code>type</code> must be specified.
+ *
+ * @param forward context-relative path of the web application resource
+ * that will process this request.
*/
public void setForward(String forward) {
if (configured) {
throw new IllegalStateException("Configuration is frozen");
}
+
this.forward = forward;
}
-
- /**
- * Context-relative path of the web application resource that will process
- * this request via RequestDispatcher.include(), instead of instantiating
- * and calling the <code>Action</code> class specified by "type".
- * Exactly one of <code>forward</code>, <code>include</code>, or
- * <code>type</code> must be specified.
- */
- protected String include = null;
-
/**
* Context-relative path of the web application resource that will process
* this request.
- * @return Context-relative path of the web application resource that will process
- * this request.
+ *
+ * @return Context-relative path of the web application resource that will
+ * process this request.
*/
public String getInclude() {
return (this.include);
}
/**
- * Set context-relative path of the web application resource that will process
- * this request.
- * Exactly one of <code>forward</code>, <code>include</code>, or
- * <code>type</code> must be specified.
- * @param include context-relative path of the web application resource that will process
- * this request.
+ * Set context-relative path of the web application resource that will
+ * process this request. Exactly one of <code>forward</code>,
+ * <code>include</code>, or <code>type</code> must be specified.
+ *
+ * @param include context-relative path of the web application resource
+ * that will process this request.
*/
public void setInclude(String include) {
if (configured) {
throw new IllegalStateException("Configuration is frozen");
}
+
this.include = include;
}
-
- /**
- * Context-relative path of the input form to which control should be
- * returned if a validation error is encountered. Required if "name"
- * is specified and the input bean returns validation errors.
- */
- protected String input = null;
-
/**
- * Get the context-relative path of the input form to which control should be
- * returned if a validation error is encountered.
- * @return context-relative path of the input form to which control should be
- * returned if a validation error is encountered.
+ * Get the context-relative path of the input form to which control should
+ * be returned if a validation error is encountered.
+ *
+ * @return context-relative path of the input form to which control should
+ * be returned if a validation error is encountered.
*/
public String getInput() {
return (this.input);
}
/**
- * Set the context-relative path of the input form to which control should be
- * returned if a validation error is encountered. Required if "name"
+ * Set the context-relative path of the input form to which control should
+ * be returned if a validation error is encountered. Required if "name"
* is specified and the input bean returns validation errors.
- * @param input context-relative path of the input form to which control should be
- * returned if a validation error is encountered.
+ *
+ * @param input context-relative path of the input form to which control
+ * should be returned if a validation error is encountered.
*/
public void setInput(String input) {
if (configured) {
throw new IllegalStateException("Configuration is frozen");
}
+
this.input = input;
}
-
- /**
- * Fully qualified Java class name of the
- * <code>MultipartRequestHandler</code> implementation class used to
- * process multi-part request data for this Action.
- */
- protected String multipartClass = null;
-
/**
* Return the fully qualified Java class name of the
* <code>MultipartRequestHandler</code> implementation class used to
@@ -283,25 +369,22 @@
}
/**
- * Set the fully qualified Java class name of the
- * <code>MultipartRequestHandler</code> implementation class used to
- * process multi-part request data for this Action.
+ * Set the fully qualified Java class name of the <code>MultipartRequestHandler</code>
+ * implementation class used to process multi-part request data for this
+ * Action.
+ *
* @param multipartClass fully qualified class name of the
- * <code>MultipartRequestHandler</code> implementation class.
+ * <code>MultipartRequestHandler</code>
+ * implementation class.
*/
public void setMultipartClass(String multipartClass) {
if (configured) {
throw new IllegalStateException("Configuration is frozen");
}
+
this.multipartClass = multipartClass;
}
-
- /**
- * Name of the form bean, if any, associated with this Action.
- */
- protected String name = null;
-
/**
* Return name of the form bean, if any, associated with this Action.
*/
@@ -316,51 +399,38 @@
if (configured) {
throw new IllegalStateException("Configuration is frozen");
}
+
this.name = name;
}
-
/**
- * General purpose configuration parameter that can be used to pass
+ * Return general purpose configuration parameter that can be used to pass
* extra information to the Action instance selected by this Action.
* Struts does not itself use this value in any way.
*/
- protected String parameter = null;
-
- /**
- * Return general purpose configuration parameter that can be used to pass
- * extra information to the Action instance selected by this Action.
- * Struts does not itself use this value in any way.
- */
public String getParameter() {
return (this.parameter);
}
/**
- * General purpose configuration parameter that can be used to pass
- * extra information to the Action instance selected by this Action.
- * Struts does not itself use this value in any way.
- * @param parameter General purpose configuration parameter.
- */
+ * General purpose configuration parameter that can be used to pass extra
+ * information to the Action instance selected by this Action. Struts does
+ * not itself use this value in any way.
+ *
+ * @param parameter General purpose configuration parameter.
+ */
public void setParameter(String parameter) {
if (configured) {
throw new IllegalStateException("Configuration is frozen");
}
+
this.parameter = parameter;
}
-
- /**
- * Context-relative path of the submitted request, starting with a
- * slash ("/") character, and omitting any filename extension if
- * extension mapping is being used.
- */
- protected String path = null;
-
/**
* Return context-relative path of the submitted request, starting with a
- * slash ("/") character, and omitting any filename extension if
- * extension mapping is being used.
+ * slash ("/") character, and omitting any filename extension if extension
+ * mapping is being used.
*/
public String getPath() {
return (this.path);
@@ -368,50 +438,39 @@
/**
* Set context-relative path of the submitted request, starting with a
- * slash ("/") character, and omitting any filename extension if
- * extension mapping is being used.
- * @param path context-relative path of the submitted request.
+ * slash ("/") character, and omitting any filename extension if extension
+ * mapping is being used.
+ *
+ * @param path context-relative path of the submitted request.
*/
public void setPath(String path) {
if (configured) {
throw new IllegalStateException("Configuration is frozen");
}
+
this.path = path;
}
-
- /**
- * Prefix used to match request parameter names to form bean property
- * names, if any.
- */
- protected String prefix = null;
-
/**
- * Retruns prefix used to match request parameter names to form bean property
- * names, if any.
+ * Retruns prefix used to match request parameter names to form bean
+ * property names, if any.
*/
public String getPrefix() {
return (this.prefix);
}
/**
- * @param prefix Prefix used to match request parameter names to
- * form bean property names, if any.
+ * @param prefix Prefix used to match request parameter names to form bean
+ * property names, if any.
*/
public void setPrefix(String prefix) {
if (configured) {
throw new IllegalStateException("Configuration is frozen");
}
+
this.prefix = prefix;
}
-
- /**
- * Comma-delimited list of security role names allowed to request
- * this Action.
- */
- protected String roles = null;
-
public String getRoles() {
return (this.roles);
}
@@ -420,34 +479,37 @@
if (configured) {
throw new IllegalStateException("Configuration is frozen");
}
+
this.roles = roles;
+
if (roles == null) {
roleNames = new String[0];
+
return;
}
+
ArrayList list = new ArrayList();
+
while (true) {
int comma = roles.indexOf(',');
+
if (comma < 0) {
break;
}
+
list.add(roles.substring(0, comma).trim());
roles = roles.substring(comma + 1);
}
+
roles = roles.trim();
+
if (roles.length() > 0) {
list.add(roles);
}
+
roleNames = (String[]) list.toArray(new String[list.size()]);
}
-
- /**
- * The set of security role names used to authorize access to this
- * Action, as an array for faster access.
- */
- protected String[] roleNames = new String[0];
-
/**
* Get array of security role names used to authorize access to this
* Action.
@@ -456,68 +518,46 @@
return (this.roleNames);
}
-
- /**
- * Identifier of the scope ("request" or "session") within which
- * our form bean is accessed, if any.
- */
- protected String scope = "session";
-
/**
- * Get the scope ("request" or "session") within which
- * our form bean is accessed, if any.
+ * Get the scope ("request" or "session") within which our form bean is
+ * accessed, if any.
*/
public String getScope() {
return (this.scope);
}
/**
- * @param scope scope ("request" or "session") within which
- * our form bean is accessed, if any.
+ * @param scope scope ("request" or "session") within which our form bean
+ * is accessed, if any.
*/
public void setScope(String scope) {
if (configured) {
throw new IllegalStateException("Configuration is frozen");
}
+
this.scope = scope;
}
-
- /**
- * Suffix used to match request parameter names to form bean property
- * names, if any.
- */
- protected String suffix = null;
-
/**
- * Return suffix used to match request parameter names to form bean property
- * names, if any.
+ * Return suffix used to match request parameter names to form bean
+ * property names, if any.
*/
public String getSuffix() {
return (this.suffix);
}
/**
- * @param suffix Suffix used to match request parameter names to form bean property
- * names, if any.
+ * @param suffix Suffix used to match request parameter names to form bean
+ * property names, if any.
*/
public void setSuffix(String suffix) {
if (configured) {
throw new IllegalStateException("Configuration is frozen");
}
+
this.suffix = suffix;
}
-
- /**
- * Fully qualified Java class name of the <code>Action</code> class
- * to be used to process requests for this mapping if the
- * <code>forward</code> and <code>include</code> properties are not set.
- * Exactly one of <code>forward</code>, <code>include</code>, or
- * <code>type</code> must be specified.
- */
- protected String type = null;
-
public String getType() {
return (this.type);
}
@@ -526,41 +566,30 @@
if (configured) {
throw new IllegalStateException("Configuration is frozen");
}
+
this.type = type;
}
-
/**
- * Indicates Action be configured as the default one for this
- * module, when true.
+ * Determine whether Action is configured as the default one for this
+ * module.
*/
- protected boolean unknown = false;
-
- /**
- * Determine whether Action is configured as the default one for this
- * module.
- */
public boolean getUnknown() {
return (this.unknown);
}
/**
- * @param unknown Indicates Action is configured as the default one for this
- * module, when true.
- */
+ * @param unknown Indicates Action is configured as the default one for
+ * this module, when true.
+ */
public void setUnknown(boolean unknown) {
if (configured) {
throw new IllegalStateException("Configuration is frozen");
}
+
this.unknown = unknown;
}
- /**
- * Should the <code>validate()</code> method of the form bean associated
- * with this action be called?
- */
- protected boolean validate = true;
-
public boolean getValidate() {
return (this.validate);
}
@@ -569,32 +598,16 @@
if (configured) {
throw new IllegalStateException("Configuration is frozen");
}
+
this.validate = validate;
}
/**
- * The name of a <code>commons-chain</code> command which should
- * be executed as part of the processing of this action.
- * @since Struts 1.3.0
- */
- protected String command = null;
-
- /**
- * The name of a <code>commons-chain</code> catalog in which <code>command</code>
- * should be sought. If a <code>command</code> is defined and this property is undefined,
- * the "default" catalog will be used.
- * This is likely to be infrequently
- * used after a future release of <code>commons-chain</code> supports
- * a one-string expression of a catalog/chain combination.
- * @since Struts 1.3.0
- */
- protected String catalog = null;
-
- /**
- * Get the name of a <code>commons-chain</code> command which should
- * be executed as part of the processing of this action.
- * @return name of a <code>commons-chain</code> command which should
- * be executed as part of the processing of this action.
+ * Get the name of a <code>commons-chain</code> command which should be
+ * executed as part of the processing of this action.
+ *
+ * @return name of a <code>commons-chain</code> command which should be
+ * executed as part of the processing of this action.
* @since Struts 1.3.0
*/
public String getCommand() {
@@ -602,12 +615,13 @@
}
/**
- * Get the name of a <code>commons-chain</code> catalog in which
- * a specified command should be sought. This is likely to be infrequently
- * used after a future release of <code>commons-chain</code> supports
- * a one-string expression of a catalog/chain combination.
- * @return name of a <code>commons-chain</code> catalog in which
- * a specified command should be sought.
+ * Get the name of a <code>commons-chain</code> catalog in which a
+ * specified command should be sought. This is likely to be infrequently
+ * used after a future release of <code>commons-chain</code> supports a
+ * one-string expression of a catalog/chain combination.
+ *
+ * @return name of a <code>commons-chain</code> catalog in which a
+ * specified command should be sought.
* @since Struts 1.3.0
*/
public String getCatalog() {
@@ -615,50 +629,52 @@
}
/**
- * Set the name of a <code>commons-chain</code> command which should
- * be executed as part of the processing of this action.
- * @param command name of a <code>commons-chain</code> command which should
- * be executed as part of the processing of this action.
+ * Set the name of a <code>commons-chain</code> command which should be
+ * executed as part of the processing of this action.
+ *
+ * @param command name of a <code>commons-chain</code> command which
+ * should be executed as part of the processing of this
+ * action.
* @since Struts 1.3.0
*/
public void setCommand(String command) {
if (configured) {
throw new IllegalStateException("Configuration is frozen");
}
+
this.command = command;
}
/**
- * Set the name of a <code>commons-chain</code> catalog in which
- * a specified command should be sought. This is likely to be infrequently
- * used after a future release of <code>commons-chain</code> supports
- * a one-string expression of a catalog/chain combination.
- * @param catalog name of a <code>commons-chain</code> catalog in which
- * a specified command should be sought.
+ * Set the name of a <code>commons-chain</code> catalog in which a
+ * specified command should be sought. This is likely to be infrequently
+ * used after a future release of <code>commons-chain</code> supports a
+ * one-string expression of a catalog/chain combination.
+ *
+ * @param catalog name of a <code>commons-chain</code> catalog in which a
+ * specified command should be sought.
* @since Struts 1.3.0
*/
public void setCatalog(String catalog) {
if (configured) {
throw new IllegalStateException("Configuration is frozen");
}
+
this.catalog = catalog;
}
-
// ------------------------------------------------------ Protected Methods
-
/**
* <p>Traces the hierarchy of this object to check if any of the ancestors
* is extending this instance.</p>
*
- * @param moduleConfig The configuration for the module being configured.
- *
+ * @param moduleConfig The configuration for the module being configured.
* @return true if circular inheritance was detected.
*/
protected boolean checkCircularInheritance(ModuleConfig moduleConfig) {
-
String ancestorPath = getExtends();
+
while (ancestorPath != null) {
// check if we have the same path as an ancestor
if (getPath().equals(ancestorPath)) {
@@ -668,6 +684,7 @@
// get our ancestor's ancestor
ActionConfig ancestor =
moduleConfig.findActionConfig(ancestorPath);
+
if (ancestor != null) {
ancestorPath = ancestor.getExtends();
} else {
@@ -678,27 +695,23 @@
return false;
}
-
/**
* <p>Compare the exception handlers of this action with that of the given
* and copy those that are not present.</p>
*
- * @param baseConfig The action config to copy handlers from.
- *
+ * @param baseConfig The action config to copy handlers from.
* @see #inheritFrom(ActionConfig)
*/
protected void inheritExceptionHandlers(ActionConfig baseConfig)
- throws ClassNotFoundException,
- IllegalAccessException,
- InstantiationException,
- InvocationTargetException {
-
+ throws ClassNotFoundException, IllegalAccessException,
+ InstantiationException, InvocationTargetException {
if (configured) {
throw new IllegalStateException("Configuration is frozen");
}
// Inherit exception handler configs
ExceptionConfig[] baseHandlers = baseConfig.findExceptionConfigs();
+
for (int i = 0; i < baseHandlers.length; i++) {
ExceptionConfig baseHandler = baseHandlers[i];
@@ -707,46 +720,38 @@
this.findExceptionConfig(baseHandler.getType());
if (copy == null) {
-
// We don't have this, so let's copy it
copy = (ExceptionConfig) RequestUtils
- .applicationInstance(baseHandler.getClass().getName());
+ .applicationInstance(baseHandler.getClass()
+ .getName());
BeanUtils.copyProperties(copy, baseHandler);
this.addExceptionConfig(copy);
copy.setProperties(baseHandler.copyProperties());
-
} else {
-
// process any extension that this config might have
copy.processExtends(getModuleConfig(), this);
-
}
-
}
}
-
/**
- * <p>Compare the forwards of this action with that of the given and
- * copy those that are not present.</p>
- *
- * @param baseConfig The action config to copy forwards from.
+ * <p>Compare the forwards of this action with that of the given and copy
+ * those that are not present.</p>
*
+ * @param baseConfig The action config to copy forwards from.
* @see #inheritFrom(ActionConfig)
*/
protected void inheritForwards(ActionConfig baseConfig)
- throws ClassNotFoundException,
- IllegalAccessException,
- InstantiationException,
- InvocationTargetException {
-
+ throws ClassNotFoundException, IllegalAccessException,
+ InstantiationException, InvocationTargetException {
if (configured) {
throw new IllegalStateException("Configuration is frozen");
}
// Inherit forward configs
ForwardConfig[] baseForwards = baseConfig.findForwardConfigs();
+
for (int i = 0; i < baseForwards.length; i++) {
ForwardConfig baseForward = baseForwards[i];
@@ -755,67 +760,55 @@
this.findForwardConfig(baseForward.getName());
if (copy == null) {
-
// We don't have this, so let's copy it
copy = (ForwardConfig) RequestUtils
- .applicationInstance(baseForward.getClass().getName());
+ .applicationInstance(baseForward.getClass()
+ .getName());
BeanUtils.copyProperties(copy, baseForward);
this.addForwardConfig(copy);
copy.setProperties(baseForward.copyProperties());
-
} else {
-
// process any extension for this forward
copy.processExtends(getModuleConfig(), this);
-
}
-
}
}
-
// --------------------------------------------------------- Public Methods
-
/**
* Add a new <code>ExceptionConfig</code> instance to the set associated
* with this action.
*
* @param config The new configuration instance to be added
- *
- * @exception IllegalStateException if this module configuration
- * has been frozen
+ * @throws IllegalStateException if this module configuration has been
+ * frozen
*/
public void addExceptionConfig(ExceptionConfig config) {
-
if (configured) {
throw new IllegalStateException("Configuration is frozen");
}
- exceptions.put(config.getType(), config);
+ exceptions.put(config.getType(), config);
}
-
/**
* Add a new <code>ForwardConfig</code> instance to the set of global
* forwards associated with this action.
*
* @param config The new configuration instance to be added
- *
- * @exception IllegalStateException if this module configuration
- * has been frozen
+ * @throws IllegalStateException if this module configuration has been
+ * frozen
*/
public void addForwardConfig(ForwardConfig config) {
-
if (configured) {
throw new IllegalStateException("Configuration is frozen");
}
- forwards.put(config.getName(), config);
+ forwards.put(config.getName(), config);
}
-
/**
* Return the exception configuration for the specified type, if any;
* otherwise return <code>null</code>.
@@ -823,30 +816,26 @@
* @param type Exception class name to find a configuration for
*/
public ExceptionConfig findExceptionConfig(String type) {
-
return ((ExceptionConfig) exceptions.get(type));
-
}
-
/**
- * Return the exception configurations for this action. If there
- * are none, a zero-length array is returned.
+ * Return the exception configurations for this action. If there are
+ * none, a zero-length array is returned.
*/
public ExceptionConfig[] findExceptionConfigs() {
+ ExceptionConfig[] results = new ExceptionConfig[exceptions.size()];
- ExceptionConfig results[] = new ExceptionConfig[exceptions.size()];
return ((ExceptionConfig[]) exceptions.values().toArray(results));
-
}
/**
* <p>Find and return the <code>ExceptionConfig</code> instance defining
* how <code>Exceptions</code> of the specified type should be handled.
* This is performed by checking local and then global configurations for
- * the specified exception's class, and then looking up the superclass chain
- * (again checking local and then global configurations). If no handler
- * configuration can be found, return <code>null</code>.</p>
+ * the specified exception's class, and then looking up the superclass
+ * chain (again checking local and then global configurations). If no
+ * handler configuration can be found, return <code>null</code>.</p>
*
* <p>Introduced in <code>ActionMapping</code> in Struts 1.1, but pushed
* up to <code>ActionConfig</code> in Struts 1.2.0.</p>
@@ -855,15 +844,16 @@
* @since Struts 1.2.0
*/
public ExceptionConfig findException(Class type) {
-
// Check through the entire superclass hierarchy as needed
ExceptionConfig config = null;
- while (true) {
+ while (true) {
// Check for a locally defined handler
String name = type.getName();
+
log.debug("findException: look locally for " + name);
config = findExceptionConfig(name);
+
if (config != null) {
return (config);
}
@@ -871,23 +861,22 @@
// Check for a globally defined handler
log.debug("findException: look globally for " + name);
config = getModuleConfig().findExceptionConfig(name);
+
if (config != null) {
return (config);
}
// Loop again for our superclass (if any)
type = type.getSuperclass();
+
if (type == null) {
break;
}
-
}
- return (null); // No handler has been configured
+ return (null); // No handler has been configured
}
-
-
/**
* Return the forward configuration for the specified key, if any;
* otherwise return <code>null</code>.
@@ -895,44 +884,38 @@
* @param name Name of the forward configuration to return
*/
public ForwardConfig findForwardConfig(String name) {
-
return ((ForwardConfig) forwards.get(name));
-
}
-
/**
- * Return all forward configurations for this module. If there
- * are none, a zero-length array is returned.
+ * Return all forward configurations for this module. If there are none,
+ * a zero-length array is returned.
*/
public ForwardConfig[] findForwardConfigs() {
+ ForwardConfig[] results = new ForwardConfig[forwards.size()];
- ForwardConfig results[] = new ForwardConfig[forwards.size()];
return ((ForwardConfig[]) forwards.values().toArray(results));
-
}
-
/**
* Freeze the configuration of this action.
*/
public void freeze() {
-
super.freeze();
ExceptionConfig[] econfigs = findExceptionConfigs();
+
for (int i = 0; i < econfigs.length; i++) {
econfigs[i].freeze();
}
ForwardConfig[] fconfigs = findForwardConfigs();
+
for (int i = 0; i < fconfigs.length; i++) {
fconfigs[i].freeze();
}
-
}
-
/**
* <p>Inherit values that have not been overridden from the provided
* config object. Subclasses overriding this method should verify that
@@ -954,16 +937,13 @@
* extensions should be resolved before it's used as a parameter to this
* method.</p>
*
- * @param config The object that this instance will be inheriting
- * its values from.
+ * @param config The object that this instance will be inheriting its
+ * values from.
* @see #processExtends(ModuleConfig)
*/
public void inheritFrom(ActionConfig config)
- throws ClassNotFoundException,
- IllegalAccessException,
- InstantiationException,
- InvocationTargetException {
-
+ throws ClassNotFoundException, IllegalAccessException,
+ InstantiationException, InvocationTargetException {
if (configured) {
throw new IllegalStateException("Configuration is frozen");
}
@@ -1042,27 +1022,24 @@
inheritProperties(config);
}
-
/**
* <p>Inherit configuration information from the ActionConfig that this
* instance is extending. This method verifies that any action config
* object that it inherits from has also had its processExtends() method
* called.</p>
*
- * @param moduleConfig The {@link ModuleConfig} that this bean is from.
- *
+ * @param moduleConfig The {@link ModuleConfig} that this bean is from.
* @see #inheritFrom(ActionConfig)
*/
public void processExtends(ModuleConfig moduleConfig)
- throws ClassNotFoundException,
- IllegalAccessException,
- InstantiationException,
- InvocationTargetException {
-
+ throws ClassNotFoundException, IllegalAccessException,
+ InstantiationException, InvocationTargetException {
if (configured) {
throw new IllegalStateException("Configuration is frozen");
}
+
String ancestorPath = getExtends();
+
if ((!extensionProcessed) && (ancestorPath != null)) {
ActionConfig baseConfig =
moduleConfig.findActionConfig(ancestorPath);
@@ -1077,7 +1054,7 @@
if (checkCircularInheritance(moduleConfig)) {
throw new IllegalArgumentException(
"Circular inheritance detected for action "
- + getPath());
+ + getPath());
}
// Make sure the ancestor's own extension has been processed.
@@ -1092,114 +1069,120 @@
extensionProcessed = true;
}
-
/**
* Remove the specified exception configuration instance.
*
* @param config ExceptionConfig instance to be removed
- *
- * @exception IllegalStateException if this module configuration
- * has been frozen
+ * @throws IllegalStateException if this module configuration has been
+ * frozen
*/
public void removeExceptionConfig(ExceptionConfig config) {
-
if (configured) {
throw new IllegalStateException("Configuration is frozen");
}
- exceptions.remove(config.getType());
+ exceptions.remove(config.getType());
}
-
/**
* Remove the specified forward configuration instance.
*
* @param config ForwardConfig instance to be removed
- *
- * @exception IllegalStateException if this module configuration
- * has been frozen
+ * @throws IllegalStateException if this module configuration has been
+ * frozen
*/
public void removeForwardConfig(ForwardConfig config) {
-
if (configured) {
throw new IllegalStateException("Configuration is frozen");
}
- forwards.remove(config.getName());
+ forwards.remove(config.getName());
}
-
/**
* Return a String representation of this object.
*/
public String toString() {
-
StringBuffer sb = new StringBuffer("ActionConfig[");
+
sb.append("path=");
sb.append(path);
+
if (attribute != null) {
sb.append(",attribute=");
sb.append(attribute);
}
+
if (catalog != null) {
sb.append(",catalog=");
sb.append(catalog);
}
+
if (command != null) {
sb.append(",command=");
sb.append(command);
}
+
if (inherit != null) {
sb.append(",extends=");
sb.append(inherit);
}
+
if (forward != null) {
sb.append(",forward=");
sb.append(forward);
}
+
if (include != null) {
sb.append(",include=");
sb.append(include);
}
+
if (input != null) {
sb.append(",input=");
sb.append(input);
}
+
if (multipartClass != null) {
sb.append(",multipartClass=");
sb.append(multipartClass);
}
+
if (name != null) {
sb.append(",name=");
sb.append(name);
}
+
if (parameter != null) {
sb.append(",parameter=");
sb.append(parameter);
}
+
if (prefix != null) {
sb.append(",prefix=");
sb.append(prefix);
}
+
if (roles != null) {
sb.append(",roles=");
sb.append(roles);
}
+
if (scope != null) {
sb.append(",scope=");
sb.append(scope);
}
+
if (suffix != null) {
sb.append(",suffix=");
sb.append(suffix);
}
+
if (type != null) {
sb.append(",type=");
sb.append(type);
}
- return (sb.toString());
+ return (sb.toString());
}
-
-
}
Modified: struts/action/trunk/src/java/org/apache/struts/config/ActionConfigMatcher.java
URL: http://svn.apache.org/viewcvs/struts/action/trunk/src/java/org/apache/struts/config/ActionConfigMatcher.java?rev=370938&r1=370937&r2=370938&view=diff
==============================================================================
--- struts/action/trunk/src/java/org/apache/struts/config/ActionConfigMatcher.java (original)
+++ struts/action/trunk/src/java/org/apache/struts/config/ActionConfigMatcher.java Fri Jan 20 16:19:02 2006
@@ -15,9 +15,14 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
package org.apache.struts.config;
+import org.apache.commons.beanutils.BeanUtils;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.struts.action.ActionForward;
+import org.apache.struts.util.WildcardHelper;
+
import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
@@ -26,30 +31,21 @@
import java.util.Map;
import java.util.Properties;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
-import org.apache.commons.beanutils.BeanUtils;
-
-import org.apache.struts.action.ActionForward;
-import org.apache.struts.util.WildcardHelper;
-
/**
- * Matches paths against pre-compiled wildcard expressions pulled from
- * action configs. It uses the wildcard matcher from the Apache
- * Cocoon project. Patterns will be matched in the order they exist
- * in the Struts config file. The last match wins, so more specific
- * patterns should be defined after less specific patterns.
+ * Matches paths against pre-compiled wildcard expressions pulled from action
+ * configs. It uses the wildcard matcher from the Apache Cocoon project.
+ * Patterns will be matched in the order they exist in the Struts config file.
+ * The last match wins, so more specific patterns should be defined after less
+ * specific patterns.
*
* @since Struts 1.2
*/
public class ActionConfigMatcher implements Serializable {
-
/**
* The logging instance
*/
private static final Log log =
- LogFactory.getLog(ActionConfigMatcher.class);
+ LogFactory.getLog(ActionConfigMatcher.class);
/**
* Handles all wildcard pattern matching.
@@ -62,27 +58,31 @@
private List compiledPaths;
/**
- * Finds and precompiles the wildcard patterns from the ActionConfig
- * "path" attributes.
- * ActionConfig's will be evaluated in the order they exist in the
- * Struts config file. Only paths that actually contain a wildcard
- * will be compiled.
+ * Finds and precompiles the wildcard patterns from the ActionConfig
+ * "path" attributes. ActionConfig's will be evaluated in the order they
+ * exist in the Struts config file. Only paths that actually contain a
+ * wildcard will be compiled.
*
- * @param configs An array of ActionConfig's to process
+ * @param configs An array of ActionConfig's to process
*/
public ActionConfigMatcher(ActionConfig[] configs) {
compiledPaths = new ArrayList();
+
int[] pattern;
String path;
+
for (int x = 0; x < configs.length; x++) {
path = configs[x].getPath();
- if (path != null && path.indexOf('*') > -1) {
- if (path.length() > 0 && path.charAt(0) == '/') {
+
+ if ((path != null) && (path.indexOf('*') > -1)) {
+ if ((path.length() > 0) && (path.charAt(0) == '/')) {
path = path.substring(1);
}
+
if (log.isDebugEnabled()) {
log.debug("Compiling action config path '" + path + "'");
}
+
pattern = wildcard.compilePattern(path);
compiledPaths.add(new Mapping(pattern, configs[x]));
}
@@ -96,29 +96,32 @@
* @return The action config if matched, else null
*/
public ActionConfig match(String path) {
-
ActionConfig config = null;
+
if (compiledPaths.size() > 0) {
if (log.isDebugEnabled()) {
log.debug("Attempting to match '" + path
- + "' to a wildcard pattern");
+ + "' to a wildcard pattern");
}
- if (path.length() > 0 && path.charAt(0) == '/') {
+
+ if ((path.length() > 0) && (path.charAt(0) == '/')) {
path = path.substring(1);
}
+
Mapping m;
HashMap vars = new HashMap();
+
for (Iterator i = compiledPaths.iterator(); i.hasNext();) {
m = (Mapping) i.next();
+
if (wildcard.match(vars, path, m.getPattern())) {
if (log.isDebugEnabled()) {
log.debug("Path matches pattern '"
- + m.getActionConfig().getPath() + "'");
- }
- config = convertActionConfig(
- path,
- (ActionConfig) m.getActionConfig(),
- vars);
+ + m.getActionConfig().getPath() + "'");
+ }
+
+ config = convertActionConfig(path,
+ (ActionConfig) m.getActionConfig(), vars);
}
}
}
@@ -127,17 +130,17 @@
}
/**
- * Clones the ActionConfig and its children, replacing various properties
- * with the values of the wildcard-matched strings.
+ * Clones the ActionConfig and its children, replacing various properties
+ * with the values of the wildcard-matched strings.
*
- * @param path The requested path
- * @param orig The original ActionConfig
- * @param vars A Map of wildcard-matched strings
- * @return A cloned ActionConfig with appropriate properties replaced
- * with wildcard-matched values
+ * @param path The requested path
+ * @param orig The original ActionConfig
+ * @param vars A Map of wildcard-matched strings
+ * @return A cloned ActionConfig with appropriate properties replaced with
+ * wildcard-matched values
*/
- protected ActionConfig convertActionConfig(String path,
- ActionConfig orig, Map vars) {
+ protected ActionConfig convertActionConfig(String path, ActionConfig orig,
+ Map vars) {
ActionConfig config = null;
try {
@@ -145,14 +148,17 @@
}
catch (Exception ex) {
log.warn("Unable to clone action config, recommend not using "
- + "wildcards", ex);
+ + "wildcards", ex);
+
return null;
}
config.setName(convertParam(orig.getName(), vars));
- if (path.length() == 0 || path.charAt(0) != '/') {
+
+ if ((path.length() == 0) || (path.charAt(0) != '/')) {
path = "/" + path;
}
+
config.setPath(path);
config.setType(convertParam(orig.getType(), vars));
config.setRoles(convertParam(orig.getRoles(), vars));
@@ -163,12 +169,14 @@
config.setInput(convertParam(orig.getInput(), vars));
config.setCatalog(convertParam(orig.getCatalog(), vars));
config.setCommand(convertParam(orig.getCommand(), vars));
- config.setMultipartClass(convertParam(orig.getMultipartClass(), vars));
+ config.setMultipartClass(convertParam(orig.getMultipartClass(),
+ vars));
config.setPrefix(convertParam(orig.getPrefix(), vars));
config.setSuffix(convertParam(orig.getSuffix(), vars));
ForwardConfig[] fConfigs = orig.findForwardConfigs();
ForwardConfig cfg;
+
for (int x = 0; x < fConfigs.length; x++) {
cfg = new ActionForward();
cfg.setName(fConfigs[x].getName());
@@ -176,9 +184,11 @@
cfg.setRedirect(fConfigs[x].getRedirect());
cfg.setCommand(convertParam(fConfigs[x].getCommand(), vars));
cfg.setCatalog(convertParam(fConfigs[x].getCatalog(), vars));
-
- replaceProperties(fConfigs[x].getProperties(), cfg.getProperties(), vars);
-
+
+ replaceProperties(fConfigs[x].getProperties(),
+ cfg.getProperties(),
+ vars);
+
config.removeForwardConfig(fConfigs[x]);
config.addForwardConfig(cfg);
}
@@ -186,6 +196,7 @@
replaceProperties(orig.getProperties(), config.getProperties(), vars);
ExceptionConfig[] exConfigs = orig.findExceptionConfigs();
+
for (int x = 0; x < exConfigs.length; x++) {
config.addExceptionConfig(exConfigs[x]);
}
@@ -194,29 +205,31 @@
return config;
}
-
+
/**
- * Replaces placeholders from one Properties values set to another.
+ * Replaces placeholders from one Properties values set to another.
*
- * @param orig The original properties set with placehold values
- * @param props The target properties to store the processed values
- * @param vars A Map of wildcard-matched strings
+ * @param orig The original properties set with placehold values
+ * @param props The target properties to store the processed values
+ * @param vars A Map of wildcard-matched strings
*/
- protected void replaceProperties(Properties orig, Properties props, Map vars) {
+ protected void replaceProperties(Properties orig, Properties props,
+ Map vars) {
Map.Entry entry = null;
- for (Iterator i = orig.entrySet().iterator(); i.hasNext(); ) {
+
+ for (Iterator i = orig.entrySet().iterator(); i.hasNext();) {
entry = (Map.Entry) i.next();
- props.setProperty((String)entry.getKey(),
- convertParam((String)entry.getValue(), vars));
- }
+ props.setProperty((String) entry.getKey(),
+ convertParam((String) entry.getValue(), vars));
+ }
}
/**
- * Inserts into a value wildcard-matched strings where specified.
+ * Inserts into a value wildcard-matched strings where specified.
*
- * @param val The value to convert
- * @param vars A Map of wildcard-matched strings
- * @return The new value
+ * @param val The value to convert
+ * @param vars A Map of wildcard-matched strings
+ * @return The new value
*/
protected String convertParam(String val, Map vars) {
if (val == null) {
@@ -230,6 +243,7 @@
StringBuffer ret = new StringBuffer(val);
String keyTmp;
int x;
+
for (Iterator i = vars.entrySet().iterator(); i.hasNext();) {
entry = (Map.Entry) i.next();
key.setCharAt(1, ((String) entry.getKey()).charAt(0));
@@ -240,25 +254,29 @@
ret.replace(x, x + 3, (String) entry.getValue());
}
}
+
return ret.toString();
}
/**
- * Stores a compiled wildcard pattern and the ActionConfig it came from.
+ * Stores a compiled wildcard pattern and the ActionConfig it came from.
*/
private class Mapping implements Serializable {
-
- /** The compiled pattern. */
+ /**
+ * The compiled pattern.
+ */
private int[] pattern;
- /** The original ActionConfig. */
+ /**
+ * The original ActionConfig.
+ */
private ActionConfig config;
/**
- * Contructs a read-only Mapping instance.
+ * Contructs a read-only Mapping instance.
*
- * @param pattern The compiled pattern
- * @param config The original ActionConfig
+ * @param pattern The compiled pattern
+ * @param config The original ActionConfig
*/
public Mapping(int[] pattern, ActionConfig config) {
this.pattern = pattern;
@@ -266,22 +284,21 @@
}
/**
- * Gets the compiled wildcard pattern.
+ * Gets the compiled wildcard pattern.
*
- * @return The compiled pattern
+ * @return The compiled pattern
*/
public int[] getPattern() {
return this.pattern;
}
/**
- * Gets the ActionConfig that contains the pattern.
+ * Gets the ActionConfig that contains the pattern.
*
- * @return The associated ActionConfig
+ * @return The associated ActionConfig
*/
public ActionConfig getActionConfig() {
return this.config;
}
}
}
-
Modified: struts/action/trunk/src/java/org/apache/struts/config/BaseConfig.java
URL: http://svn.apache.org/viewcvs/struts/action/trunk/src/java/org/apache/struts/config/BaseConfig.java?rev=370938&r1=370937&r2=370938&view=diff
==============================================================================
--- struts/action/trunk/src/java/org/apache/struts/config/BaseConfig.java (original)
+++ struts/action/trunk/src/java/org/apache/struts/config/BaseConfig.java Fri Jan 20 16:19:02 2006
@@ -1,65 +1,56 @@
/*
- * $Id$
+ * $Id$
*
* Copyright 1999-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.config;
-
import java.io.Serializable;
-
-import java.util.Properties;
import java.util.Enumeration;
-import java.lang.reflect.InvocationTargetException;
-
+import java.util.Properties;
/**
- * A abstract base class for all config classes. Provide basic support for arbitrary properties
- *
+ * A abstract base class for all config classes. Provide basic support for
+ * arbitrary properties
*
* @since Struts 1.3
*/
public abstract class BaseConfig implements Serializable {
-
-
/**
- * Indicates if configuration of this component been completed.
- * TODO change protected to private and use methods provided by extenders?
+ * Indicates if configuration of this component been completed. TODO
+ * change protected to private and use methods provided by extenders?
*/
protected boolean configured = false;
/**
* A map of arbitrary properties configured for this component.
+ *
* @since Struts 1.3
*/
private Properties properties = new Properties();
-
-
/**
* Freeze the configuration of this action.
*/
public void freeze() {
configured = true;
}
-
/**
- * Throw <code>IllegalStateException</code> if configuration is
- * frozen.
+ * Throw <code>IllegalStateException</code> if configuration is frozen.
+ *
* @throws IllegalStateException if configuration is frozen
*/
public void throwIfConfigured() {
@@ -68,17 +59,14 @@
}
}
-
/**
- * Set an arbitary key/value pair which can be retrieved by
- * this config class. This facility should eliminate many use
- * cases for subclassing <code>*Config</code> classes by
- * providing a mechanism to pass any amount of arbitrary
- * configuration information into an config class.
- * <p />
- * This method must not be called after configuration is complete, or an
- * <code>IllegalStateException</code> will be thrown.</p>
- *
+ * Set an arbitary key/value pair which can be retrieved by this config
+ * class. This facility should eliminate many use cases for subclassing
+ * <code>*Config</code> classes by providing a mechanism to pass any
+ * amount of arbitrary configuration information into an config class. <p
+ * /> This method must not be called after configuration is complete, or
+ * an <code>IllegalStateException</code> will be thrown.</p>
+ *
* <p><b>Example</b>
* <code><pre>
* <action path="/example" type="com.example.MyAction">
@@ -86,22 +74,21 @@
* </action>
* </pre></code>
* </p>
- *
- * @param key the key by which this value will be retrieved
+ *
+ * @param key the key by which this value will be retrieved
* @param value the value to store with the supplied key
+ * @throws IllegalStateException if this module configuration has been
+ * frozen
* @since Struts 1.3
- * @exception IllegalStateException if this module configuration
- * has been frozen
*/
public void setProperty(String key, String value) {
throwIfConfigured();
- properties.setProperty(key,value);
+ properties.setProperty(key, value);
}
-
/**
- * Return the property-value for the specified key, if any;
- * otherwise return <code>null</code>.
+ * Return the property-value for the specified key, if any; otherwise
+ * return <code>null</code>.
*
* @param key a key specified in the <code>struts-config</code> file
* @return the value stored with the supplied key
@@ -110,23 +97,22 @@
public String getProperty(String key) {
return properties.getProperty(key);
}
-
/**
- * Return the entire set of properties configured for this object.
- * At this time, this only needs to be exposed to support inheritance,
- * so choosing a conservative access modifier ("protected").
+ * Return the entire set of properties configured for this object. At this
+ * time, this only needs to be exposed to support inheritance, so choosing
+ * a conservative access modifier ("protected").
+ *
* @return
*/
protected Properties getProperties() {
return this.properties;
}
-
/**
- * Set the entire set of properties configured for this object.
- * At this time, this only needs to be exposed to support inheritance,
- * so choosing a conservative access modifier ("protected").
+ * Set the entire set of properties configured for this object. At this
+ * time, this only needs to be exposed to support inheritance, so choosing
+ * a conservative access modifier ("protected").
*/
protected void setProperties(Properties properties) {
this.properties = properties;
@@ -137,20 +123,21 @@
* copy those that are not present. This method is used by subclasses
* that support configuration inheritance.</p>
*
- * @param baseConfig The config object to copy properties from.
+ * @param baseConfig The config object to copy properties from.
*/
protected void inheritProperties(BaseConfig baseConfig) {
-
throwIfConfigured();
// Inherit forward properties
Properties baseProperties = baseConfig.getProperties();
Enumeration keys = baseProperties.propertyNames();
+
while (keys.hasMoreElements()) {
String key = (String) keys.nextElement();
// Check if we have this property before copying it
String value = this.getProperty(key);
+
if (value == null) {
value = baseProperties.getProperty(key);
setProperty(key, value);
@@ -158,22 +145,20 @@
}
}
-
/**
* <p>Return a copy of the properties held by this object.</p>
*/
protected Properties copyProperties() {
-
Properties copy = new Properties();
-
+
Enumeration keys = properties.propertyNames();
+
while (keys.hasMoreElements()) {
String key = (String) keys.nextElement();
+
copy.setProperty(key, properties.getProperty(key));
}
-
+
return copy;
}
-
}
-
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@struts.apache.org
For additional commands, e-mail: dev-help@struts.apache.org