Example usage for com.google.common.net UrlEscapers urlFormParameterEscaper

List of usage examples for com.google.common.net UrlEscapers urlFormParameterEscaper

Introduction

In this page you can find the example usage for com.google.common.net UrlEscapers urlFormParameterEscaper.

Prototype

public static Escaper urlFormParameterEscaper() 

Source Link

Document

Returns an Escaper instance that escapes strings so they can be safely included in <a href="http://goo.gl/OQEc8">URL form parameter names and values</a>.

Usage

From source file:org.eclipse.mylyn.internal.wikitext.commonmark.inlines.PotentialBracketEndDelimiter.java

private String normalizeUri(String uriWithEscapes) {
    String uriWithoutBackslashEscapes = unescapeBackslashEscapes(uriWithEscapes);
    try {//from  w  w  w . j  av a2 s .c o  m
        String uriWithoutHtmlEntities = replaceHtmlEntities(uriWithoutBackslashEscapes,
                UrlEscapers.urlFormParameterEscaper());
        String decoded = URLDecoder.decode(uriWithoutHtmlEntities, StandardCharsets.UTF_8.name());
        Escaper escaper = UrlEscapers.urlFragmentEscaper();
        return escaper.escape(decoded);
    } catch (Exception e) {
        return uriWithoutBackslashEscapes;
    }
}

From source file:com.pidoco.juri.JURI.java

public static CharSequence buildQueryParametersString(Multimap<String, String> currentQueryParameters) {
    StringBuilder paramsString = new StringBuilder();
    boolean first = true;
    for (Map.Entry<String, String> entry : currentQueryParameters.entries()) {
        if (!first) {
            paramsString.append('&');
        }/*from   w ww.  j  a va2s .c  o  m*/
        String keyEnc = UrlEscapers.urlFormParameterEscaper().escape(entry.getKey());
        if (entry.getValue() != null) {
            String valueEnc = UrlEscapers.urlFormParameterEscaper().escape(entry.getValue());
            paramsString.append(keyEnc).append('=').append(valueEnc);
        } else {
            paramsString.append(keyEnc);
        }
        first = false;
    }

    return paramsString;
}

From source file:com.addthis.basis.util.LessBytes.java

/**
 * Makes Strings safe to use in URLs.//from   ww  w .j  av  a2 s. c o m
 *
 * @deprecated Use {@link UrlEscapers#urlFormParameterEscaper()}. This
 *     implementation was aggressively creating byte[]s for no reason.
 */
@Deprecated
public static String urlencode(String s) {
    if (nativeURLCodec) {
        try {
            return URLEncoder.encode(s, "UTF-8");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    return UrlEscapers.urlFormParameterEscaper().escape(s);
}