Example usage for org.springframework.web.util UriComponents encode

List of usage examples for org.springframework.web.util UriComponents encode

Introduction

In this page you can find the example usage for org.springframework.web.util UriComponents encode.

Prototype

public final UriComponents encode() 

Source Link

Document

Invoke this after expanding URI variables to encode the resulting URI component values.

Usage

From source file:su90.mybatisdemo.utils.UriUtils.java

public static URI generateUri(Object info) {
    UriComponents uriComponents = MvcUriComponentsBuilder.fromMethodCall(info).build();
    return uriComponents.encode().toUri();
}

From source file:su90.mybatisdemo.utils.UriUtils.java

public static String generateAsciiStr(Object info) {
    UriComponents uriComponents = MvcUriComponentsBuilder.fromMethodCall(info).build();
    return uriComponents.encode().toUri().toASCIIString();
}

From source file:su90.mybatisdemo.utils.UriUtils.java

public static Href generateHref(Object info) {
    UriComponents uriComponents = MvcUriComponentsBuilder.fromMethodCall(info).build();
    return new Href(uriComponents.encode().toUri().toASCIIString());
}

From source file:org.wallride.web.support.Users.java

private String path(UriComponentsBuilder builder, User user, boolean encode) {
    Map<String, Object> params = new HashMap<>();
    builder.path("/author/{code}");
    params.put("code", user.getLoginId());

    UriComponents components = builder.buildAndExpand(params);
    if (encode) {
        components = components.encode();
    }//ww  w .j  a  v  a  2s . c o  m
    return components.toUriString();
}

From source file:org.wallride.support.PostUtils.java

private String path(UriComponentsBuilder builder, Article article, boolean encode) {
    Map<String, Object> params = new HashMap<>();
    builder.path("/{year}/{month}/{day}/{code}");
    params.put("year", String.format("%04d", article.getDate().getYear()));
    params.put("month", String.format("%02d", article.getDate().getMonth().getValue()));
    params.put("day", String.format("%02d", article.getDate().getDayOfMonth()));
    params.put("code", article.getCode());

    UriComponents components = builder.buildAndExpand(params);
    if (encode) {
        components = components.encode();
    }/*from w w  w .  j a  v a2 s.com*/
    return components.toUriString();
}

From source file:org.wallride.support.PostUtils.java

private String path(UriComponentsBuilder builder, Page page, boolean encode) {
    Map<String, Object> params = new HashMap<>();

    List<String> codes = new LinkedList<>();
    Map<Page, String> paths = pageUtils.getPaths(page);
    paths.keySet().stream().map(p -> p.getCode()).forEach(codes::add);

    for (int i = 0; i < codes.size(); i++) {
        String key = "code" + i;
        builder.path("/{" + key + "}");
        params.put(key, codes.get(i));/* w  w w  .ja v a  2s.com*/
    }

    UriComponents components = builder.buildAndExpand(params);
    if (encode) {
        components = components.encode();
    }
    return components.toUriString();
}