cziegeler 2004/07/12 06:27:57
Modified: src/java/org/apache/cocoon/environment Request.java
src/blocks/portal/java/org/apache/cocoon/environment/portlet
PortletRequest.java
src/java/org/apache/cocoon/environment/http HttpRequest.java
src/test/org/apache/cocoon/environment/mock MockRequest.java
src/java/org/apache/cocoon/environment/commandline
CommandLineRequest.java
Log:
Clarify/Correct the contract of the get() method
Revision Changes Path
1.11 +15 -7
cocoon-2.1/src/java/org/apache/cocoon/environment/Request.java
Index: Request.java
===================================================================
RCS file:
/home/cvs/cocoon-2.1/src/java/org/apache/cocoon/environment/Request.java,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- Request.java 12 Jul 2004 06:33:26 -0000 1.10
+++ Request.java 12 Jul 2004 13:27:57 -0000 1.11
@@ -58,15 +58,23 @@
/**
*
- * Returns the value of the named attribute as an <code>Object</code>,
- * or <code>null</code> if no attribute of the given name exists.
- *
+ * Returns the value of the named parameter as an <code>Object</code>,
+ * or <code>null</code> if no parameter of the given name exists.
+ * Basically, this method is similar to [EMAIL PROTECTED]
#getParameter(String)},
+ * but it returns an object instead.
+ * This is useful when special processing has been made on these
parameters,
+ * for example for file uploads. In this case you get an object
+ * representing the uploaded file.
+ * If the parameters have not been processed, you either get a String
+ * object if the parameter has one value, or a Collection of Strings
+ * if the parameter has more than one value.
+ *
* @param name a <code>String</code> specifying the name of
- * the attribute
+ * the parameter
*
* @return an <code>Object</code> containing the value
- * of the attribute, or <code>null</code> if
- * the attribute does not exist
+ * of the parameter, or <code>null</code> if
+ * the parameter does not exist
*
*/
Object get(String name);
1.6 +4 -1
cocoon-2.1/src/blocks/portal/java/org/apache/cocoon/environment/portlet/PortletRequest.java
Index: PortletRequest.java
===================================================================
RCS file:
/home/cvs/cocoon-2.1/src/blocks/portal/java/org/apache/cocoon/environment/portlet/PortletRequest.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- PortletRequest.java 11 Jul 2004 13:59:12 -0000 1.5
+++ PortletRequest.java 12 Jul 2004 13:27:57 -0000 1.6
@@ -86,6 +86,9 @@
this.environment = environment;
}
+ /* (non-Javadoc)
+ * @see org.apache.cocoon.environment.Request#get(java.lang.String)
+ */
public Object get(String name) {
// if the request has been wrapped then access its method
if (request instanceof MultipartActionRequest) {
1.11 +4 -1
cocoon-2.1/src/java/org/apache/cocoon/environment/http/HttpRequest.java
Index: HttpRequest.java
===================================================================
RCS file:
/home/cvs/cocoon-2.1/src/java/org/apache/cocoon/environment/http/HttpRequest.java,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- HttpRequest.java 11 Jul 2004 13:59:12 -0000 1.10
+++ HttpRequest.java 12 Jul 2004 13:27:57 -0000 1.11
@@ -71,6 +71,9 @@
this.env = env;
}
+ /* (non-Javadoc)
+ * @see org.apache.cocoon.environment.Request#get(java.lang.String)
+ */
public Object get(String name) {
// if the request has been wrapped then access its method
if (req instanceof MultipartHttpServletRequest) {
1.14 +17 -2
cocoon-2.1/src/test/org/apache/cocoon/environment/mock/MockRequest.java
Index: MockRequest.java
===================================================================
RCS file:
/home/cvs/cocoon-2.1/src/test/org/apache/cocoon/environment/mock/MockRequest.java,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -r1.13 -r1.14
--- MockRequest.java 11 Jul 2004 13:59:12 -0000 1.13
+++ MockRequest.java 12 Jul 2004 13:27:57 -0000 1.14
@@ -22,6 +22,7 @@
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
+import java.util.Vector;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.text.ParseException;
@@ -66,8 +67,22 @@
private boolean isRequestedSessionIdFromCookie = true;
private boolean isRequestedSessionIdFromURL = false;
- public Object get(String name) {
- return getAttribute(name);
+ /* (non-Javadoc)
+ * @see org.apache.cocoon.environment.Request#get(java.lang.String)
+ */
+ public Object get(String name) {
+ String[] values = this.getParameterValues(name);
+ if (values == null || values.length == 0) {
+ return null;
+ } else if (values.length == 1) {
+ return values[0];
+ } else {
+ Vector vect = new Vector(values.length);
+ for (int i = 0; i < values.length; i++) {
+ vect.add(values[i]);
+ }
+ return vect;
+ }
}
public String getAuthType() {
1.13 +19 -2
cocoon-2.1/src/java/org/apache/cocoon/environment/commandline/CommandLineRequest.java
Index: CommandLineRequest.java
===================================================================
RCS file:
/home/cvs/cocoon-2.1/src/java/org/apache/cocoon/environment/commandline/CommandLineRequest.java,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -r1.12 -r1.13
--- CommandLineRequest.java 11 Jul 2004 23:02:54 -0000 1.12
+++ CommandLineRequest.java 12 Jul 2004 13:27:57 -0000 1.13
@@ -20,6 +20,7 @@
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
+import java.util.Vector;
import org.apache.cocoon.Constants;
import org.apache.cocoon.environment.Cookie;
@@ -103,7 +104,23 @@
this.headers = headers;
}
- public Object get(String name) { return getAttribute(name); }
+ /* (non-Javadoc)
+ * @see org.apache.cocoon.environment.Request#get(java.lang.String)
+ */
+ public Object get(String name) {
+ String[] values = this.getParameterValues(name);
+ if (values == null || values.length == 0) {
+ return null;
+ } else if (values.length == 1) {
+ return values[0];
+ } else {
+ Vector vect = new Vector(values.length);
+ for (int i = 0; i < values.length; i++) {
+ vect.add(values[i]);
+ }
+ return vect;
+ }
+ }
public String getContextPath() { return contextPath; }
public String getServletPath() { return servletPath; }