001// ***************************************************************************************************************************
002// * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements.  See the NOTICE file *
003// * distributed with this work for additional information regarding copyright ownership.  The ASF licenses this file        *
004// * to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance            *
005// * with the License.  You may obtain a copy of the License at                                                              *
006// *                                                                                                                         *
007// *  http://www.apache.org/licenses/LICENSE-2.0                                                                             *
008// *                                                                                                                         *
009// * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an  *
010// * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the License for the        *
011// * specific language governing permissions and limitations under the License.                                              *
012// ***************************************************************************************************************************
013package org.apache.juneau.rest.client;
014
015import static org.apache.juneau.internal.StringUtils.*;
016
017import java.util.*;
018
019import org.apache.http.*;
020import org.apache.http.client.entity.*;
021import org.apache.http.message.*;
022import org.apache.juneau.httppart.*;
023import org.apache.juneau.oapi.*;
024import org.apache.juneau.urlencoding.*;
025
026/**
027 * Convenience class for constructing instances of <c>List&lt;NameValuePair&gt;</c> for the
028 * {@link UrlEncodedFormEntity} class.
029 *
030 * <p>
031 * Instances of this method can be passed directly to the {@link RestClient#doPost(Object, Object)} method or
032 * {@link RestCall#body(Object)} methods to perform URL-encoded form posts.
033 *
034 * <h5 class='section'>Example:</h5>
035 * <p class='bcode w800'>
036 *    NameValuePairs params = <jk>new</jk> NameValuePairs()
037 *       .append(<js>"j_username"</js>, user)
038 *       .append(<js>"j_password"</js>, pw);
039 *    restClient.doPost(url, params).run();
040 * </p>
041 *
042 * @deprecated Use {@link org.apache.juneau.http.NameValuePairSupplier}
043 */
044@Deprecated
045public final class NameValuePairs extends LinkedList<NameValuePair> {
046
047   private static final long serialVersionUID = 1L;
048
049   /**
050    * Appends the specified pair to the end of this list.
051    *
052    * @param pair The pair to append to this list.
053    * @return This object (for method chaining).
054    */
055   public NameValuePairs append(NameValuePair pair) {
056      super.add(pair);
057      return this;
058   }
059
060   /**
061    * Appends the specified name/value pair to the end of this list.
062    *
063    * <p>
064    * The value is simply converted to a string using <c>toString()</c>, or <js>"null"</js> if <jk>null</jk>.
065    *
066    * @param name The pair name.
067    * @param value The pair value.
068    * @return This object (for method chaining).
069    */
070   public NameValuePairs append(String name, Object value) {
071      super.add(new BasicNameValuePair(name, stringify(value)));
072      return this;
073   }
074
075   /**
076    * Appends the specified name/value pair to the end of this list.
077    *
078    * <p>
079    * The value is converted to UON notation using the {@link UrlEncodingSerializer} defined on the client.
080    *
081    * @param name The pair name.
082    * @param value The pair value.
083    * @param serializer
084    *    The serializer to use for serializing the value to a string value.
085    * @param schema
086    *    The schema object that defines the format of the output.
087    *    <br>If <jk>null</jk>, defaults to the schema defined on the parser.
088    *    <br>If that's also <jk>null</jk>, defaults to {@link HttpPartSchema#DEFAULT}.
089    *    <br>Only used if serializer is schema-aware (e.g. {@link OpenApiSerializer}).
090    * @return This object (for method chaining).
091    */
092   public NameValuePairs append(String name, Object value, HttpPartSerializer serializer, HttpPartSchema schema) {
093      super.add(new SerializedNameValuePair(name, value, serializer, schema));
094      return this;
095   }
096}