File D:\maven-qcr-plugin-testsunitaires\qcr4java\jenkins-master\target\site\qc\core\src\main\java\hudson\StructuredForm.java.html

1 /*
2 * The MIT License
3 *
4 * Copyright (c) 2004-2009, Sun Microsystems, Inc., Kohsuke Kawaguchi
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 * THE SOFTWARE.
23 */
24 package hudson;
25
26 import net.sf.json.JSONArray;
27 import net.sf.json.JSONObject;
28 import org.kohsuke.stapler.StaplerRequest;
29
30 import javax.servlet.ServletException;
31 import java.util.Collections;
32 import java.util.List;
33
34 /**
35 * Obtains the structured form data from {@link StaplerRequest}.
36 * See http://wiki.jenkins-ci.org/display/JENKINS/Structured+Form+Submission
37 *
38 * @author Kohsuke Kawaguchi
39 */
40 public class StructuredForm {
41
42 /**
43 * @deprecated
44 * Use {@link StaplerRequest#getSubmittedForm()}. Since 1.238.
45 */
46 public static JSONObject get(StaplerRequest req) throws ServletException {
47 return req.getSubmittedForm();
48 }
49 /**
50 * Retrieves the property of the given object and returns it as a list of {@link JSONObject}.
51 *
52 * <p>
53 * If the value doesn't exist, this method returns an empty list. If the value is
54 * a {@link JSONObject}, this method will return a singleton list. If it's a {@link JSONArray},
55 * the contents will be returned as a list.
56 *
57 * <p>
58 * Because of the way structured form submission work, this is convenient way of
59 * handling repeated multi-value entries.
60 *
61 * @since 1.233
62 */
63 public static List<JSONObject> toList(JSONObject parent, String propertyName) {
64 Object v = parent.get(propertyName);
65 if(v==null)
66 return Collections.emptyList();
67 if(v instanceof JSONObject)
68 return Collections.singletonList((JSONObject)v);
69 if(v instanceof JSONArray)
70 return (List)(JSONArray)v;
71
72 throw new IllegalArgumentException();
73 }
74 }
75