private String makeURLSave(String name, EncodingOptions encodingOptions) { return URLUtils.encodeForURL(name, encodingOptions); }
public static String encodeForURL(String value) { return encodeForURL(value, EncodingOptions.defaultOptions()); }
private static void appendRequestParameter(StringBuilder currentRequestLocation, HttpServletRequest httpRequest) { Enumeration params = httpRequest.getParameterNames(); if (!params.hasMoreElements()) { return; } currentRequestLocation.append("?"); while (params.hasMoreElements()) { String name = (String) params.nextElement(); String val = httpRequest.getParameter(name); currentRequestLocation.append(URLUtils.encodeForURL(name)); if (val != null) { currentRequestLocation.append("=").append(URLUtils.encodeForURL(val)); } currentRequestLocation.append("&"); } int lastIndex = currentRequestLocation.length() - 1; if (currentRequestLocation.charAt(lastIndex) == '&') { currentRequestLocation.deleteCharAt(lastIndex); } }
public static String buildQueryStringForUrl(Map<String, Iterable<String>> params, EncodingOptions options) { StringBuilder queryString = new StringBuilder(); for (String key : params.keySet()) { Iterable<String> values = params.get(key); Iterator<String> valueIterator = values.iterator(); if (valueIterator.hasNext()) { while (valueIterator.hasNext()) { String value = valueIterator.next(); queryString.append(encodeForURL(key, options)); queryString.append("="); queryString.append(encodeForURL(value, options)); queryString.append("&"); } } else { // only append key queryString.append(encodeForURL(key, options)); queryString.append("&"); } } if (queryString.length() > 0) { // delete ending '&' queryString.deleteCharAt(queryString.length() - 1); } return queryString.toString(); }
@Override public HTTPContentRequest cookie(String name, String value, boolean urlEncode) { if (urlEncode) { name = URLUtils.encodeForURL(name); value = URLUtils.encodeForURL(value); } // cookie header only exists once and has a value with name value pairs // we URL encode the name and value String values = m_header.getValue(HTTPHeader.COOKIE.getName()); if (!values.isEmpty() && !values.endsWith(";")) { values += ";"; } values += name + "=" + value + ";"; setHeader(HTTPHeader.COOKIE.getName(), values); return this; }
public static String encodeForURL(String value, String charset) { EncodingOptions encodingOptions = EncodingOptions.defaultOptions().charset(charset); return encodeForURL(value, encodingOptions); }