Example usage for org.springframework.web.util UrlPathHelper getPathWithinServletMapping

List of usage examples for org.springframework.web.util UrlPathHelper getPathWithinServletMapping

Introduction

In this page you can find the example usage for org.springframework.web.util UrlPathHelper getPathWithinServletMapping.

Prototype

public String getPathWithinServletMapping(HttpServletRequest request) 

Source Link

Document

Return the path within the servlet mapping for the given request, i.e.

Usage

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

private Map<String, String> buildLanguageLinks(String currentLanguage, List<String> languages,
        HttpServletRequest request) {//from  ww  w  .  j  a  va  2s  . 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;
}