提交 281868ef 编写于 作者: K kohsuke

implemented structured form submission for file uploads.

See http://hudson.gotdns.com/wiki/display/HUDSON/Structured+Form+Submission for the behavior.

git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@11381 71c3de6d-444a-0410-be80-ed276b4c234a
上级 d2ea8295
......@@ -310,7 +310,7 @@
<dependency>
<groupId>org.kohsuke.stapler</groupId>
<artifactId>stapler</artifactId>
<version>1.80</version>
<version>1.81</version>
</dependency>
<dependency>
<!-- until the next rev of stapler picks up localizer 1.5 -->
......@@ -355,11 +355,6 @@
<version>2.4</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
<version>1.1</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
......
......@@ -7,6 +7,7 @@ import org.kohsuke.stapler.StaplerRequest;
import org.kohsuke.stapler.StaplerResponse;
import static javax.servlet.http.HttpServletResponse.SC_BAD_REQUEST;
import javax.servlet.ServletException;
import java.io.IOException;
import java.util.List;
import java.util.Collections;
......@@ -23,7 +24,7 @@ public class StructuredForm {
* @deprecated
* Use {@link StaplerRequest#getSubmittedForm()}. Since 1.238.
*/
public static JSONObject get(StaplerRequest req) {
public static JSONObject get(StaplerRequest req) throws ServletException {
return req.getSubmittedForm();
}
/**
......
......@@ -979,7 +979,7 @@ public abstract class AbstractProject<P extends AbstractProject<P,R>,R extends A
}
protected final <T extends Describable<T>> List<T> buildDescribable(StaplerRequest req, List<? extends Descriptor<T>> descriptors, String prefix)
throws FormException {
throws FormException, ServletException {
JSONObject data = req.getSubmittedForm();
List<T> r = new Vector<T>();
......
......@@ -1597,6 +1597,11 @@ public final class Hudson extends View implements ItemGroup<TopLevelItem>, Node,
}
}
public synchronized void doTestPost( StaplerRequest req, StaplerResponse rsp ) throws IOException, ServletException {
JSONObject form = req.getSubmittedForm();
rsp.sendRedirect("foo");
}
private boolean configureDescriptor(StaplerRequest req, JSONObject json, Descriptor<?> d) throws FormException {
// collapse the structure to remain backward compatible with the JSON structure before 1.
String name = d.getJsonSafeClassName();
......
......@@ -7,6 +7,8 @@ import java.util.List;
import org.kohsuke.stapler.StaplerRequest;
import javax.servlet.ServletException;
/**
* List of all installed SCMs.
*
......@@ -26,7 +28,7 @@ public class SCMS {
/**
* Parses {@link SCM} configuration from the submitted form.
*/
public static SCM parseSCM(StaplerRequest req) throws FormException {
public static SCM parseSCM(StaplerRequest req) throws FormException, ServletException {
String scm = req.getParameter("scm");
if(scm==null) return new NullSCM();
......
......@@ -1110,6 +1110,26 @@ function buildFormTree(form) {
addProperty(p, e.name, e.formDom = {});
}
break;
case "file":
// to support structured form submission with file uploads,
// rename form field names to unique ones, and leave this name mapping information
// in JSON. this behavior is backward incompatible, so only do
// this when
p = findParent(e);
if(e.getAttribute("jsonAware")!=null) {
var on = e.getAttribute("originalName");
if(on!=null) {
addProperty(p,on,e.name);
} else {
var uniqName = "file"+(iota++);
addProperty(p,e.name,uniqName);
e.setAttribute("originalName",e.name);
e.name = uniqName;
}
}
// switch to multipart/form-data to support file submission
form.enctype = "multipart/form-data";
break;
case "radio":
if(!e.checked) break;
if(e.groupingNode) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册