List of usage examples for org.springframework.util PathMatcher extractUriTemplateVariables
Map<String, String> extractUriTemplateVariables(String pattern, String path);
From source file:org.wallride.web.controller.guest.page.PageDescribeController.java
@Override protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception { BlogLanguage blogLanguage = (BlogLanguage) request .getAttribute(BlogLanguageMethodArgumentResolver.BLOG_LANGUAGE_ATTRIBUTE); if (blogLanguage == null) { Blog blog = blogService.getBlogById(Blog.DEFAULT_ID); blogLanguage = blog.getLanguage(blog.getDefaultLanguage()); }//from ww w. j av a 2s . co m String path = urlPathHelper.getLookupPathForRequest(request); PathMatcher pathMatcher = new AntPathMatcher(); if (!pathMatcher.match(PATH_PATTERN, path)) { throw new HttpNotFoundException(); } Map<String, String> variables = pathMatcher.extractUriTemplateVariables(PATH_PATTERN, path); request.setAttribute(HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE, variables); Page page = pageService.getPageByCode(variables.get("code"), blogLanguage.getLanguage()); if (page == null) { page = pageService.getPageByCode(variables.get("code"), blogLanguage.getBlog().getDefaultLanguage()); } if (page == null) { throw new HttpNotFoundException(); } if (page.getStatus() != Post.Status.PUBLISHED) { throw new HttpNotFoundException(); } return createModelAndView(page); }
From source file:com.bstek.dorado.web.resolver.UriResolverMapping.java
@Override protected Object lookupHandler(String urlPath, HttpServletRequest request) throws Exception { Map<String, Object> handlerMap = getHandlerMap(); Object handler = handlerMap.get(urlPath); String bestPatternMatch = urlPath; String pathWithinMapping = urlPath; if (handler == null) { PathMatcher pathMatcher = getPathMatcher(); for (Iterator<String> it = handlerMap.keySet().iterator(); it.hasNext();) { String registeredPath = it.next(); if (pathMatcher.match(registeredPath, urlPath)) { request.setAttribute("originalUrlPath", urlPath); handler = handlerMap.get(registeredPath); bestPatternMatch = registeredPath; pathWithinMapping = pathMatcher.extractPathWithinPattern(bestPatternMatch, urlPath); break; }//ww w. j a v a2 s .c om } } if (handler != null) { PathMatcher pathMatcher = getPathMatcher(); Map<String, String> uriTemplateVariables = new LinkedHashMap<String, String>(); uriTemplateVariables.putAll(pathMatcher.extractUriTemplateVariables(bestPatternMatch, urlPath)); if (logger.isDebugEnabled()) { logger.debug("URI Template variables for request [" + urlPath + "] are " + uriTemplateVariables); } handler = buildPathExposingHandler(handler, bestPatternMatch, pathWithinMapping, uriTemplateVariables); } return handler; }