Java Code Examples for com.google.gwt.http.client.URL#encodeComponent()

The following examples show how to use com.google.gwt.http.client.URL#encodeComponent() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: UrlParameters.java    From swellrt with Apache License 2.0 6 votes vote down vote up
/**
 * Build a query string out of a map of key/value pairs.
 * @param queryEntries
 */
public static String buildQueryString(Map<String, String> queryEntries) {
  StringBuffer sb = new StringBuffer();
  boolean firstIteration = true;
  for (Entry<String, String> e : queryEntries.entrySet()) {
    if (firstIteration) {
      sb.append('?');
    } else {
      sb.append('&');
    }
    String encodedName = URL.encodeComponent(e.getKey());
    sb.append(encodedName);

    sb.append('=');

    String encodedValue = URL.encodeComponent(e.getValue());
    sb.append(encodedValue);
    firstIteration = false;
  }
  return sb.toString();
}
 
Example 2
Source File: Scrub.java    From swellrt with Apache License 2.0 6 votes vote down vote up
/**
 * Scrub a url if scrubbing is turned on
 *
 * Does not scrub urls with leading hashes
 *
 * @param url
 * @return The scrubbed version of the url, if it's not already scrubbed
 */
public static String scrub(String url) {
  if (enableScrubbing) {
    if (url.startsWith("#") || url.startsWith(REFERRER_SCRUBBING_URL)) {
      // NOTE(user): The caller should be responsible for url encoding if
      // neccessary. There is no XSS risk here as it is a fragment.
      return url;
    } else {
      String x = REFERRER_SCRUBBING_URL + URL.encodeComponent(url);
      return x;
    }
  } else {
    // If we are not scrubbing the url, then we still need to sanitize it,
    // to protect against e.g. javascript.
    String sanitizedUri = EscapeUtils.sanitizeUri(url);
    return sanitizedUri;
  }
}
 
Example 3
Source File: UrlParameters.java    From incubator-retired-wave with Apache License 2.0 6 votes vote down vote up
/**
 * Build a query string out of a map of key/value pairs.
 * @param queryEntries
 */
public static String buildQueryString(Map<String, String> queryEntries) {
  StringBuffer sb = new StringBuffer();
  boolean firstIteration = true;
  for (Entry<String, String> e : queryEntries.entrySet()) {
    if (firstIteration) {
      sb.append('?');
    } else {
      sb.append('&');
    }
    String encodedName = URL.encodeComponent(e.getKey());
    sb.append(encodedName);

    sb.append('=');

    String encodedValue = URL.encodeComponent(e.getValue());
    sb.append(encodedValue);
    firstIteration = false;
  }
  return sb.toString();
}
 
Example 4
Source File: Scrub.java    From incubator-retired-wave with Apache License 2.0 6 votes vote down vote up
/**
 * Scrub a url if scrubbing is turned on
 *
 * Does not scrub urls with leading hashes
 *
 * @param url
 * @return The scrubbed version of the url, if it's not already scrubbed
 */
public static String scrub(String url) {
  if (enableScrubbing) {
    if (url.startsWith("#") || url.startsWith(REFERRER_SCRUBBING_URL)) {
      // NOTE(user): The caller should be responsible for url encoding if
      // neccessary. There is no XSS risk here as it is a fragment.
      return url;
    } else {
      String x = REFERRER_SCRUBBING_URL + URL.encodeComponent(url);
      return x;
    }
  } else {
    // If we are not scrubbing the url, then we still need to sanitize it,
    // to protect against e.g. javascript.
    String sanitizedUri = EscapeUtils.sanitizeUri(url);
    return sanitizedUri;
  }
}
 
Example 5
Source File: GadgetWidget.java    From swellrt with Apache License 2.0 5 votes vote down vote up
/**
 * Appends tokens to the iframe URI fragment.
 *
 * @param fragment Original parameter fragment of the gadget URI.
 * @return Updated parameter fragment with new RPC and security tokens.
 */
private String updateGadgetUriFragment(String fragment) {
  fragment = "rpctoken=" + rpcToken +
        (fragment.isEmpty() || (fragment.charAt(0) == '&') ? "" : "&") + fragment;
  if ((securityToken != null) && !securityToken.isEmpty()) {
    fragment += "&st=" + URL.encodeComponent(securityToken);
  }
  return fragment;
}
 
Example 6
Source File: GadgetWidget.java    From incubator-retired-wave with Apache License 2.0 5 votes vote down vote up
/**
 * Appends tokens to the iframe URI fragment.
 *
 * @param fragment Original parameter fragment of the gadget URI.
 * @return Updated parameter fragment with new RPC and security tokens.
 */
private String updateGadgetUriFragment(String fragment) {
  fragment = "rpctoken=" + rpcToken +
        (fragment.isEmpty() || (fragment.charAt(0) == '&') ? "" : "&") + fragment;
  if ((securityToken != null) && !securityToken.isEmpty()) {
    fragment += "&st=" + URL.encodeComponent(securityToken);
  }
  return fragment;
}
 
Example 7
Source File: AnnotationSerializer.java    From swellrt with Apache License 2.0 4 votes vote down vote up
private static String escape(String s) {
  return URL.encodeComponent(s);
}
 
Example 8
Source File: AnnotationSerializer.java    From incubator-retired-wave with Apache License 2.0 4 votes vote down vote up
private static String escape(String s) {
  return URL.encodeComponent(s);
}
 
Example 9
Source File: GadgetWidget.java    From swellrt with Apache License 2.0 3 votes vote down vote up
/**
 * Utility function to convert a Gadget StateMap to a string to be stored as
 * an attribute value.
 *
 * @param state JSON object to be converted to string.
 * @return string to be saved as an attribute value.
 */
private static String stateToAttribute(StateMap state) {
  if (state == null) {
    return URL.encodeComponent("{}");
  }
  return URL.encodeComponent(state.toJson());
}
 
Example 10
Source File: GadgetWidget.java    From incubator-retired-wave with Apache License 2.0 3 votes vote down vote up
/**
 * Utility function to convert a Gadget StateMap to a string to be stored as
 * an attribute value.
 *
 * @param state JSON object to be converted to string.
 * @return string to be saved as an attribute value.
 */
private static String stateToAttribute(StateMap state) {
  if (state == null) {
    return URL.encodeComponent("{}");
  }
  return URL.encodeComponent(state.toJson());
}