You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by di...@apache.org on 2002/07/07 15:58:45 UTC
cvs commit: jakarta-commons/latka/src/java/org/apache/commons/latka/jelly PostTag.java LatkaTagLibrary.java HttpTag.java
dion 2002/07/07 06:58:45
Modified: latka/src/java/org/apache/commons/latka/jelly
LatkaTagLibrary.java HttpTag.java
Added: latka/src/java/org/apache/commons/latka/jelly PostTag.java
Log:
Support for posting with parameters (i.e. forms)
Revision Changes Path
1.7 +5 -4 jakarta-commons/latka/src/java/org/apache/commons/latka/jelly/LatkaTagLibrary.java
Index: LatkaTagLibrary.java
===================================================================
RCS file: /home/cvs/jakarta-commons/latka/src/java/org/apache/commons/latka/jelly/LatkaTagLibrary.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- LatkaTagLibrary.java 6 Jul 2002 17:09:01 -0000 1.6
+++ LatkaTagLibrary.java 7 Jul 2002 13:58:45 -0000 1.7
@@ -81,6 +81,7 @@
registerTag("suite", SuiteTag.class);
registerTag("session", SessionTag.class);
registerTag("get", GetTag.class);
+ registerTag("post", PostTag.class);
registerTag("parameter", ParameterTag.class);
registerTag("header", HeaderTag.class);
}
1.10 +18 -9 jakarta-commons/latka/src/java/org/apache/commons/latka/jelly/HttpTag.java
Index: HttpTag.java
===================================================================
RCS file: /home/cvs/jakarta-commons/latka/src/java/org/apache/commons/latka/jelly/HttpTag.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- HttpTag.java 7 Jul 2002 11:17:47 -0000 1.9
+++ HttpTag.java 7 Jul 2002 13:58:45 -0000 1.10
@@ -157,11 +157,7 @@
urlMethod.addRequestHeader(header.getName(), header.getValue());
}
// add parameters
- if (getParameters().size() > 0) {
- NameValuePair[] parameters = (NameValuePair[]) getParameters().
- toArray(new NameValuePair[0]);
- urlMethod.setQueryString(parameters);
- }
+ setParameters();
// find the multi client and use it to execute the method
SessionTag sessionTag = (SessionTag) findAncestorWithClass(
SessionTag.class);
@@ -172,6 +168,19 @@
}
}
+ /**
+ * Set the current parameters on the url method ready for processing
+ *
+ * @throws MalformedURLException when {@link #getHttpUrlMethod()} does
+ */
+ protected void setParameters() throws MalformedURLException {
+ if (getParameters().size() > 0) {
+ NameValuePair[] parameters = (NameValuePair[]) getParameters().
+ toArray(new NameValuePair[0]);
+ getHttpUrlMethod().setQueryString(parameters);
+ }
+ }
+
/**
* Add a parameter to the list
*
1.1 jakarta-commons/latka/src/java/org/apache/commons/latka/jelly/PostTag.java
Index: PostTag.java
===================================================================
/*
* PostTag.java
*
* Created on July 7, 2002, 11:18 AM
*/
package org.apache.commons.latka.jelly;
import java.net.MalformedURLException;
import org.apache.commons.httpclient.HttpUrlMethod;
import org.apache.commons.httpclient.NameValuePair;
import org.apache.commons.httpclient.methods.UrlPostMethod;
/**
* A http post
*
* @author dion
*/
public class PostTag extends HttpTag {
/** the post method */
private UrlPostMethod _postMethod;
/** Creates a new instance of PostTag */
public PostTag() {
}
/**
* Return a {@link HttpUrlMethod method} to be used for post'ing
*
* @return a HttpUrlMethod implementation
* @throws MalformedURLException when the {@link getUrl() url} or
* {@link #getPath() path} is invalid
*/
protected HttpUrlMethod getHttpUrlMethod() throws MalformedURLException {
if (_postMethod == null) {
_postMethod = new UrlPostMethod(getResolvedUrl());
}
return _postMethod;
}
/**
* Set the current parameters on the url method ready for processing
*
* This method <strong>must</strong> be called after
* {@link getHttpUrlMethod}
*/
protected void setParameters() {
NameValuePair nvp = null;
for (int index = 0; index < getParameters().size(); index++) {
NameValuePair parameter = (NameValuePair) getParameters().
get(index);
_postMethod.setParameter(parameter.getName(), parameter.getValue());
}
}
}
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>