You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by vg...@apache.org on 2003/11/16 01:52:08 UTC
cvs commit: cocoon-2.1/src/blocks/scratchpad/java/org/apache/cocoon/ant UriType.java
vgritsenko 2003/11/15 16:52:08
Modified: src/java/org/apache/cocoon/environment/commandline
CommandLineRequest.java FileSavingEnvironment.java
LinkSamplingEnvironment.java
src/java/org/apache/cocoon/util NetUtils.java
src/blocks/scratchpad/java/org/apache/cocoon/ant
UriType.java
Log:
Modify NetUtils to allow parsing of multivalue request parameters.
Revision Changes Path
1.5 +29 -23 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.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- CommandLineRequest.java 15 Nov 2003 04:21:28 -0000 1.4
+++ CommandLineRequest.java 16 Nov 2003 00:52:08 -0000 1.5
@@ -159,6 +159,7 @@
public String getSitemapURI() {
return this.env.getURI();
}
+
public String getQueryString() { return null; } // use parameters instead
public String getPathTranslated() { return null; } // FIXME (SM) this is legal but should we do something more?
@@ -176,7 +177,20 @@
}
public String getParameter(String name) {
- return (this.parameters != null) ? (String)this.parameters.get(name) : null;
+ if (this.parameters == null) {
+ return null;
+ }
+
+ final Object value = this.parameters.get(name);
+ if (value instanceof String) {
+ return (String)value;
+ } else {
+ final String[] values = (String[]) value;
+ if (values.length == 0) {
+ return null;
+ }
+ return values[0];
+ }
}
public Enumeration getParameterNames() {
@@ -184,34 +198,40 @@
}
public String[] getParameterValues(String name) {
- final String value = this.getParameter(name);
- if (value != null) {
- return new String[] {value};
+ final Object value = this.parameters.get(name);
+ if (value instanceof String) {
+ return new String[] { (String)value };
+ } else {
+ return (String[]) value;
}
- return null;
}
public String getHeader(String name) {
return (headers != null) ? (String) headers.get(name.toLowerCase()) : null;
}
+
public int getIntHeader(String name) {
String header = (headers != null) ? (String) headers.get(name.toLowerCase()) : null;
return (header != null) ? Integer.parseInt(header) : -1;
}
+
public long getDateHeader(String name) {
//FIXME
//throw new RuntimeException (this.getClass().getName() + ".getDateHeader(String name) method not yet implemented!");
return 0;
}
+
public Enumeration getHeaders(String name) {
//throw new RuntimeException (this.getClass().getName() + ".getHeaders(String name) method not yet implemented!");
return new EmptyEnumeration();
} // FIXME
+
public Enumeration getHeaderNames() {
- if (headers != null)
+ if (headers != null) {
return new IteratorWrapper(headers.keySet().iterator());
- else
+ } else {
return new EmptyEnumeration();
+ }
}
public String getCharacterEncoding() { return characterEncoding; }
@@ -233,7 +253,6 @@
}
/**
- *
* Returns the current session associated with this request,
* or if the request does not have a session, creates one.
*
@@ -241,14 +260,12 @@
* with this request
*
* @see #getSession(boolean)
- *
*/
public Session getSession() {
return this.getSession(true);
}
/**
- *
* Returns the current <code>Session</code>
* associated with this request or, if if there is no
* current session and <code>create</code> is true, returns
@@ -272,15 +289,12 @@
* and the request has no valid session
*
* @see #getSession()
- *
- *
*/
public Session getSession(boolean create) {
return CommandLineSession.getSession(create);
}
/**
- *
* Returns the session ID specified by the client. This may
* not be the same as the ID of the actual session in use.
* For example, if the request specified an old (expired)
@@ -295,7 +309,6 @@
* not specify a session ID
*
* @see #isRequestedSessionIdValid
- *
*/
public String getRequestedSessionId() {
return (CommandLineSession.getSession(false) != null) ?
@@ -303,7 +316,6 @@
}
/**
- *
* Checks whether the requested session ID is still valid.
*
* @return <code>true</code> if this
@@ -313,14 +325,12 @@
*
* @see #getRequestedSessionId
* @see #getSession
- *
*/
public boolean isRequestedSessionIdValid() {
return (CommandLineSession.getSession(false) != null);
}
/**
- *
* Checks whether the requested session ID came in as a cookie.
*
* @return <code>true</code> if the session ID
@@ -329,14 +339,12 @@
*
*
* @see #getSession
- *
*/
public boolean isRequestedSessionIdFromCookie() {
return false;
}
/**
- *
* Checks whether the requested session ID came in as part of the
* request URL.
*
@@ -346,7 +354,6 @@
*
*
* @see #getSession
- *
*/
public boolean isRequestedSessionIdFromURL() {
return false;
@@ -354,7 +361,7 @@
public Locale getLocale() { return Locale.getDefault(); }
public Enumeration getLocales() {
- throw new RuntimeException (this.getClass().getName() + ".getLocales() method not yet implemented!");
+ throw new RuntimeException (getClass().getName() + ".getLocales() method not yet implemented!");
} // FIXME
public String getAuthType() { return null; }
@@ -366,5 +373,4 @@
public void setCharacterEncoding(java.lang.String env)
throws java.io.UnsupportedEncodingException { characterEncoding = env; }
public StringBuffer getRequestURL() { return null; }
-
}
1.5 +8 -8 cocoon-2.1/src/java/org/apache/cocoon/environment/commandline/FileSavingEnvironment.java
Index: FileSavingEnvironment.java
===================================================================
RCS file: /home/cvs/cocoon-2.1/src/java/org/apache/cocoon/environment/commandline/FileSavingEnvironment.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- FileSavingEnvironment.java 17 Aug 2003 13:43:00 -0000 1.4
+++ FileSavingEnvironment.java 16 Nov 2003 00:52:08 -0000 1.5
@@ -85,9 +85,12 @@
Logger log)
throws MalformedURLException {
super(uri, null, context, stream, log);
- this.objectModel.put(ObjectModelHelper.REQUEST_OBJECT, new CommandLineRequest(this, null, uri, null, attributes, parameters));
- this.objectModel.put(ObjectModelHelper.RESPONSE_OBJECT, new CommandLineResponse());
- this.objectModel.put(ObjectModelHelper.CONTEXT_OBJECT, cliContext);
+ this.objectModel.put(ObjectModelHelper.REQUEST_OBJECT,
+ new CommandLineRequest(this, null, uri, null, attributes, parameters));
+ this.objectModel.put(ObjectModelHelper.RESPONSE_OBJECT,
+ new CommandLineResponse());
+ this.objectModel.put(ObjectModelHelper.CONTEXT_OBJECT,
+ cliContext);
this.sourceLastModified = lastModified;
if (links != null) {
this.objectModel.put(Constants.LINK_OBJECT, links);
@@ -96,6 +99,7 @@
this.objectModel.put(Constants.LINK_COLLECTION_OBJECT, gatheredLinks);
}
}
+
public FileSavingEnvironment(String uri,
File context,
Map attributes,
@@ -134,8 +138,4 @@
public boolean isModified() {
return this.modified;
}
-
}
-
-
-
1.6 +9 -6 cocoon-2.1/src/java/org/apache/cocoon/environment/commandline/LinkSamplingEnvironment.java
Index: LinkSamplingEnvironment.java
===================================================================
RCS file: /home/cvs/cocoon-2.1/src/java/org/apache/cocoon/environment/commandline/LinkSamplingEnvironment.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- LinkSamplingEnvironment.java 19 Aug 2003 23:27:03 -0000 1.5
+++ LinkSamplingEnvironment.java 16 Nov 2003 00:52:08 -0000 1.6
@@ -82,14 +82,17 @@
Map parameters,
CommandLineContext cliContext,
Logger log)
- throws MalformedURLException, IOException {
+ throws MalformedURLException, IOException {
super(uri, Constants.LINK_VIEW, contextFile, new ByteArrayOutputStream(), log);
if (getLogger().isDebugEnabled()) {
- this.getLogger().debug("LinkSamplingEnvironment: uri = " + uri);
+ getLogger().debug("uri = " + uri);
}
- this.objectModel.put(ObjectModelHelper.REQUEST_OBJECT, new CommandLineRequest(this, null, uri, null, attributes, parameters));
- this.objectModel.put(ObjectModelHelper.RESPONSE_OBJECT, new CommandLineResponse());
- this.objectModel.put(ObjectModelHelper.CONTEXT_OBJECT, cliContext);
+ this.objectModel.put(ObjectModelHelper.REQUEST_OBJECT,
+ new CommandLineRequest(this, null, uri, null, attributes, parameters));
+ this.objectModel.put(ObjectModelHelper.RESPONSE_OBJECT,
+ new CommandLineResponse());
+ this.objectModel.put(ObjectModelHelper.CONTEXT_OBJECT,
+ cliContext);
}
/**
1.7 +50 -11 cocoon-2.1/src/java/org/apache/cocoon/util/NetUtils.java
Index: NetUtils.java
===================================================================
RCS file: /home/cvs/cocoon-2.1/src/java/org/apache/cocoon/util/NetUtils.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- NetUtils.java 31 Oct 2003 21:41:59 -0000 1.6
+++ NetUtils.java 16 Nov 2003 00:52:08 -0000 1.7
@@ -396,18 +396,20 @@
}
StringBuffer b = new StringBuffer(uri.length());
-
for (int i = 0; (i < length) && (clean[i] != null); i++) {
b.append(clean[i]);
- if ((i+1 < length) && (clean[i+1] != null)) b.append("/");
+ if ((i+1 < length) && (clean[i+1] != null)) {
+ b.append("/");
+ }
}
-
return b.toString();
}
/**
* Remove parameters from a uri.
- *
+ * Resulting Map will have either String for single value attributes,
+ * or String arrays for multivalue attributes.
+ *
* @param uri The uri path to deparameterize.
* @param parameters The map that collects parameters.
* @return The cleaned uri
@@ -426,24 +428,61 @@
break;
}
String name = p.substring(0, k);
- String value = p.substring(k+1);
- parameters.put(name, value);
+ String value = p.substring(k + 1);
+ Object values = parameters.get(name);
+ if (values == null) {
+ parameters.put(name, value);
+ } else if (values.getClass().isArray()) {
+ String[] v1 = (String[])values;
+ String[] v2 = new String[v1.length + 1];
+ System.arraycopy(v1, 0, v2, 0, v1.length);
+ v2[v1.length] = value;
+ parameters.put(name, v2);
+ } else {
+ parameters.put(name, new String[]{values.toString(), value});
+ }
}
return uri.substring(0, i);
}
+ /**
+ * Add parameters stored in the Map to the uri string.
+ * Map can contain Object values which will be converted to the string,
+ * or Object arrays, which will be treated as multivalue attributes.
+ *
+ * @param uri The uri to add parameters into
+ * @param parameters The map containing parameters to be added
+ * @return The uri with added parameters
+ */
public static String parameterize(String uri, Map parameters) {
if (parameters.size() == 0) {
return uri;
}
StringBuffer buffer = new StringBuffer(uri);
- buffer.append('?');
+ if (uri.indexOf('&') != -1) {
+ buffer.append('?');
+ } else {
+ buffer.append('&');
+ }
+
for (Iterator i = parameters.entrySet().iterator(); i.hasNext();) {
Map.Entry entry = (Map.Entry)i.next();
- buffer.append(entry.getKey());
- buffer.append('=');
- buffer.append(entry.getValue());
+ if (entry.getValue().getClass().isArray()) {
+ Object[] value = (Object[])entry.getValue();
+ for (int j = 0; j < value.length; j++) {
+ if (j > 0) {
+ buffer.append('&');
+ }
+ buffer.append(entry.getKey());
+ buffer.append('=');
+ buffer.append(value[j]);
+ }
+ } else {
+ buffer.append(entry.getKey());
+ buffer.append('=');
+ buffer.append(entry.getValue());
+ }
if (i.hasNext()) {
buffer.append('&');
}
1.3 +16 -16 cocoon-2.1/src/blocks/scratchpad/java/org/apache/cocoon/ant/UriType.java
Index: UriType.java
===================================================================
RCS file: /home/cvs/cocoon-2.1/src/blocks/scratchpad/java/org/apache/cocoon/ant/UriType.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- UriType.java 31 Oct 2003 21:41:59 -0000 1.2
+++ UriType.java 16 Nov 2003 00:52:08 -0000 1.3
@@ -183,7 +183,7 @@
/**
- * Gets the parameters attribute of the UriType object
+ * Gets the parameters attribute of the UriType object
*
* @return The parameters value
*/
@@ -193,7 +193,7 @@
/**
- * Gets the deparameterizedURI attribute of the UriType object
+ * Gets the deparameterizedURI attribute of the UriType object
*
* @return The deparameterizedURI value
*/
@@ -203,7 +203,7 @@
/**
- * Gets the sURI attribute of the UriType object
+ * Gets the sURI attribute of the UriType object
*
* @return The sURI value
*/
@@ -213,7 +213,7 @@
/**
- * Gets the mangledURI attribute of the UriType object
+ * Gets the mangledURI attribute of the UriType object
*
* @return The mangledURI value
*/
@@ -223,7 +223,7 @@
/**
- * Gets the path attribute of the UriType object
+ * Gets the path attribute of the UriType object
*
* @return The path value
*/
@@ -233,7 +233,7 @@
/**
- * Gets the filename attribute of the UriType object
+ * Gets the filename attribute of the UriType object
*
* @return The filename value
*/
@@ -243,7 +243,7 @@
/**
- * Gets the extension attribute of the UriType object
+ * Gets the extension attribute of the UriType object
*
* @return The extension value
*/
@@ -359,15 +359,15 @@
* Calculate all member values depending on the uri member value
*/
protected void init() {
- if (uri != null) {
- parameters = new HashMap();
- deparameterizedUri = NetUtils.deparameterize(uri, parameters);
- sUri = NetUtils.parameterize(deparameterizedUri, parameters);
- mangledUri = mangledUri(sUri);
- path = NetUtils.getPath(uri);
+ if (this.uri != null) {
+ this.parameters = new HashMap();
+ this.deparameterizedUri = NetUtils.deparameterize(this.uri, this.parameters);
+ this.sUri = NetUtils.parameterize(this.deparameterizedUri, this.parameters);
+ this.mangledUri = mangledUri(this.sUri);
+ this.path = NetUtils.getPath(this.uri);
- if (path.length() == 0) {
- path = "/";
+ if (this.path.length() == 0) {
+ this.path = "/";
}
}
}
Re: cvs commit: cocoon-2.1/src/blocks/scratchpad/java/org/apache/cocoon/ant
UriType.java
Posted by Vadim Gritsenko <va...@verizon.net>.
vgritsenko@apache.org wrote:
>vgritsenko 2003/11/15 16:52:08
>
> Modified: src/java/org/apache/cocoon/environment/commandline
> CommandLineRequest.java FileSavingEnvironment.java
> LinkSamplingEnvironment.java
> src/java/org/apache/cocoon/util NetUtils.java
> src/blocks/scratchpad/java/org/apache/cocoon/ant
> UriType.java
> Log:
> Modify NetUtils to allow parsing of multivalue request parameters.
>
>
Upayavira,
Can you test CLI that it did not broke? ;-)
Vadim