private String encodePath(final String path) { return URLEncodedUtilsHC4.encPath(path, Consts.UTF_8); }
private String encodeUric(final String fragment) { return URLEncodedUtilsHC4.encUric(fragment, Consts.UTF_8); }
private String encodeUserInfo(final String userInfo) { return URLEncodedUtilsHC4.encUserInfo(userInfo, Consts.UTF_8); }
/** * Returns a list of {@link NameValuePair NameValuePairs} as parsed from the given string using the given character * encoding. By convention, {@code '&'} and {@code ';'} are accepted as parameter separators. * * @param s * text to parse. * @param charset * Encoding to use when decoding the parameters. * @return a list of {@link NameValuePair} as built from the URI's query portion. * * @since 4.2 */ public static List<NameValuePair> parse(final String s, final Charset charset) { return parse(s, charset, QP_SEPS); }
/** * Encode a String using the {@link #PATHSAFE} set of characters. * <p> * Used by URIBuilder to encode path segments. * * @param content the string to encode, does not convert space to '+' * @param charset the charset to use * @return the encoded string */ static String encPath(final String content, final Charset charset) { return urlEncode(content, charset, PATHSAFE, false); }
/** * Returns a String that is suitable for use as an {@code application/x-www-form-urlencoded} * list of parameters in an HTTP PUT or HTTP POST. * * @param parameters The parameters to include. * @param charset The encoding to use. * @return An {@code application/x-www-form-urlencoded} string */ public static String format( final List <? extends NameValuePair> parameters, final String charset) { return format(parameters, QP_SEP_A, charset); }
/** * Decode/unescape www-url-form-encoded content. * * @param content the content to decode, will decode '+' as space * @param charset the charset to use * @return encoded string */ private static String decodeFormFields (final String content, final Charset charset) { if (content == null) { return null; } return urlDecode(content, charset != null ? charset : Consts.UTF_8, true); }
/** * Returns a String that is suitable for use as an {@code application/x-www-form-urlencoded} * list of parameters in an HTTP PUT or HTTP POST. * * @param parameters The parameters to include. * @param parameterSeparator The parameter separator, by convention, {@code '&'} or {@code ';'}. * @param charset The encoding to use. * @return An {@code application/x-www-form-urlencoded} string * * @since 4.3 */ public static String format( final List <? extends NameValuePair> parameters, final char parameterSeparator, final String charset) { final StringBuilder result = new StringBuilder(); for (final NameValuePair parameter : parameters) { final String encodedName = encodeFormFields(parameter.getName(), charset); final String encodedValue = encodeFormFields(parameter.getValue(), charset); if (result.length() > 0) { result.append(parameterSeparator); } result.append(encodedName); if (encodedValue != null) { result.append(NAME_VALUE_SEPARATOR); result.append(encodedValue); } } return result.toString(); }
final int i = token.indexOf(NAME_VALUE_SEPARATOR); if (i != -1) { name = decodeFormFields(token.substring(0, i).trim(), charset); value = decodeFormFields(token.substring(i + 1).trim(), charset); } else { name = decodeFormFields(token.trim(), charset);
/** * Adds all parameters within the Scanner to the list of <code>parameters</code>, as encoded by * <code>encoding</code>. For example, a scanner containing the string <code>a=1&b=2&c=3</code> would add the * {@link NameValuePair NameValuePairs} a=1, b=2, and c=3 to the list of parameters. By convention, {@code '&'} and * {@code ';'} are accepted as parameter separators. * * @param parameters * List to add parameters to. * @param scanner * Input that contains the parameters to parse. * @param charset * Encoding to use when decoding the parameters. */ public static void parse( final List <NameValuePair> parameters, final Scanner scanner, final String charset) { parse(parameters, scanner, QP_SEP_PATTERN, charset); }
/** * Encode a String using the {@link #URIC} set of characters. * <p> * Used by URIBuilder to encode the query and fragment segments. * * @param content the string to encode, does not convert space to '+' * @param charset the charset to use * @return the encoded string */ static String encUric(final String content, final Charset charset) { return urlEncode(content, charset, URIC, false); }
private String encodeUrlForm(final List<NameValuePair> params) { return URLEncodedUtilsHC4.format(params, Consts.UTF_8); }
/** * Decode/unescape www-url-form-encoded content. * * @param content the content to decode, will decode '+' as space * @param charset the charset to use * @return encoded string */ private static String decodeFormFields (final String content, final String charset) { if (content == null) { return null; } return urlDecode(content, charset != null ? Charset.forName(charset) : Consts.UTF_8, true); }
/** * Returns a String that is suitable for use as an {@code application/x-www-form-urlencoded} * list of parameters in an HTTP PUT or HTTP POST. * * @param parameters The parameters to include. * @param parameterSeparator The parameter separator, by convention, {@code '&'} or {@code ';'}. * @param charset The encoding to use. * @return An {@code application/x-www-form-urlencoded} string * * @since 4.3 */ public static String format( final Iterable<? extends NameValuePair> parameters, final char parameterSeparator, final Charset charset) { final StringBuilder result = new StringBuilder(); for (final NameValuePair parameter : parameters) { final String encodedName = encodeFormFields(parameter.getName(), charset); final String encodedValue = encodeFormFields(parameter.getValue(), charset); if (result.length() > 0) { result.append(parameterSeparator); } result.append(encodedName); if (encodedValue != null) { result.append(NAME_VALUE_SEPARATOR); result.append(encodedValue); } } return result.toString(); }
if (nvp.getName().length() > 0) { list.add(new BasicNameValuePair( decodeFormFields(nvp.getName(), charset), decodeFormFields(nvp.getValue(), charset)));
private List <NameValuePair> parseQuery(final String query, final Charset charset) { if (query != null && query.length() > 0) { return URLEncodedUtilsHC4.parse(query, charset); } return null; }
/** * Encode a String using the {@link #USERINFO} set of characters. * <p> * Used by URIBuilder to encode the userinfo segment. * * @param content the string to encode, does not convert space to '+' * @param charset the charset to use * @return the encoded string */ static String encUserInfo(final String content, final Charset charset) { return urlEncode(content, charset, USERINFO, false); }
/** * Returns a String that is suitable for use as an {@code application/x-www-form-urlencoded} * list of parameters in an HTTP PUT or HTTP POST. * * @param parameters The parameters to include. * @param charset The encoding to use. * @return An {@code application/x-www-form-urlencoded} string * * @since 4.2 */ public static String format( final Iterable<? extends NameValuePair> parameters, final Charset charset) { return format(parameters, QP_SEP_A, charset); }
/** * Returns a list of {@link NameValuePair NameValuePairs} as built from the URI's query portion. For example, a URI * of http://example.org/path/to/file?a=1&b=2&c=3 would return a list of three NameValuePairs, one for a=1, one for * b=2, and one for c=3. By convention, {@code '&'} and {@code ';'} are accepted as parameter separators. * <p> * This is typically useful while parsing an HTTP PUT. * * This API is currently only used for testing. * * @param uri * URI to parse * @param charset * Charset name to use while parsing the query * @return a list of {@link NameValuePair} as built from the URI's query portion. */ public static List <NameValuePair> parse(final URI uri, final String charset) { final String query = uri.getRawQuery(); if (query != null && query.length() > 0) { final List<NameValuePair> result = new ArrayList<NameValuePair>(); final Scanner scanner = new Scanner(query); parse(result, scanner, QP_SEP_PATTERN, charset); return result; } return Collections.emptyList(); }
/** * Encode/escape www-url-form-encoded content. * <p> * Uses the {@link #URLENCODER} set of characters, rather than * the {@link #UNRSERVED} set; this is for compatibilty with previous * releases, URLEncoder.encode() and most browsers. * * @param content the content to encode, will convert space to '+' * @param charset the charset to use * @return encoded string */ private static String encodeFormFields (final String content, final Charset charset) { if (content == null) { return null; } return urlEncode(content, charset != null ? charset : Consts.UTF_8, URLENCODER, true); }