List of usage examples for org.springframework.web.servlet.support RequestContextUtils getLocale
public static Locale getLocale(HttpServletRequest request)
From source file:common.cms.controller.LocalizedCmsDelegate.java
/** * must show items associated with this table * @param req//from w ww. ja v a2 s .com * @param resp * @return */ @Override public ModelAndView doView(HttpServletRequest request, HttpServletResponse resp) { //logger.fine("do=view"); getCommonModel(request); request.setAttribute(config.getContentUrlAttribute(), config.getContentViewTemplate()); LocaleDataCms data = new LocaleDataCms(); List<T> cur = service.getCurrentLocalization(RequestContextUtils.getLocale(request).getLanguage()); data.setCurrent(cur); data.setOther(service.getOtherLocalization(RequestContextUtils.getLocale(request).getLanguage(), cur)); request.setAttribute(config.getContentDataAttribute(), data); return new ModelAndView(config.getTemplateUrl()); }
From source file:jetx.ext.springmvc.SpringMvcFunctions.java
/** * ??Locale //from ww w. j a v a 2s. co m */ public static Locale getLocale(JetPageContext ctx) { HttpServletRequest request = ExtendUtils.getHttpServletRequest(ctx); return RequestContextUtils.getLocale(request); }
From source file:net.sourceforge.subsonic.controller.StatusController.java
@Override protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception { Map<String, Object> map = new HashMap<String, Object>(); List<TransferStatus> streamStatuses = statusService.getAllStreamStatuses(); List<TransferStatus> downloadStatuses = statusService.getAllDownloadStatuses(); List<TransferStatus> uploadStatuses = statusService.getAllUploadStatuses(); Locale locale = RequestContextUtils.getLocale(request); List<TransferStatusHolder> transferStatuses = new ArrayList<TransferStatusHolder>(); for (int i = 0; i < streamStatuses.size(); i++) { long minutesAgo = streamStatuses.get(i).getMillisSinceLastUpdate() / 1000L / 60L; if (minutesAgo < 60L) { transferStatuses// www . j a v a2 s . co m .add(new TransferStatusHolder(streamStatuses.get(i), true, false, false, i, locale)); } } for (int i = 0; i < downloadStatuses.size(); i++) { transferStatuses.add(new TransferStatusHolder(downloadStatuses.get(i), false, true, false, i, locale)); } for (int i = 0; i < uploadStatuses.size(); i++) { transferStatuses.add(new TransferStatusHolder(uploadStatuses.get(i), false, false, true, i, locale)); } map.put("transferStatuses", transferStatuses); map.put("chartWidth", StatusChartController.IMAGE_WIDTH); map.put("chartHeight", StatusChartController.IMAGE_HEIGHT); ModelAndView result = super.handleRequestInternal(request, response); result.addObject("model", map); return result; }
From source file:nl.surfnet.coin.api.controller.AccessConfirmationController.java
@RequestMapping("/oauth2/confirm_access") public ModelAndView getAccessConfirmation(HttpServletRequest request, @ModelAttribute AuthorizationRequest clientAuth) throws Exception { ClientDetails client = clientDetailsService.loadClientByClientId(clientAuth.getClientId()); TreeMap<String, Object> model = new TreeMap<String, Object>(); model.put("auth_request", clientAuth); model.put("client", client); model.put("locale", RequestContextUtils.getLocale(request).toString()); model.put("staticContentBasePath", staticContentBasePath); Map<String, String> languageLinks = new HashMap<String, String>(); languageLinks.put("en", getUrlWithLanguageParam(request, "en")); languageLinks.put("nl", getUrlWithLanguageParam(request, "nl")); model.put("languageLinks", languageLinks); return new ModelAndView("access_confirmation", model); }
From source file:com.krawler.common.util.LocaleJsController.java
@Override protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception { OutputStream out = response.getOutputStream(); response.setContentType("text/javascript"); byte[] buffer = getContents(RequestContextUtils.getLocale(request)); out.write(buffer);/*www . j ava 2 s . co m*/ out.close(); return null; }
From source file:info.jtrac.util.ItemUtils.java
public static String getAsHtml(Item item, HttpServletRequest request, HttpServletResponse response) { Locale locale = RequestContextUtils.getLocale(request); MessageSource messageSource = RequestContextUtils.getWebApplicationContext(request); return getAsHtml(item, request, response, messageSource, locale); }
From source file:org.bpmscript.web.view.JavascriptView.java
/** * @see org.springframework.web.servlet.view.AbstractView#renderMergedOutputModel(java.util.Map, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse) *//* www . j av a 2 s . c om*/ @SuppressWarnings("unchecked") @Override protected void renderMergedTemplateModel(Map model, HttpServletRequest request, HttpServletResponse response) throws Exception { Locale locale = RequestContextUtils.getLocale(request); Context cx = new ContextFactory().enterContext(); try { // create scripting environment (i.e. load everything) ScriptableObject scope = new Global(cx); cx.putThreadLocal(Global.LIBRARY_ASSOCIATION_QUEUE, libraryAssociationQueue); ScriptableObject.putProperty(scope, "log", Context.javaToJS(log, scope)); ScriptableObject.putProperty(scope, "request", Context.javaToJS(request, scope)); ScriptableObject.putProperty(scope, "response", Context.javaToJS(response, scope)); ScriptableObject.putProperty(scope, "base", Context.javaToJS(request.getContextPath(), scope)); ScriptableObject.putProperty(scope, "locale", Context.javaToJS(locale, scope)); Set<Map.Entry> entrySet = model.entrySet(); for (Map.Entry<String, Object> entry : entrySet) { ScriptableObject.putProperty(scope, entry.getKey(), mapToJsConverter.convertObject(scope, entry.getValue())); } Stack<String> sourceStack = new Stack<String>(); sourceStack.push(configResource); cx.putThreadLocal(Global.SOURCE_STACK, sourceStack); if (libraryAssociationQueue != null) { cx.putThreadLocal(Global.LIBRARY_ASSOCIATION_QUEUE, libraryAssociationQueue); } Script configScript = javascriptSourceCache.getScript( new String(StreamUtils .getBytes(getApplicationContext().getResource(configResource).getInputStream())), configResource); configScript.exec(cx, scope); sourceStack.pop(); sourceStack.push(getUrl()); Script script = javascriptSourceCache.getScript( new String( StreamUtils.getBytes(getApplicationContext().getResource(getUrl()).getInputStream())), getUrl()); Object result = script.exec(cx, scope); response.getWriter().write(result.toString()); // not sure if this is necessary response.getWriter().flush(); } finally { Context.exit(); } }
From source file:com.jaspersoft.jasperserver.war.tags.FormatDateTag.java
public int doStartTag() throws JspException { HttpServletRequest request = (HttpServletRequest) pageContext.getRequest(); WebApplicationContext applicationContext = RequestContextUtils.getWebApplicationContext(request); Locale locale = RequestContextUtils.getLocale(request); TimeZone timezone = JasperServerUtil.getTimezone(request); String formattingPattern = getFormattingPattern(applicationContext, locale); SimpleDateFormat format = new SimpleDateFormat(formattingPattern, locale); format.setTimeZone(timezone);/*www .j av a 2 s . c om*/ String formattedValue = format.format(getValue()); try { //TODO html escaping? pageContext.getOut().write(formattedValue); } catch (IOException e) { log.error(e); throw new JspException(e); } return SKIP_BODY; }
From source file:com.mitchellbosecke.pebble.spring.PebbleView.java
@Override protected void renderMergedTemplateModel(Map<String, Object> model, HttpServletRequest request, HttpServletResponse response) throws Exception { response.setCharacterEncoding(this.characterEncoding); long startNanos = System.nanoTime(); PebbleTemplate template = this.engine.getTemplate(this.templateName); // Add beans context model.put(BEANS_VARIABLE_NAME, new Beans(this.getApplicationContext())); // Add request & response model.put(REQUEST_VARIABLE_NAME, request); model.put(RESPONSE_VARIABLE_NAME, response); // Add session model.put(SESSION_VARIABLE_NAME, request.getSession(false)); // Locale/*from w ww .j a v a2s . c o m*/ Locale locale = RequestContextUtils.getLocale(request); final Writer writer = response.getWriter(); try { template.evaluate(writer, model, locale); } finally { writer.flush(); } if (TIMER_LOGGER.isDebugEnabled()) { long endNanos = System.nanoTime(); BigDecimal elapsed = BigDecimal.valueOf(endNanos - startNanos); BigDecimal elapsedMs = elapsed.divide(BigDecimal.valueOf(NANOS_IN_SECOND), RoundingMode.HALF_UP); TIMER_LOGGER.debug("Pebble template \"{}\" with locale {} processed in {} nanoseconds (approx. {}ms)", new Object[] { this.templateName, locale, elapsed, elapsedMs }); } }