org.springframework.web.servlet.support.RequestContext Java Examples
The following examples show how to use
org.springframework.web.servlet.support.RequestContext.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RequestContextDataResolver.java From spring-soy-view with Apache License 2.0 | 6 votes |
@Override public void resolveData(final HttpServletRequest request, final HttpServletResponse response, final Map<String, ? extends Object> model, final SoyMapData root) { final RequestContext requestContext = new RequestContext(request, response, servletContext, (Map<String, Object>) model); if (requestContext.getContextPath() != null) { root.put(prefix + "contextPath", requestContext.getContextPath()); } if (requestContext.getPathToServlet() != null) { root.put(prefix + "pathToServlet", requestContext.getPathToServlet()); } if (requestContext.getQueryString() != null) { root.put(prefix + "queryString", requestContext.getQueryString()); } if (requestContext.getRequestUri() != null) { root.put(prefix + "requestUri", requestContext.getRequestUri()); } if (requestContext.getLocale() != null) { root.put(prefix + "locale", requestContext.getLocale().toString()); } }
Example #2
Source File: EmailController.java From BlogSystem with Apache License 2.0 | 6 votes |
/** * 发送反馈邮件 */ @RequestMapping(value = "/feedback", method = RequestMethod.POST) public ResultBean sendFeedback(HttpServletRequest request, @RequestParam(value = "bloggerId", required = false) Integer bloggerId, @RequestParam("content") String content, @RequestParam(value = "contact", required = false) String contact) { if (bloggerId != null) { handleBloggerSignInCheck(request, bloggerId); } String subject = new RequestContext(request).getMessage("common.feedbackTitle"); if (!emailService.sendFeedback(bloggerId == null ? -1 : bloggerId, subject, content, contact)) handlerOperateFail(request); return new ResultBean<>(""); }
Example #3
Source File: TilesView.java From spring-analysis-note with MIT License | 6 votes |
@Override protected void renderMergedOutputModel(Map<String, Object> model, HttpServletRequest request, HttpServletResponse response) throws Exception { Assert.state(this.renderer != null, "No Renderer set"); exposeModelAsRequestAttributes(model, request); if (this.exposeJstlAttributes) { JstlUtils.exposeLocalizationContext(new RequestContext(request, getServletContext())); } if (this.alwaysInclude) { request.setAttribute(AbstractRequest.FORCE_INCLUDE_ATTRIBUTE_NAME, true); } Request tilesRequest = createTilesRequest(request, response); this.renderer.render(getUrl(), tilesRequest); }
Example #4
Source File: TilesView.java From java-technology-stack with MIT License | 6 votes |
@Override protected void renderMergedOutputModel(Map<String, Object> model, HttpServletRequest request, HttpServletResponse response) throws Exception { Assert.state(this.renderer != null, "No Renderer set"); exposeModelAsRequestAttributes(model, request); if (this.exposeJstlAttributes) { JstlUtils.exposeLocalizationContext(new RequestContext(request, getServletContext())); } if (this.alwaysInclude) { request.setAttribute(AbstractRequest.FORCE_INCLUDE_ATTRIBUTE_NAME, true); } Request tilesRequest = createTilesRequest(request, response); this.renderer.render(getUrl(), tilesRequest); }
Example #5
Source File: AbstractJasperReportsView.java From lams with GNU General Public License v2.0 | 6 votes |
/** * Expose current Spring-managed Locale and MessageSource to JasperReports i18n * ($R expressions etc). The MessageSource should only be exposed as JasperReports * resource bundle if no such bundle is defined in the report itself. * <p>The default implementation exposes the Spring RequestContext Locale and a * MessageSourceResourceBundle adapter for the Spring ApplicationContext, * analogous to the {@code JstlUtils.exposeLocalizationContext} method. * @see org.springframework.web.servlet.support.RequestContextUtils#getLocale * @see org.springframework.context.support.MessageSourceResourceBundle * @see #getApplicationContext() * @see net.sf.jasperreports.engine.JRParameter#REPORT_LOCALE * @see net.sf.jasperreports.engine.JRParameter#REPORT_RESOURCE_BUNDLE * @see org.springframework.web.servlet.support.JstlUtils#exposeLocalizationContext */ protected void exposeLocalizationContext(Map<String, Object> model, HttpServletRequest request) { RequestContext rc = new RequestContext(request, getServletContext()); Locale locale = rc.getLocale(); if (!model.containsKey(JRParameter.REPORT_LOCALE)) { model.put(JRParameter.REPORT_LOCALE, locale); } TimeZone timeZone = rc.getTimeZone(); if (timeZone != null && !model.containsKey(JRParameter.REPORT_TIME_ZONE)) { model.put(JRParameter.REPORT_TIME_ZONE, timeZone); } JasperReport report = getReport(); if ((report == null || report.getResourceBundle() == null) && !model.containsKey(JRParameter.REPORT_RESOURCE_BUNDLE)) { model.put(JRParameter.REPORT_RESOURCE_BUNDLE, new MessageSourceResourceBundle(rc.getMessageSource(), locale)); } }
Example #6
Source File: BloggerCommentController.java From BlogSystem with Apache License 2.0 | 6 votes |
/** * 新增评论 */ @RequestMapping(method = RequestMethod.POST) public ResultBean add(HttpServletRequest request, @PathVariable Integer bloggerId, @RequestParam("blogId") Integer blogId, @RequestParam("content") String content, @RequestParam("listenerId") Integer listenerId) { handleBloggerSignInCheck(request, bloggerId); handleBlogExistCheck(request, blogId); handleBloggerExist(request, listenerId); if (StringUtils.isEmpty_(content) || !commentValidateManager.checkCommentContent(content)) throw exceptionManager.getParameterIllegalException(new RequestContext(request)); int id = commentService.insertComment(blogId, bloggerId, listenerId, RIGHTFUL.getCode(), content); if (id < 0) handlerOperateFail(request); return new ResultBean<>(id); }
Example #7
Source File: ImageController.java From BlogSystem with Apache License 2.0 | 6 votes |
/** * 输出公开图片,这些图片无需验证登录,如果数据库不存在指定图片,则返回默认图片 */ @RequestMapping(value = "/type=public/{imageId}", method = RequestMethod.GET) public void getBlogPicture(HttpServletRequest request, HttpServletResponse response, @PathVariable("bloggerId") Integer bloggerId, @PathVariable("imageId") Integer imageId, @RequestParam(value = "default", required = false) Integer category) { handleAccountCheck(request, bloggerId); // 检查default是否为默认类别 if (category != null) handleBlogCategoryDefaultCheck(request, category); BloggerPicture picture = bloggerPictureService.getPicture(imageId, bloggerId); // 如果图片是私有的,不能访问 if (picture != null && picture.getCategory().equals(BloggerPictureCategoryEnum.PRIVATE.getCode())) throw exceptionManager.getUnauthorizedException(new RequestContext(request)); BloggerPicture backupPicture = bloggerPictureService.getDefaultPicture( category == null ? BloggerPictureCategoryEnum.DEFAULT_PICTURE : BloggerPictureCategoryEnum.valueOf(category)); //如果目标图片不存在,返回指定类别的默认图片 // 输出图片 outPutPicture(picture, backupPicture, request, response); }
Example #8
Source File: MessageTagTests.java From java-technology-stack with MIT License | 6 votes |
@Test @SuppressWarnings("rawtypes") public void requestContext() throws ServletException { PageContext pc = createPageContext(); RequestContext rc = new RequestContext((HttpServletRequest) pc.getRequest(), pc.getServletContext()); assertEquals("test message", rc.getMessage("test")); assertEquals("test message", rc.getMessage("test", (Object[]) null)); assertEquals("test message", rc.getMessage("test", "default")); assertEquals("test message", rc.getMessage("test", (Object[]) null, "default")); assertEquals("test arg1 message arg2", rc.getMessage("testArgs", new String[] {"arg1", "arg2"}, "default")); assertEquals("test arg1 message arg2", rc.getMessage("testArgs", Arrays.asList(new String[] {"arg1", "arg2"}), "default")); assertEquals("default", rc.getMessage("testa", "default")); assertEquals("default", rc.getMessage("testa", (List) null, "default")); MessageSourceResolvable resolvable = new DefaultMessageSourceResolvable(new String[] {"test"}); assertEquals("test message", rc.getMessage(resolvable)); }
Example #9
Source File: BloggerOperateController.java From BlogSystem with Apache License 2.0 | 6 votes |
/** * 投诉博文 */ @RequestMapping(value = "/operate=complain", method = RequestMethod.POST) public ResultBean complainBlog(HttpServletRequest request, @PathVariable Integer blogId, @PathVariable Integer bloggerId, @RequestParam("content") String content) { if (StringUtils.isEmpty_(content)) throw exceptionManager.getParameterIllegalException(new RequestContext(request)); handleBloggerSignInCheck(request, bloggerId); handleBlogExistCheck(request, blogId); //执行 int id = operateService.insertComplain(blogId, bloggerId, content); if (id <= 0) handlerOperateFail(request); return new ResultBean<>(id); }
Example #10
Source File: BloggerCollectBlogController.java From BlogSystem with Apache License 2.0 | 6 votes |
/** * 修改博文收藏 */ @RequestMapping(value = "/{blogId}", method = RequestMethod.PUT) public ResultBean update(HttpServletRequest request, @PathVariable("blogId") Integer blogId, @PathVariable("bloggerId") Integer bloggerId, @RequestParam(value = "reason", required = false) String newReason) { handleBloggerSignInCheck(request, bloggerId); if (StringUtils.isEmpty(newReason)) { throw exceptionManager.getParameterIllegalException(new RequestContext(request)); } boolean result = bloggerCollectBlogService.updateCollect(bloggerId, blogId, newReason, -1); if (!result) handlerOperateFail(request); return new ResultBean<>(""); }
Example #11
Source File: BloggerBlogController.java From BlogSystem with Apache License 2.0 | 6 votes |
/** * 下载博文 */ @RequestMapping(value = "/download-type={type}", method = RequestMethod.GET) public void download(HttpServletRequest request, HttpServletResponse response, @PathVariable Integer bloggerId, @PathVariable String type) { handleBloggerSignInCheck(request, bloggerId); // 检查请求的文件类别 BlogFormatEnum format = BlogFormatEnum.get(type); if (format == null) { throw exceptionManager.getParameterIllegalException(new RequestContext(request)); } String zipFilePath = bloggerBlogService.getAllBlogForDownload(bloggerId, format); if (StringUtils.isEmpty(zipFilePath)) handlerOperateFail(request); // 输出文件流 outFile(zipFilePath, request, response); // 删除临时 zip 文件 fileManager.deleteFileIfExist(zipFilePath); }
Example #12
Source File: TilesView.java From lams with GNU General Public License v2.0 | 6 votes |
@Override protected void renderMergedOutputModel( Map<String, Object> model, HttpServletRequest request, HttpServletResponse response) throws Exception { ServletContext servletContext = getServletContext(); TilesContainer container = ServletUtil.getContainer(servletContext); if (container == null) { throw new ServletException("Tiles container is not initialized. " + "Have you added a TilesConfigurer to your web application context?"); } exposeModelAsRequestAttributes(model, request); JstlUtils.exposeLocalizationContext(new RequestContext(request, servletContext)); if (this.alwaysInclude) { ServletUtil.setForceInclude(request, true); } container.render(getUrl(), request, response); }
Example #13
Source File: BloggerGalleryController.java From BlogSystem with Apache License 2.0 | 6 votes |
/** * 从设备和数据库中删除图片 */ @RequestMapping(value = "/{pictureId}", method = RequestMethod.DELETE) @ResponseBody public ResultBean delete(HttpServletRequest request, @PathVariable("bloggerId") Integer bloggerId, @PathVariable("pictureId") Integer pictureId) { handleBloggerSignInCheck(request, bloggerId); BloggerPicture picture = bloggerPictureService.getPicture(pictureId, bloggerId); if (picture == null) { throw exceptionManager.getUnknownPictureException(new RequestContext(request)); } //检查权限 if (!validateManager.checkBloggerPictureLegal(bloggerId, picture.getCategory())) throw exceptionManager.getUnauthorizedException(new RequestContext(request)); boolean succ = bloggerPictureService.deletePicture(bloggerId, picture.getId(), true); if (!succ) handlerOperateFail(request); return new ResultBean<>(""); }
Example #14
Source File: AbstractHtmlElementTagTests.java From spring-analysis-note with MIT License | 5 votes |
protected MockPageContext createAndPopulatePageContext() throws JspException { MockPageContext pageContext = createPageContext(); MockHttpServletRequest request = (MockHttpServletRequest) pageContext.getRequest(); ((StaticWebApplicationContext) RequestContextUtils.findWebApplicationContext(request)) .registerSingleton("requestDataValueProcessor", RequestDataValueProcessorWrapper.class); extendRequest(request); extendPageContext(pageContext); RequestContext requestContext = new JspAwareRequestContext(pageContext); pageContext.setAttribute(RequestContextAwareTag.REQUEST_CONTEXT_PAGE_ATTRIBUTE, requestContext); return pageContext; }
Example #15
Source File: PageNavigationTagTest.java From sinavi-jfw with Apache License 2.0 | 5 votes |
@Before public void setUp() { MockServletContext sc = new MockServletContext(); WebApplicationContext wac = new StaticWebApplicationContext(); sc.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, wac); req = new MockHttpServletRequest(sc); resp = new MockHttpServletResponse(); context = new MockPageContext(sc, req, resp); rcon = new RequestContext(req, sc); context.setAttribute(RequestContextAwareTag.REQUEST_CONTEXT_PAGE_ATTRIBUTE, rcon); }
Example #16
Source File: AbstractHtmlElementTagTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
protected MockPageContext createAndPopulatePageContext() throws JspException { MockPageContext pageContext = createPageContext(); MockHttpServletRequest request = (MockHttpServletRequest) pageContext.getRequest(); StaticWebApplicationContext wac = (StaticWebApplicationContext) RequestContextUtils.findWebApplicationContext(request); wac.registerSingleton("requestDataValueProcessor", RequestDataValueProcessorWrapper.class); extendRequest(request); extendPageContext(pageContext); RequestContext requestContext = new JspAwareRequestContext(pageContext); pageContext.setAttribute(RequestContextAwareTag.REQUEST_CONTEXT_PAGE_ATTRIBUTE, requestContext); return pageContext; }
Example #17
Source File: BloggerLinkController.java From BlogSystem with Apache License 2.0 | 5 votes |
/** * 更新链接 */ @RequestMapping(value = "/{linkId}", method = RequestMethod.PUT) public ResultBean update(HttpServletRequest request, @PathVariable Integer bloggerId, @PathVariable Integer linkId, @RequestParam(value = "iconId", required = false) Integer newIconId, @RequestParam(value = "title", required = false) String newTitle, @RequestParam(value = "url", required = false) String newUrl, @RequestParam(value = "bewrite", required = false) String newBewrite) { RequestContext context = new RequestContext(request); //都为null则无需更新 if (newIconId == null && newTitle == null && newUrl == null && newBewrite == null) { throw exceptionManager.getParameterIllegalException(context); } handleBloggerSignInCheck(request, bloggerId); handlePictureExistCheck(request, bloggerId, newIconId); checkLinkExist(linkId, context); //检查url规范 if (newUrl != null && !StringUtils.isURL(newUrl)) { throw exceptionManager.getParameterIllegalException(context); } boolean result = bloggerLinkService.updateBloggerLink(linkId, newIconId == null ? -1 : newIconId, newTitle, newUrl, newBewrite); if (!result) handlerOperateFail(request); return new ResultBean<>(""); }
Example #18
Source File: AbstractHtmlElementTagTests.java From spring-analysis-note with MIT License | 5 votes |
protected void exposeBindingResult(Errors errors) { // wrap errors in a Model Map<String, Object> model = Collections.singletonMap( BindingResult.MODEL_KEY_PREFIX + COMMAND_NAME, errors); // replace the request context with one containing the errors MockPageContext pageContext = getPageContext(); RequestContext context = new RequestContext((HttpServletRequest) pageContext.getRequest(), model); pageContext.setAttribute(RequestContextAwareTag.REQUEST_CONTEXT_PAGE_ATTRIBUTE, context); }
Example #19
Source File: BloggerProfileController.java From BlogSystem with Apache License 2.0 | 5 votes |
private void handleParamsCheck(String phone, String email, HttpServletRequest request) { RequestContext context = new RequestContext(request); if (phone != null && !StringUtils.isPhone(phone)) throw exceptionManager.getParameterFormatIllegalException(context); if (email != null && !StringUtils.isEmail(email)) throw exceptionManager.getParameterFormatIllegalException(context); }
Example #20
Source File: ViewResolverTests.java From spring-analysis-note with MIT License | 5 votes |
private void doTestUrlBasedViewResolverWithoutPrefixes(UrlBasedViewResolver vr) throws Exception { StaticWebApplicationContext wac = new StaticWebApplicationContext(); wac.setServletContext(new MockServletContext()); wac.refresh(); vr.setApplicationContext(wac); vr.setContentType("myContentType"); vr.setRequestContextAttribute("rc"); View view = vr.resolveViewName("example1", Locale.getDefault()); assertEquals("Correct view class", JstlView.class, view.getClass()); assertEquals("Correct URL", "example1", ((InternalResourceView) view).getUrl()); assertEquals("Correct textContentType", "myContentType", ((InternalResourceView) view).getContentType()); view = vr.resolveViewName("example2", Locale.getDefault()); assertEquals("Correct view class", JstlView.class, view.getClass()); assertEquals("Correct URL", "example2", ((InternalResourceView) view).getUrl()); assertEquals("Correct textContentType", "myContentType", ((InternalResourceView) view).getContentType()); HttpServletRequest request = new MockHttpServletRequest(wac.getServletContext()); HttpServletResponse response = new MockHttpServletResponse(); request.setAttribute(DispatcherServlet.WEB_APPLICATION_CONTEXT_ATTRIBUTE, wac); request.setAttribute(DispatcherServlet.LOCALE_RESOLVER_ATTRIBUTE, new AcceptHeaderLocaleResolver()); request.setAttribute(DispatcherServlet.THEME_RESOLVER_ATTRIBUTE, new FixedThemeResolver()); Map<String, Object> model = new HashMap<>(); TestBean tb = new TestBean(); model.put("tb", tb); view.render(model, request, response); assertTrue("Correct tb attribute", tb.equals(request.getAttribute("tb"))); assertTrue("Correct rc attribute", request.getAttribute("rc") instanceof RequestContext); view = vr.resolveViewName("redirect:myUrl", Locale.getDefault()); assertEquals("Correct view class", RedirectView.class, view.getClass()); assertEquals("Correct URL", "myUrl", ((RedirectView) view).getUrl()); assertSame("View not initialized as bean", wac, ((RedirectView) view).getApplicationContext()); view = vr.resolveViewName("forward:myUrl", Locale.getDefault()); assertEquals("Correct view class", InternalResourceView.class, view.getClass()); assertEquals("Correct URL", "myUrl", ((InternalResourceView) view).getUrl()); }
Example #21
Source File: RestController.java From BlogSystem with Apache License 2.0 | 5 votes |
/** * 统一处理异常,这些异常是服务器异常 */ @ExceptionHandler(InternalRuntimeException.class) @ResponseBody protected final ResultBean handleException(HttpServletRequest request, Exception e) { //转化为未知异常 return new ResultBean(exceptionManager.getUnknownException(new RequestContext(request), e)); }
Example #22
Source File: BloggerCollectBlogController.java From BlogSystem with Apache License 2.0 | 5 votes |
/** * 收藏博文清单 */ @RequestMapping(method = RequestMethod.GET) public ResultBean<List<FavouriteBlogListItemDTO>> list(HttpServletRequest request, @PathVariable("bloggerId") Integer bloggerId, @RequestParam(value = "offset", required = false) Integer offset, @RequestParam(value = "rows", required = false) Integer rows, @RequestParam(value = "sort", required = false) String sort, @RequestParam(value = "order", required = false) String order) { final RequestContext context = new RequestContext(request); handleAccountCheck(request, bloggerId); //检查数据合法性 String sor = sort == null ? Rule.VIEW_COUNT.name() : sort.toUpperCase(); String ord = order == null ? Order.DESC.name() : order.toUpperCase(); if (!Rule.contains(sor)) throw exceptionManager.getBlogSortRuleUndefinedException(context); if (!Order.contains(ord)) throw exceptionManager.getBlogSortOrderUndefinedException(context); int os = offset == null || offset < 0 ? 0 : offset; int rs = rows == null || rows < 0 ? bloggerProperties.getRequestBloggerCollectCount() : rows; // 查询数据 ResultBean<List<FavouriteBlogListItemDTO>> result = bloggerCollectBlogService.listCollectBlog(bloggerId, bloggerProperties.getDefaultBlogCollectCategory(), os, rs, BlogSortRule.valueOf(sor, ord)); if (result == null) handlerEmptyResult(request); return result; }
Example #23
Source File: BloggerBlogCategoryController.java From BlogSystem with Apache License 2.0 | 5 votes |
/** * 删除类别,类别被删除后该类别下的所有博文将被移动到指定类别,不指定将移动到默认类别。 * 不能同时删除类别下的所有文章,删除博文通过博文api操控。 */ @RequestMapping(value = "/{categoryId}", method = RequestMethod.DELETE) public ResultBean delete(HttpServletRequest request, @PathVariable Integer bloggerId, @PathVariable Integer categoryId, @RequestParam(value = "newCategoryId", required = false) Integer newCategoryId) { handleBloggerSignInCheck(request, bloggerId); handleCategoryExistCheck(request, bloggerId, categoryId); int cate = -1; if (newCategoryId != null) { //检查删除类别和原博文移动到类别是否相同 if (newCategoryId.equals(categoryId)) throw exceptionManager.getParameterIllegalException(new RequestContext(request)); //检查新类别 handleCategoryExistCheck(request, bloggerId, newCategoryId); cate = newCategoryId; } if (!bloggerCategoryService.deleteCategoryAndMoveBlogsTo(bloggerId, categoryId, cate)) handlerOperateFail(request); return new ResultBean<>(""); }
Example #24
Source File: ViewResolverTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
private void doTestUrlBasedViewResolverWithoutPrefixes(UrlBasedViewResolver vr) throws Exception { StaticWebApplicationContext wac = new StaticWebApplicationContext(); wac.setServletContext(new MockServletContext()); wac.refresh(); vr.setApplicationContext(wac); vr.setContentType("myContentType"); vr.setRequestContextAttribute("rc"); View view = vr.resolveViewName("example1", Locale.getDefault()); assertEquals("Correct view class", JstlView.class, view.getClass()); assertEquals("Correct URL", "example1", ((InternalResourceView) view).getUrl()); assertEquals("Correct textContentType", "myContentType", ((InternalResourceView) view).getContentType()); view = vr.resolveViewName("example2", Locale.getDefault()); assertEquals("Correct view class", JstlView.class, view.getClass()); assertEquals("Correct URL", "example2", ((InternalResourceView) view).getUrl()); assertEquals("Correct textContentType", "myContentType", ((InternalResourceView) view).getContentType()); HttpServletRequest request = new MockHttpServletRequest(wac.getServletContext()); HttpServletResponse response = new MockHttpServletResponse(); request.setAttribute(DispatcherServlet.WEB_APPLICATION_CONTEXT_ATTRIBUTE, wac); request.setAttribute(DispatcherServlet.LOCALE_RESOLVER_ATTRIBUTE, new AcceptHeaderLocaleResolver()); request.setAttribute(DispatcherServlet.THEME_RESOLVER_ATTRIBUTE, new FixedThemeResolver()); Map model = new HashMap(); TestBean tb = new TestBean(); model.put("tb", tb); view.render(model, request, response); assertTrue("Correct tb attribute", tb.equals(request.getAttribute("tb"))); assertTrue("Correct rc attribute", request.getAttribute("rc") instanceof RequestContext); view = vr.resolveViewName("redirect:myUrl", Locale.getDefault()); assertEquals("Correct view class", RedirectView.class, view.getClass()); assertEquals("Correct URL", "myUrl", ((RedirectView) view).getUrl()); assertSame("View not initialized as bean", wac, ((RedirectView) view).getApplicationContext()); view = vr.resolveViewName("forward:myUrl", Locale.getDefault()); assertEquals("Correct view class", InternalResourceView.class, view.getClass()); assertEquals("Correct URL", "myUrl", ((InternalResourceView) view).getUrl()); }
Example #25
Source File: JstlView.java From lams with GNU General Public License v2.0 | 5 votes |
/** * Exposes a JSTL LocalizationContext for Spring's locale and MessageSource. * @see JstlUtils#exposeLocalizationContext */ @Override protected void exposeHelpers(HttpServletRequest request) throws Exception { if (this.messageSource != null) { JstlUtils.exposeLocalizationContext(request, this.messageSource); } else { JstlUtils.exposeLocalizationContext(new RequestContext(request, getServletContext())); } }
Example #26
Source File: BloggerAccountController.java From BlogSystem with Apache License 2.0 | 5 votes |
/** * 检查电话号码是否存在 */ @RequestMapping(value = "/check=phone", method = RequestMethod.GET) public ResultBean checkProfileExist(HttpServletRequest request, @RequestParam("phone") String phone) { BloggerAccount account = accountService.getAccountByPhone(phone); if (account != null) { return new ResultBean(exceptionManager.getDuplicationDataException(new RequestContext(request))); } else { return new ResultBean<>(""); } }
Example #27
Source File: BloggerGalleryController.java From BlogSystem with Apache License 2.0 | 5 votes |
/** * 获得多张图片 */ @RequestMapping(method = RequestMethod.GET) public ResultBean<List<BloggerPicture>> list(HttpServletRequest request, @PathVariable("bloggerId") Integer bloggerId, @RequestParam(value = "category", required = false) Integer category, @RequestParam(value = "offset", required = false) Integer offset, @RequestParam(value = "rows", required = false) Integer rows) { handleBloggerSignInCheck(request, bloggerId); RequestContext context = new RequestContext(request); int cate; if (category != null) { //检查类别是否存在 if (BloggerPictureCategoryEnum.valueOf(category) == null) { throw exceptionManager.getParameterIllegalException(context); } //检查权限 if (validateManager.checkBloggerPictureLegal(bloggerId, category)) cate = category; else throw exceptionManager.getUnauthorizedException(context); } else cate = -1; int os = offset == null || offset < 0 ? 0 : offset; int rs = rows == null || rows < 0 ? bloggerProperties.getRequestBloggerPictureCount() : rows; ResultBean<List<BloggerPicture>> result = bloggerPictureService.listBloggerPicture(bloggerId, cate == -1 ? null : BloggerPictureCategoryEnum.valueOf(cate), os, rs); if (result == null) handlerEmptyResult(request); for (BloggerPicture picture : result.getData()) { String url = stringConstructorManager.constructPictureUrl(picture, DEFAULT_PICTURE); picture.setPath(url); } return result; }
Example #28
Source File: BlogController.java From BlogSystem with Apache License 2.0 | 5 votes |
private void handleSortRuleCheck(HttpServletRequest request, String sort, String order) { if (sort != null && !Rule.contains(sort)) { throw exceptionManager.getBlogSortRuleUndefinedException(new RequestContext(request)); } if (order != null && !Order.contains(order)) { throw exceptionManager.getBlogSortOrderUndefinedException(new RequestContext(request)); } }
Example #29
Source File: ImageController.java From BlogSystem with Apache License 2.0 | 5 votes |
/** * 上传图片 */ @RequestMapping(method = RequestMethod.POST) @ResponseBody public ResultBean upload(MultipartHttpServletRequest request, @PathVariable("bloggerId") Integer bloggerId, @RequestParam(value = "category", required = false) Integer category, @RequestParam(value = "bewrite", required = false) String bewrite, @RequestParam(value = "title", required = false) String title) { handleBloggerSignInCheck(request, bloggerId); MultipartFile file = request.getFile("image");// 与页面input的name相同 int id; if (ImageUtils.isImageFile(file)) { // 默认上传到私有目录 int cate = category == null ? BloggerPictureCategoryEnum.PRIVATE.getCode() : category; // 普通用户没有指定图片类别的必要 //检查博主权限 if (!validateManager.checkBloggerPictureLegal(bloggerId, cate)) { throw exceptionManager.getUnauthorizedException(new RequestContext(request)); } id = bloggerPictureService.insertPicture(file, bloggerId, bewrite, BloggerPictureCategoryEnum.valueOf(cate), title); if (id <= 0) handlerOperateFail(request); } else { return new ResultBean(exceptionManager.getPictureFormatErrorException(new RequestContext(request))); } return new ResultBean<>(id); }
Example #30
Source File: SpringWebThymeleafContextConverter.java From ogham with Apache License 2.0 | 5 votes |
@Override public IContext convert(fr.sii.ogham.core.template.context.Context context) throws ContextException { IContext base = delegate.convert(context); // the web context may be lost due to @Async method call if (isAsyncCall()) { return base; } // partially borrowed from org.thymeleaf.spring5.view.ThymeleafView final Map<String, Object> springModel = new HashMap<>(30); HttpServletRequest request = webContextProvider.getRequest(context); HttpServletResponse response = webContextProvider.getResponse(context); ServletContext servletContext = webContextProvider.getServletContext(context); if (pathVariablesSelector != null) { @SuppressWarnings("unchecked") final Map<String, Object> pathVars = (Map<String, Object>) request.getAttribute(pathVariablesSelector); if (pathVars != null) { springModel.putAll(pathVars); } } final RequestContext requestContext = new RequestContext(request, response, servletContext, springModel); // For compatibility with ThymeleafView addRequestContextAsVariable(springModel, springRequestContextVariableName, requestContext); // For compatibility with AbstractTemplateView addRequestContextAsVariable(springModel, AbstractTemplateView.SPRING_MACRO_REQUEST_CONTEXT_ATTRIBUTE, requestContext); thymeleafRequestContextWrapper.wrapAndRegister(requestContext, request, response, servletContext, springModel); return contextMerger.merge(thymeleafWebContextProvider.getWebContext(context, base, request, response, servletContext, applicationContext, springModel), base); }