com.google.gwt.safehtml.shared.UriUtils Java Examples

The following examples show how to use com.google.gwt.safehtml.shared.UriUtils. 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: HtmlMarkdownUtils.java    From actor-platform with GNU Affero General Public License v3.0 6 votes vote down vote up
private static String urlElement(MDUrl url) {
    // Sanitizing URL
    String href = UriUtils.sanitizeUri(url.getUrl());

    // "DeSanitize" custom url scheme
    if (url.getUrl().startsWith("send:")) {
        href = UriUtils.encodeAllowEscapes(url.getUrl());
    } else {
        // HotFixing url without prefix
        if (!href.equals("#") && !href.contains("://")) {
            href = "http://" + href;
        }
    }

    return "<a " +
            "target=\"_blank\" " +
            "onClick=\"window.messenger.handleLinkClick(event)\" " +
            "href=\"" + href + "\">" +
            SafeHtmlUtils.htmlEscape(url.getUrlTitle()) +
            "</a>";
}
 
Example #2
Source File: PasswordRecoverOperation.java    From swellrt with Apache License 2.0 6 votes vote down vote up
@Override
protected void buildRestParams() throws SException {

  addPathElement("email");

  if (options.getId() != null)
    addQueryParam("id-or-email", options.getId());
  else if (options.getEmail() != null)
    addQueryParam("id-or-email", UriUtils.encode(options.getEmail()));
  else
    throw new SException(SException.MISSING_PARAMETERS, null, "User id or email is required");

  addQueryParam("recover-url", options.getUrl());
  addQueryParam("method", "password-reset");

}
 
Example #3
Source File: GwtMockitoTest.java    From gwtmockito with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldCreateFakeMessages() {
  SampleMessages messages = GWT.create(SampleMessages.class);

  assertEquals("noArgs", messages.noArgs());
  assertEquals("oneArg(somearg)", messages.oneArg("somearg"));
  assertEquals("twoArgs(onearg, twoarg)", messages.twoArgs("onearg", "twoarg"));
  assertEquals("safeHtml(arg)",
      messages.safeHtml(SafeHtmlUtils.fromTrustedString("arg")).asString());
  assertEquals("safeHtmlWithUri(argX, http://uriY)",
      messages.safeHtmlWithUri(SafeHtmlUtils.fromTrustedString("argX"),
          UriUtils.fromSafeConstant("http://uriY")).asString());
}
 
Example #4
Source File: FakeClientBundleProvider.java    From gwtmockito with Apache License 2.0 4 votes vote down vote up
/**
 * Creates a fake resource class that returns its own name where possible.
 */
@SuppressWarnings("unchecked") // safe since the proxy implements type
private <T> T createFakeResource(Class<T> type, final String name) {
  return (T) Proxy.newProxyInstance(
      FakeClientBundleProvider.class.getClassLoader(),
      new Class<?>[] {type},
      new InvocationHandler() {
        @Override
        public Object invoke(Object proxy, Method method, Object[] args) throws Exception {
          Class<?> returnType = method.getReturnType();
          if (returnType == String.class) {
            return name;
          } else if (returnType == SafeHtml.class) {
            return SafeHtmlUtils.fromTrustedString(name);
          } else if (returnType == SafeUri.class) {
            return UriUtils.fromTrustedString(name);
          } else if (returnType == boolean.class) {
            return false;
          } else if (returnType == int.class) {
            return 0;
          } else if (method.getParameterTypes().length > 0
              && method.getParameterTypes()[0] == ResourceCallback.class) {
            // Read the underlying resource type out of the generic parameter
            // in the method's argument
            Class<?> resourceType = 
                (Class<?>) 
                ((ParameterizedType) args[0].getClass().getGenericInterfaces()[0])
                .getActualTypeArguments()[0];
            ((ResourceCallback<ResourcePrototype>) args[0]).onSuccess(
                (ResourcePrototype) createFakeResource(resourceType, name));
            return null;
          } else if (returnType.isInstance(proxy)) {
            // for custom methods producing ResourcePrototype
            return proxy;
          } else {
            throw new IllegalArgumentException(
                "Unexpected return type for method " + method.getName());
          }
        }
      });
}