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 [3/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...
Modified: struts/action/trunk/src/java/org/apache/struts/action/ActionMessages.java
URL: http://svn.apache.org/viewcvs/struts/action/trunk/src/java/org/apache/struts/action/ActionMessages.java?rev=370938&r1=370937&r2=370938&view=diff
==============================================================================
--- struts/action/trunk/src/java/org/apache/struts/action/ActionMessages.java (original)
+++ struts/action/trunk/src/java/org/apache/struts/action/ActionMessages.java Fri Jan 20 16:19:02 2006
@@ -15,20 +15,19 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
package org.apache.struts.action;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
-import java.util.Iterator;
import java.util.HashMap;
+import java.util.Iterator;
import java.util.List;
/**
- * <p>A class that encapsulates messages. Messages can be either global
- * or they are specific to a particular bean property.</p>
+ * <p>A class that encapsulates messages. Messages can be either global or
+ * they are specific to a particular bean property.</p>
*
* <p>Each individual message is described by an <code>ActionMessage</code>
* object, which contains a message key (to be looked up in an appropriate
@@ -40,37 +39,32 @@
* Therefore, no synchronization is required for access to internal
* collections.</p>
*
- * @version $Rev$ $Date$
+ * @version $Rev$ $Date: 2005-08-26 21:58:39 -0400 (Fri, 26 Aug 2005)
+ * $
* @since Struts 1.1
*/
public class ActionMessages implements Serializable {
-
-
/**
* <p>Compares ActionMessageItem objects.</p>
*/
private static final Comparator actionItemComparator = new Comparator() {
public int compare(Object o1, Object o2) {
return ((ActionMessageItem) o1).getOrder()
- - ((ActionMessageItem) o2).getOrder();
+ - ((ActionMessageItem) o2).getOrder();
}
};
-
// ----------------------------------------------------- Manifest Constants
-
/**
* <p>The "property name" marker to use for global messages, as opposed to
* those related to a specific property.</p>
*/
public static final String GLOBAL_MESSAGE =
- "org.apache.struts.action.GLOBAL_MESSAGE";
-
+ "org.apache.struts.action.GLOBAL_MESSAGE";
// ----------------------------------------------------- Instance Variables
-
/**
* <p>Have the messages been retrieved from this object?</p>
*
@@ -81,40 +75,34 @@
*/
protected boolean accessed = false;
-
/**
- * <p>The accumulated set of <code>ActionMessage</code> objects (represented
- * as an ArrayList) for each property, keyed by property name.</p>
+ * <p>The accumulated set of <code>ActionMessage</code> objects
+ * (represented as an ArrayList) for each property, keyed by property
+ * name.</p>
*/
protected HashMap messages = new HashMap();
-
/**
- * <p>The current number of the property/key being added. This is used
- * to maintain the order messages are added.</p>
+ * <p>The current number of the property/key being added. This is used to
+ * maintain the order messages are added.</p>
*/
protected int iCount = 0;
-
// --------------------------------------------------------- Public Methods
-
/**
* <p>Create an empty <code>ActionMessages</code> object.</p>
*/
public ActionMessages() {
-
super();
-
}
-
/**
* <p>Create an <code>ActionMessages</code> object initialized with the
* given messages.</p>
*
- * @param messages The messages to be initially added to this object.
- * This parameter can be <code>null</code>.
+ * @param messages The messages to be initially added to this object. This
+ * parameter can be <code>null</code>.
* @since Struts 1.1
*/
public ActionMessages(ActionMessages messages) {
@@ -122,17 +110,15 @@
this.add(messages);
}
-
/**
* <p>Add a message to the set of messages for the specified property. An
* order of the property/key is maintained based on the initial addition
* of the property/key.</p>
*
- * @param property Property name (or ActionMessages.GLOBAL_MESSAGE)
- * @param message The message to be added
+ * @param property Property name (or ActionMessages.GLOBAL_MESSAGE)
+ * @param message The message to be added
*/
public void add(String property, ActionMessage message) {
-
ActionMessageItem item = (ActionMessageItem) messages.get(property);
List list = null;
@@ -146,79 +132,70 @@
}
list.add(message);
-
}
-
/**
* <p>Adds the messages from the given <code>ActionMessages</code> object
* to this set of messages. The messages are added in the order they are
- * returned from the <code>properties</code> method. If a message's property
- * is already in the current <code>ActionMessages</code> object, it is added
- * to the end of the list for that property. If a message's property is not
- * in the current list it is added to the end of the properties.</p>
+ * returned from the <code>properties</code> method. If a message's
+ * property is already in the current <code>ActionMessages</code> object,
+ * it is added to the end of the list for that property. If a message's
+ * property is not in the current list it is added to the end of the
+ * properties.</p>
*
- * @param actionMessages The <code>ActionMessages</code> object to be added.
- * This parameter can be <code>null</code>.
+ * @param actionMessages The <code>ActionMessages</code> object to be
+ * added. This parameter can be <code>null</code>.
* @since Struts 1.1
*/
public void add(ActionMessages actionMessages) {
-
if (actionMessages == null) {
return;
}
// loop over properties
Iterator props = actionMessages.properties();
+
while (props.hasNext()) {
String property = (String) props.next();
// loop over messages for each property
Iterator msgs = actionMessages.get(property);
+
while (msgs.hasNext()) {
ActionMessage msg = (ActionMessage) msgs.next();
+
this.add(property, msg);
}
}
}
-
/**
* <p>Clear all messages recorded by this object.</p>
*/
public void clear() {
-
messages.clear();
-
}
-
/**
- * <p>Return <code>true</code> if there are no messages recorded
- * in this collection, or <code>false</code> otherwise.</p>
+ * <p>Return <code>true</code> if there are no messages recorded in this
+ * collection, or <code>false</code> otherwise.</p>
*
* @return <code>true</code> if there are no messages recorded in this
* collection; <code>false</code> otherwise.
- *
* @since Struts 1.1
*/
public boolean isEmpty() {
-
return (messages.isEmpty());
-
-
}
-
/**
- * <p>Return the set of all recorded messages, without distinction
- * by which property the messages are associated with. If there are
- * no messages recorded, an empty enumeration is returned.</p>
+ * <p>Return the set of all recorded messages, without distinction by
+ * which property the messages are associated with. If there are no
+ * messages recorded, an empty enumeration is returned.</p>
*
* @return An iterator over the messages for all properties.
*/
public Iterator get() {
-
this.accessed = true;
if (messages.isEmpty()) {
@@ -240,7 +217,7 @@
ActionMessageItem ami = (ActionMessageItem) i.next();
for (Iterator msgsIter = ami.getList().iterator();
- msgsIter.hasNext();) {
+ msgsIter.hasNext();) {
results.add(msgsIter.next());
}
}
@@ -248,16 +225,14 @@
return results.iterator();
}
-
/**
- * <p>Return the set of messages related to a specific property.
- * If there are no such messages, an empty enumeration is returned.</p>
+ * <p>Return the set of messages related to a specific property. If there
+ * are no such messages, an empty enumeration is returned.</p>
*
* @param property Property name (or ActionMessages.GLOBAL_MESSAGE)
* @return An iterator over the messages for the specified property.
*/
public Iterator get(String property) {
-
this.accessed = true;
ActionMessageItem item = (ActionMessageItem) messages.get(property);
@@ -267,25 +242,20 @@
} else {
return (item.getList().iterator());
}
-
}
-
/**
* <p>Returns <code>true</code> if the <code>get()</code> or
* <code>get(String)</code> methods are called.</p>
*
- * @return <code>true</code> if the messages have been accessed one or more
- * times.
+ * @return <code>true</code> if the messages have been accessed one or
+ * more times.
* @since Struts 1.2
*/
public boolean isAccessed() {
-
return this.accessed;
-
}
-
/**
* <p>Return the set of property names for which at least one message has
* been recorded. If there are no messages, an empty <code>Iterator</code>
@@ -296,7 +266,6 @@
* @return An iterator over the property names for which messages exist.
*/
public Iterator properties() {
-
if (messages.isEmpty()) {
return Collections.EMPTY_LIST.iterator();
}
@@ -314,14 +283,13 @@
for (Iterator i = actionItems.iterator(); i.hasNext();) {
ActionMessageItem ami = (ActionMessageItem) i.next();
+
results.add(ami.getProperty());
}
return results.iterator();
-
}
-
/**
* <p>Return the number of messages recorded for all properties (including
* global messages). <strong>NOTE</strong> - it is more efficient to call
@@ -331,76 +299,66 @@
* @return The number of messages associated with all properties.
*/
public int size() {
-
int total = 0;
for (Iterator i = messages.values().iterator(); i.hasNext();) {
ActionMessageItem ami = (ActionMessageItem) i.next();
+
total += ami.getList().size();
}
return (total);
-
}
-
/**
- * <p>Return the number of messages associated with the specified property.
- * </p>
+ * <p>Return the number of messages associated with the specified
+ * property. </p>
*
* @param property Property name (or ActionMessages.GLOBAL_MESSAGE)
* @return The number of messages associated with the property.
*/
public int size(String property) {
-
ActionMessageItem item = (ActionMessageItem) messages.get(property);
return (item == null) ? 0 : item.getList().size();
}
-
/**
- * <p>Returns a String representation of this ActionMessages'
- * property name=message list mapping.</p>
- * @see java.lang.Object#toString()
+ * <p>Returns a String representation of this ActionMessages' property
+ * name=message list mapping.</p>
+ *
+ * @see Object#toString()
*/
public String toString() {
return this.messages.toString();
}
-
/**
* <p>This class is used to store a set of messages associated with a
* property/key and the position it was initially added to list.</p>
*/
protected class ActionMessageItem implements Serializable {
-
-
/**
* <p>The list of <code>ActionMessage</code>s.</p>
*/
protected List list = null;
-
/**
* <p>The position in the list of messages.</p>
*/
protected int iOrder = 0;
-
/**
* <p>The property associated with <code>ActionMessage</code>.</p>
*/
protected String property = null;
-
/**
* <p>Construct an instance of this class.</p>
*
* @param list The list of <code>ActionMessage</code>s.
* @param iOrder The position in the list of messages.
- * @param property The property associated with
- * <code>ActionMessage</code>.
+ * @param property The property associated with <code>ActionMessage</code>.
*/
public ActionMessageItem(List list, int iOrder, String property) {
this.list = list;
@@ -408,7 +366,6 @@
this.property = property;
}
-
/**
* <p>Retrieve the list of messages associated with this item.</p>
*
@@ -418,7 +375,6 @@
return list;
}
-
/**
* <p>Set the list of messages associated with this item.</p>
*
@@ -428,7 +384,6 @@
this.list = list;
}
-
/**
* <p>Retrieve the position in the message list.</p>
*
@@ -438,7 +393,6 @@
return iOrder;
}
-
/**
* <p>Set the position in the message list.</p>
*
@@ -448,7 +402,6 @@
this.iOrder = iOrder;
}
-
/**
* <p>Retrieve the property associated with this item.</p>
*
@@ -458,7 +411,6 @@
return property;
}
-
/**
* <p>Set the property associated with this item.</p>
*
@@ -468,7 +420,6 @@
this.property = property;
}
-
/**
* <p>Construct a string representation of this object.</p>
*
@@ -477,7 +428,5 @@
public String toString() {
return this.list.toString();
}
-
}
-
}
Modified: struts/action/trunk/src/java/org/apache/struts/action/ActionRedirect.java
URL: http://svn.apache.org/viewcvs/struts/action/trunk/src/java/org/apache/struts/action/ActionRedirect.java?rev=370938&r1=370937&r2=370938&view=diff
==============================================================================
--- struts/action/trunk/src/java/org/apache/struts/action/ActionRedirect.java (original)
+++ struts/action/trunk/src/java/org/apache/struts/action/ActionRedirect.java Fri Jan 20 16:19:02 2006
@@ -15,29 +15,25 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
package org.apache.struts.action;
-import org.apache.struts.config.ForwardConfig;
-import org.apache.struts.util.ResponseUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.apache.struts.config.ForwardConfig;
+import org.apache.struts.util.ResponseUtils;
-import java.util.Map;
-import java.util.HashMap;
-import java.util.Arrays;
import java.util.ArrayList;
-import java.util.List;
+import java.util.Arrays;
+import java.util.HashMap;
import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
/**
- * A subclass of {@link ActionForward} which is designed for use
- * in redirecting requests, with support for adding parameters
- * at runtime.
- * <br/>
- * An {@link ForwardConfig} (or subclass) can be passed to the constructor
- * to copy its configuration:
- * <br/>
+ * A subclass of {@link ActionForward} which is designed for use in
+ * redirecting requests, with support for adding parameters at runtime. <br/>
+ * An {@link ForwardConfig} (or subclass) can be passed to the constructor to
+ * copy its configuration: <br/>
* <pre>
* public ActionForward execute(ActionMapping mapping,
* ActionForm form,
@@ -57,7 +53,6 @@
* @version $Rev$ $Date$
*/
public class ActionRedirect extends ActionForward {
-
// ----------------------------------------------------- Manifest constants
/**
@@ -65,7 +60,6 @@
*/
private static final int DEFAULT_BUFFER_SIZE = 256;
-
// ----------------------------------------------------- Static variables
/**
@@ -73,22 +67,19 @@
*/
protected static final Log log = LogFactory.getLog(ActionRedirect.class);
-
// ----------------------------------------------------- Instance variables
/**
- * <p>Holds the redirect parameters.
- * Each entry is either a String or a String[] depending on whether
- * it has one or more entries.</p>
+ * <p>Holds the redirect parameters. Each entry is either a String or a
+ * String[] depending on whether it has one or more entries.</p>
*/
protected Map parameterValues = null;
-
// ----------------------------------------------------- Constructors
/**
- * <p>Construct a new instance with redirect set to true
- * and initialize parameter lists.</p>
+ * <p>Construct a new instance with redirect set to true and initialize
+ * parameter lists.</p>
*/
public ActionRedirect() {
setRedirect(true);
@@ -96,8 +87,8 @@
}
/**
- * <p>Construct a new instance with the specified path
- * and initialize parameter lists.</p>
+ * <p>Construct a new instance with the specified path and initialize
+ * parameter lists.</p>
*
* @param path Path for this instance
*/
@@ -108,11 +99,11 @@
}
/**
- * <p>Construct a new instance with the specified values
- * and initialize parameter lists.</p>
+ * <p>Construct a new instance with the specified values and initialize
+ * parameter lists.</p>
*
- * @param name Name of this instance
- * @param path Path for this instance
+ * @param name Name of this instance
+ * @param path Path for this instance
* @param module Module prefix, if any
*/
public ActionRedirect(String name, String path, String module) {
@@ -121,13 +112,12 @@
initializeParameters();
}
-
/**
- * <p>Construct a new instance with a {@link ForwardConfig} object
- * to copy name, path, and contextRelative values from.</p>
+ * <p>Construct a new instance with a {@link ForwardConfig} object to copy
+ * name, path, and contextRelative values from.</p>
*
- * @param baseConfig the {@link ForwardConfig}
- * to copy configuration values from
+ * @param baseConfig the {@link ForwardConfig} to copy configuration
+ * values from
*/
public ActionRedirect(ForwardConfig baseConfig) {
setName(baseConfig.getName());
@@ -137,67 +127,64 @@
initializeParameters();
}
-
-
// ----------------------------------------------------- Private methods
/**
- * <p>Initializes the internal objects
- * used to hold parameter values.</p>
+ * <p>Initializes the internal objects used to hold parameter values.</p>
*/
private void initializeParameters() {
parameterValues = new HashMap();
}
-
// ----------------------------------------------------- Public methods
/**
- * <p>Adds the object's toString() to the list of parameters if it's
- * not null, or an empty string with the given fieldName if it is.</p>
+ * <p>Adds the object's toString() to the list of parameters if it's not
+ * null, or an empty string with the given fieldName if it is.</p>
*
* @param fieldName the name to use for the parameter
- * @param valueObj the value for this parameter
+ * @param valueObj the value for this parameter
*/
public void addParameter(String fieldName, Object valueObj) {
-
String value = (valueObj != null) ? valueObj.toString() : "";
+
if (parameterValues == null) {
initializeParameters();
}
//try {
- value = ResponseUtils.encodeURL(value);
- //} catch (UnsupportedEncodingException uce) {
- // this shouldn't happen since UTF-8 is the W3C Recommendation
- // String errorMsg = "UTF-8 Character Encoding not supported";
- // log.error(errorMsg, uce);
- // throw new RuntimeException(errorMsg, uce);
- // }
+ value = ResponseUtils.encodeURL(value);
+ //} catch (UnsupportedEncodingException uce) {
+ // this shouldn't happen since UTF-8 is the W3C Recommendation
+ // String errorMsg = "UTF-8 Character Encoding not supported";
+ // log.error(errorMsg, uce);
+ // throw new RuntimeException(errorMsg, uce);
+ // }
Object currentValue = parameterValues.get(fieldName);
+
if (currentValue == null) {
// there's no value for this param yet; add it to the map
parameterValues.put(fieldName, value);
-
} else if (currentValue instanceof String) {
// there's already a value; let's use an array for these parameters
String[] newValue = new String[2];
+
newValue[0] = (String) currentValue;
newValue[1] = value;
parameterValues.put(fieldName, newValue);
-
} else if (currentValue instanceof String[]) {
// add the value to the list of existing values
List newValues = new ArrayList(Arrays.asList(
(Object[]) currentValue));
+
newValues.add(value);
parameterValues.put(fieldName,
- (String[]) newValues.toArray(new String[newValues.size()]));
+ (String[]) newValues
+ .toArray(new String[newValues.size()]));
}
}
-
/**
* <p>Get the original path without the parameters added at runtime.</p>
*
@@ -207,10 +194,9 @@
return super.getPath();
}
-
/**
- * <p>Get the path for this object, including any parameters
- * that may have been added at runtime.</p>
+ * <p>Get the path for this object, including any parameters that may have
+ * been added at runtime.</p>
*
* @return The path for this object.
*/
@@ -230,10 +216,13 @@
// does the original path already have a "?"?
int paramStartIndex = originalPath.indexOf("?");
+
if (paramStartIndex > 0) {
// did the path end with "?"?
needsParamSeparator =
- (paramStartIndex != originalPath.length() - 1);
+ (paramStartIndex != (originalPath.length()
+ - 1));
+
if (needsParamSeparator) {
paramSeparator = "&";
}
@@ -242,26 +231,26 @@
if (needsParamSeparator) {
result.append(paramSeparator);
}
+
result.append(parameterString);
}
return result.toString();
}
-
/**
- * <p>Forms the string containing the parameters
- * passed onto this object thru calls to addParameter().</p>
+ * <p>Forms the string containing the parameters passed onto this object
+ * thru calls to addParameter().</p>
*
- * @return a string which can be appended to the URLs. The
- * return string does not include a leading question
- * mark (?).
+ * @return a string which can be appended to the URLs. The return string
+ * does not include a leading question mark (?).
*/
public String getParameterString() {
StringBuffer strParam = new StringBuffer(DEFAULT_BUFFER_SIZE);
// loop through all parameters
Iterator iterator = parameterValues.keySet().iterator();
+
while (iterator.hasNext()) {
// get the parameter name
String paramName = (String) iterator.next();
@@ -271,18 +260,15 @@
if (value instanceof String) {
// just one value for this param
- strParam.append(paramName)
- .append("=")
- .append(value);
-
+ strParam.append(paramName).append("=").append(value);
} else if (value instanceof String[]) {
// loop through all values for this param
String[] values = (String[]) value;
+
for (int i = 0; i < values.length; i++) {
- strParam.append(paramName)
- .append("=")
- .append(values[i]);
- if (i < values.length - 1) {
+ strParam.append(paramName).append("=").append(values[i]);
+
+ if (i < (values.length - 1)) {
strParam.append("&");
}
}
@@ -296,23 +282,22 @@
return strParam.toString();
}
-
// ----------------------------------------------------- toString()
/**
* <p>Return a string description of this object.</p>
*
- * @return a string containing the original path for this object
- * and the parameters it currently holds
+ * @return a string containing the original path for this object and the
+ * parameters it currently holds
*/
public String toString() {
StringBuffer result = new StringBuffer(DEFAULT_BUFFER_SIZE);
+
result.append("ActionRedirect [");
result.append("originalPath=").append(getOriginalPath()).append(";");
- result.append("parameterString=")
- .append(getParameterString()).append("]");
+ result.append("parameterString=").append(getParameterString())
+ .append("]");
+
return result.toString();
}
-
-
}
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@struts.apache.org
For additional commands, e-mail: dev-help@struts.apache.org