diff -r 000000000000 -r 6474c204b198 mobile/android/thirdparty/ch/boye/httpclientandroidlib/client/utils/URLEncodedUtils.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/mobile/android/thirdparty/ch/boye/httpclientandroidlib/client/utils/URLEncodedUtils.java Wed Dec 31 06:09:35 2014 +0100
@@ -0,0 +1,220 @@
+/*
+ * ====================================================================
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ *
+ * This is typically useful while parsing an HTTP PUT.
+ *
+ * @param uri
+ * uri to parse
+ * @param encoding
+ * encoding to use while parsing the query
+ */
+ public static List
+ * This is typically used while parsing an HTTP POST.
+ *
+ * @param entity
+ * The entity to parse
+ * @throws IOException
+ * If there was an exception getting the entity's data.
+ */
+ public static List application/x-www-form-urlencoded
.
+ */
+ public static boolean isEncoded (final HttpEntity entity) {
+ Header h = entity.getContentType();
+ if (h != null) {
+ HeaderElement[] elems = h.getElements();
+ if (elems.length > 0) {
+ String contentType = elems[0].getName();
+ return contentType.equalsIgnoreCase(CONTENT_TYPE);
+ } else {
+ return false;
+ }
+ } else {
+ return false;
+ }
+ }
+
+ /**
+ * Adds all parameters within the Scanner to the list of
+ * parameters
, as encoded by encoding
. For
+ * example, a scanner containing the string a=1&b=2&c=3
would
+ * add the {@link NameValuePair NameValuePairs} a=1, b=2, and c=3 to the
+ * list of parameters.
+ *
+ * @param parameters
+ * List to add parameters to.
+ * @param scanner
+ * Input that contains the parameters to parse.
+ * @param encoding
+ * Encoding to use when decoding the parameters.
+ */
+ public static void parse (
+ final List application/x-www-form-urlencoded
+ * list of parameters in an HTTP PUT or HTTP POST.
+ *
+ * @param parameters The parameters to include.
+ * @param encoding The encoding to use.
+ */
+ public static String format (
+ final List extends NameValuePair> parameters,
+ final String encoding) {
+ final StringBuilder result = new StringBuilder();
+ for (final NameValuePair parameter : parameters) {
+ final String encodedName = encode(parameter.getName(), encoding);
+ final String value = parameter.getValue();
+ final String encodedValue = value != null ? encode(value, encoding) : "";
+ if (result.length() > 0)
+ result.append(PARAMETER_SEPARATOR);
+ result.append(encodedName);
+ result.append(NAME_VALUE_SEPARATOR);
+ result.append(encodedValue);
+ }
+ return result.toString();
+ }
+
+ private static String decode (final String content, final String encoding) {
+ try {
+ return URLDecoder.decode(content,
+ encoding != null ? encoding : HTTP.DEFAULT_CONTENT_CHARSET);
+ } catch (UnsupportedEncodingException problem) {
+ throw new IllegalArgumentException(problem);
+ }
+ }
+
+ private static String encode (final String content, final String encoding) {
+ try {
+ return URLEncoder.encode(content,
+ encoding != null ? encoding : HTTP.DEFAULT_CONTENT_CHARSET);
+ } catch (UnsupportedEncodingException problem) {
+ throw new IllegalArgumentException(problem);
+ }
+ }
+
+}