List of usage examples for org.springframework.web.util UriComponentsBuilder buildAndExpand
public UriComponents buildAndExpand(Object... uriVariableValues)
From source file:org.kmnet.com.fw.web.el.Functions.java
/** * build query string from map with the specified {@link BeanWrapper}. * <p>//from w ww . j av a 2 s . c o m * query string is encoded with "UTF-8". * </p> * @param map map * @param beanWrapper beanWrapper which has the definition of each field. * @return query string. if map is not empty, return query string. ex) name1=value&name2=value&... */ public static String mapToQuery(Map<String, Object> map, BeanWrapper beanWrapper) { if (map == null || map.isEmpty()) { return ""; } UriComponentsBuilder builder = UriComponentsBuilder.fromPath(""); Map<String, Object> uriVariables = new HashMap<String, Object>(); for (Map.Entry<String, Object> e : map.entrySet()) { String name = e.getKey(); Object value = e.getValue(); builder.queryParam(name, "{" + name + "}"); TypeDescriptor sourceType; if (beanWrapper != null) { sourceType = beanWrapper.getPropertyTypeDescriptor(name); } else { sourceType = TypeDescriptor.forObject(value); } uriVariables.put(name, CONVERSION_SERVICE.convert(value, sourceType, STRING_DESC)); } String query = builder.buildAndExpand(uriVariables).encode().toString(); // remove the beginning symbol character('?') of the query string. return query.substring(1); }
From source file:com.saasovation.identityaccess.resource.NotificationResource.java
private Link linkFor(String aRelationship, String anId) { Link link = null;/*w ww . j av a 2s. c om*/ if (anId != null) { UriComponentsBuilder builder = UriComponentsBuilder.fromPath("/notifications/{notificationId}"); String linkUrl = builder.buildAndExpand(anId).toUriString(); link = new Link(linkUrl, aRelationship, null, OvationsMediaType.ID_OVATION_TYPE); } return link; }
From source file:org.wallride.web.support.DefaultModelAttributeInterceptor.java
private String buildGuestPath(String currentLanguage, List<String> languages) { UriComponentsBuilder builder = UriComponentsBuilder.fromPath(""); if (languages.size() > 1) { builder.path("/{language}"); }/*from w w w . j ava2 s .co m*/ return builder.buildAndExpand(currentLanguage).toUriString(); }
From source file:org.wallride.web.support.DefaultModelAttributeInterceptor.java
private String buildAdminPath(String currentLanguage) { // String contextPath = request.getContextPath(); UriComponentsBuilder builder = UriComponentsBuilder .fromPath(WallRideServletConfiguration.ADMIN_SERVLET_PATH); builder.path("/{language}"); return builder.buildAndExpand(currentLanguage).toUriString(); }
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(); }//from w w w . j a v a 2s.c o m return components.toUriString(); }
From source file:org.wallride.web.support.DefaultModelAttributeInterceptor.java
private Map<String, String> buildLanguageLinks(String currentLanguage, List<String> languages, HttpServletRequest request) {//w w w. j av a 2 s .c o m UrlPathHelper pathHelper = new UrlPathHelper(); Map<String, String> languageLinks = new LinkedHashMap<>(); String path = pathHelper.getPathWithinServletMapping(request); if (path.startsWith("/" + currentLanguage + "/")) { path = path.substring(currentLanguage.length() + 1); } UriComponentsBuilder uriComponentsBuilder = ServletUriComponentsBuilder.fromCurrentServletMapping() .path("/{language}").path(path).query(pathHelper.getOriginatingQueryString(request)); if (languages != null) { for (String language : languages) { languageLinks.put(language, uriComponentsBuilder.buildAndExpand(language).toUriString()); } } return languageLinks; }
From source file:com.art4ul.jcoon.context.RestClientContext.java
@Override public URI buildUri() { if (baseUrl == null) { throw new InitializationException("@BaseUrl is not set."); }/*w w w .j ava 2 s.c o m*/ UriComponentsBuilder componentsBuilder = UriComponentsBuilder.fromUriString(baseUrl + urlPath); if (httpParams != null) { //if (httpMethod == HttpMethod.GET) { for (String key : httpParams.keySet()) { componentsBuilder.queryParam(key, httpParams.get(key)); } //} } return componentsBuilder.buildAndExpand(uriVariable).toUri(); }
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 ww . jav a 2s. c o m*/ 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 . j a v a 2 s . com } UriComponents components = builder.buildAndExpand(params); if (encode) { components = components.encode(); } return components.toUriString(); }
From source file:org.wallride.web.support.AtomFeedView.java
private String link(Article article) { UriComponentsBuilder builder = ServletUriComponentsBuilder.fromCurrentContextPath(); Map<String, Object> params = new HashMap<>(); Blog blog = blogService.getBlogById(Blog.DEFAULT_ID); if (blog.getLanguages().size() > 1) { builder.path("/{language}"); params.put("language", LocaleContextHolder.getLocale().getLanguage()); }/*from w w w .ja va2 s . c om*/ 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()); return builder.buildAndExpand(params).encode().toUriString(); }