dion 2004/09/12 08:52:27
Modified: jelly/jelly-tags/http/src/java/org/apache/commons/jelly/tags/http
HttpTagLibrary.java
jelly/jelly-tags/http/xdocs changes.xml
Added: jelly/jelly-tags/http/src/java/org/apache/commons/jelly/tags/http
PartTag.java MultipartPostTag.java
Log:
Jelly-59. Multi-part MIME Http Request
Revision Changes Path
1.7 +8 -6
jakarta-commons/jelly/jelly-tags/http/src/java/org/apache/commons/jelly/tags/http/HttpTagLibrary.java
Index: HttpTagLibrary.java
===================================================================
RCS file:
/home/cvs/jakarta-commons/jelly/jelly-tags/http/src/java/org/apache/commons/jelly/tags/http/HttpTagLibrary.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- HttpTagLibrary.java 9 Sep 2004 12:08:26 -0000 1.6
+++ HttpTagLibrary.java 12 Sep 2004 15:52:26 -0000 1.7
@@ -32,16 +32,18 @@
* Creates a new instance of LatkaTagLibrary
*/
public HttpTagLibrary() {
- registerTag("session", SessionTag.class);
- registerTag("get", GetTag.class);
- registerTag("post", PostTag.class);
+ registerTag("body", BodyTag.class);
registerTag("delete", DeleteTag.class);
+ registerTag("get", GetTag.class);
registerTag("head", HeadTag.class);
+ registerTag("header", HeaderTag.class);
+ registerTag("mppost", MultipartPostTag.class);
registerTag("options", OptionsTag.class);
- registerTag("put", PutTag.class);
registerTag("parameter", ParameterTag.class);
- registerTag("header", HeaderTag.class);
- registerTag("body", BodyTag.class);
+ registerTag("part", PartTag.class);
+ registerTag("post", PostTag.class);
+ registerTag("put", PutTag.class);
+ registerTag("session", SessionTag.class);
}
/**
1.1
jakarta-commons/jelly/jelly-tags/http/src/java/org/apache/commons/jelly/tags/http/PartTag.java
Index: PartTag.java
===================================================================
/*
* Copyright 2002,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.commons.jelly.tags.http;
import org.apache.commons.jelly.JellyTagException;
import org.apache.commons.jelly.TagSupport;
import org.apache.commons.jelly.XMLOutput;
import org.apache.commons.httpclient.methods.multipart.StringPart;
/**
* A tag to hold a part of a multiPartPost
*
*/
public class PartTag extends TagSupport {
/** parameter name */
private String _name;
/** parameter value */
private String _value;
/** parameter type (like text/plain) */
private String _contentType = "text/plain";
/** Creates a new instance of PartTag */
public PartTag() {
}
/**
* Extend StringPart so that I can specify the content type (ex: text/plain)
*/
private class MyStringPart extends StringPart {
String _contentType;
public MyStringPart(String name, String value, String contentType) {
super(name, value, "utf-8");
_contentType=contentType;
}
public String getContentType() { return _contentType; }
}
/**
* Perform the tag functionality. In this case, store this parameter
* in the <mppost> tag above me
*
* @param xmlOutput where to send output
* @throws Exception when an error occurs
*/
public void doTag(XMLOutput xmlOutput) throws JellyTagException {
MultipartPostTag http = (MultipartPostTag)
findAncestorWithClass(MultipartPostTag.class);
StringPart sp = new MyStringPart(getName(), getValue(), getContentType());
http.addPart(sp);
invokeBody(xmlOutput);
}
//--------------------------------------------------------------------------
// Property accessors/mutators
//--------------------------------------------------------------------------
/**
* Getter for property name.
*
* @return Value of property name.
*/
public String getName() {
return _name;
}
/**
* Setter for property name.
*
* @param name New value of property name.
*/
public void setName(String name) {
_name = name;
}
/**
* Getter for property value.
*
* @return Value of property value.
*/
public String getValue() {
return _value;
}
/**
* Setter for property value.
*
* @param value New value of property value.
*/
public void setValue(String value) {
_value = value;
}
/**
* Getter for property contentType.
*
* @return Value of contentType.
*/
public String getContentType() {
return _contentType;
}
/**
* Setter for property contentType.
*
* @param value New value of contentType.
*/
public void setContentType(String contentType) {
_contentType = contentType;
}
}
1.1
jakarta-commons/jelly/jelly-tags/http/src/java/org/apache/commons/jelly/tags/http/MultipartPostTag.java
Index: MultipartPostTag.java
===================================================================
/*
* Copyright 2002,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.commons.jelly.tags.http;
import java.net.MalformedURLException;
import java.util.ArrayList;
import java.util.List;
import org.apache.commons.httpclient.HttpMethod;
import org.apache.commons.httpclient.NameValuePair;
import org.apache.commons.httpclient.methods.MultipartPostMethod;
import org.apache.commons.httpclient.methods.multipart.Part;
import org.apache.commons.httpclient.methods.multipart.StringPart;
/**
* A Multipart MIME message post
*
* This tag should contain one or more <part> tags, to
* specify the multiple parts of the message
*
* Example:
* <pre>
* <mppost uri="http://localhost?doit">
* <part name="user" type="text/plain">Fred</part>
* <part name="data" type="text/plain">This is the second part of the
message</part>
* </mppost>
*</pre>
*
* @author <a href="mailto:[EMAIL PROTECTED]">Bill Keese</a>
*
* @since ???
*/
public class MultipartPostTag extends PostTag {
/** the post method */
private MultipartPostMethod _postMethod;
/** list of parts as name value pairs */
private List _parts;
/** Creates a new instance of MppostTag */
public MultipartPostTag() {
_parts = new ArrayList();
}
/**
* Return a [EMAIL PROTECTED] HttpUrlMethod method} to be used for multi-part
post'ing
*
* @return a HttpUrlMethod implementation
* @throws MalformedURLException when the [EMAIL PROTECTED] getUrl() url} or
* [EMAIL PROTECTED] #getPath() path} is invalid
*/
protected HttpMethod getHttpMethod() throws MalformedURLException {
if (_postMethod == null) {
_postMethod = new MultipartPostMethod(getResolvedUrl());
}
return _postMethod;
}
/**
* Add a part to the message
*
* @param name the parameter name
* @param value the parameter value
*/
public void addPart(Part p) {
_parts.add(p);
}
/**
* Set the current parameters on the url method ready for processing
*
* This method basically
* It <strong>must</strong> be called after
* [EMAIL PROTECTED] getHttpUrlMethod}
*/
protected void setParameters(HttpMethod method) {
for (int index = 0; index < _parts.size(); index++) {
((MultipartPostMethod) method).addPart( (Part) _parts.get(index) );
}
}
}
1.5 +1 -0 jakarta-commons/jelly/jelly-tags/http/xdocs/changes.xml
Index: changes.xml
===================================================================
RCS file: /home/cvs/jakarta-commons/jelly/jelly-tags/http/xdocs/changes.xml,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- changes.xml 12 Sep 2004 15:40:55 -0000 1.4
+++ changes.xml 12 Sep 2004 15:52:27 -0000 1.5
@@ -25,6 +25,7 @@
</properties>
<body>
<release version="1.1-SNAPSHOT" date="in CVS">
+ <action dev="dion" type="add" issue="JELLY-59" due-to="Bill Keese">multi-part
mime http request</action>
<action dev="dion" type="fix" issue="JELLY-96" due-to="Jason
Horne">HttpClient cannot be specified in HttpSession</action>
</release>
<release version="1.0" date="2004-09-12"></release>
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]