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

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

Introduction

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

Prototype

public String getOriginatingServletPath(HttpServletRequest request) 

Source Link

Document

Return the servlet path for the given request, detecting an include request URL if called within a RequestDispatcher include.

Usage

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

@Override
public RewriteMatch matches(HttpServletRequest request, HttpServletResponse response) {
    UrlPathHelper urlPathHelper = new UrlPathHelper();

    String servletPath = urlPathHelper.getOriginatingServletPath(request);
    if (ObjectUtils.nullSafeEquals(servletPath, WallRideServletConfiguration.ADMIN_SERVLET_PATH)) {
        return null;
    }/*w  w w.  java  2  s.  co  m*/

    String lookupPath = urlPathHelper.getLookupPathForRequest(request);

    Blog blog = blogService.getBlogById(Blog.DEFAULT_ID);
    if (blog == null) {
        return null;
    }

    BlogLanguage matchedBlogLanguage = null;
    for (BlogLanguage blogLanguage : blog.getLanguages()) {
        if (lookupPath.startsWith("/" + blogLanguage.getLanguage() + "/")) {
            matchedBlogLanguage = blogLanguage;
            break;
        }
    }

    if (matchedBlogLanguage == null) {
        matchedBlogLanguage = blog.getLanguage(blog.getDefaultLanguage());
    }

    return new BlogLanguageRewriteMatch(matchedBlogLanguage);
}