List of usage examples for org.springframework.web.servlet.support RequestContextUtils getLocale
public static Locale getLocale(HttpServletRequest request)
From source file:cz.zcu.kiv.eegdatabase.logic.controller.group.BookingRoomController.java
@Override public ModelAndView onSubmit(HttpServletRequest request, HttpServletResponse response, Object comm, BindException bindException) throws Exception { try {//w w w . j a v a2 s.c o m BookRoomCommand command = (BookRoomCommand) comm; status = messageSource.getMessage("bookRoom.controllerMessages.status.fail", null, RequestContextUtils.getLocale(request)); comment = messageSource.getMessage("bookRoom.controllerMessages.comment.error.unknown", null, RequestContextUtils.getLocale(request)); Person user = personDao.getLoggedPerson(); int group = command.getSelectedGroup(); int repType = command.getRepType(); int repCount = command.getRepCount(); String startStr = BookingRoomUtils.getHoursAndMinutes(command.getStartTimeCal()); String endStr = BookingRoomUtils.getHoursAndMinutes(command.getEndTimeCal()); Reservation res = new Reservation(); Timestamp createTime = new Timestamp(new GregorianCalendar().getTimeInMillis()); res.setCreationTime(createTime); res.setStartTime(command.getStartTimeTimestamp()); res.setEndTime(command.getEndTimeTimestamp()); res.setPerson(user); //searching for ResearchGroup ResearchGroup grp = getResearchGroup(group); res.setResearchGroup(grp); log.debug("Reservation has been created: " + ((res == null) ? "false" : "true")); reservationDao.create(res); if (repCount > 0) { comment = messageSource.getMessage("bookRoom.controllerMessages.comment.booked.multiple.part1", null, RequestContextUtils.getLocale(request)); comment += command.getDate() + ", from " + startStr + " to " + endStr + "<br>\n"; GregorianCalendar nextS = command.getStartTimeCal(); GregorianCalendar nextE = command.getEndTimeCal(); for (int i = 0; i < repCount; i++) { //shift of dates int add = BookingRoomUtils.getWeeksAddCount(repType, i); nextS.add(Calendar.WEEK_OF_YEAR, add); nextE.add(Calendar.WEEK_OF_YEAR, add); Reservation newReservation = new Reservation(); newReservation.setCreationTime(createTime); newReservation.setStartTime(new Timestamp(nextS.getTimeInMillis())); newReservation.setEndTime(new Timestamp(nextE.getTimeInMillis())); newReservation.setPerson(user); newReservation.setResearchGroup(grp); reservationDao.create(newReservation); comment += BookingRoomUtils.getDate(nextS) + ", from " + BookingRoomUtils.getHoursAndMinutes(nextS) + " to " + BookingRoomUtils.getHoursAndMinutes(nextE) + "<br>\n"; } comment += String.format( messageSource.getMessage("bookRoom.controllerMessages.comment.booked.multiple.part2", null, RequestContextUtils.getLocale(request)), repCount + 1);//+1 because we need count "original" reservation! } else { comment = String .format(messageSource.getMessage("bookRoom.controllerMessages.comment.booked.single", null, RequestContextUtils.getLocale(request)), command.getDate(), startStr, endStr); } status = messageSource.getMessage("bookRoom.controllerMessages.status.ok", null, RequestContextUtils.getLocale(request)); } catch (Exception e) { log.error("Exception: " + e.getMessage() + "\n" + e.getStackTrace()[0].getFileName() + " at line " + e.getStackTrace()[0].getLineNumber(), e); status = messageSource.getMessage("bookRoom.controllerMessages.status.fail", null, RequestContextUtils.getLocale(request)); comment = messageSource.getMessage("bookRoom.controllerMessages.comment.error.exception", null, RequestContextUtils.getLocale(request)) + " " + e.getMessage(); } log.debug("Returning MAV" + " with status=" + status + "&comment=" + comment); ModelAndView mav = new ModelAndView(getSuccessView()/* + "?status=" + status + "&comment=" + comment*/); return mav; }
From source file:cz.zcu.kiv.eegdatabase.logic.controller.list.hardware.HardwareMultiController.java
@RequestMapping(value = "lists/hardware-definitions/list.html", method = RequestMethod.GET) public String showSelectForm(WebRequest webRequest, ModelMap model, HttpServletRequest request) { log.debug("Processing hardware list controller"); SelectGroupCommand selectGroupCommand = new SelectGroupCommand(); String defaultHardware = messageSource.getMessage("label.defaultHardware", null, RequestContextUtils.getLocale(request)); fillAuthResearchGroupList(defaultHardware); String idString = webRequest.getParameter("groupid"); if (auth.isAdmin()) { if (idString != null) { int id = Integer.parseInt(idString); if (id != DEFAULT_ID) { fillHardwareList(id);//from w w w .j a v a 2s . c o m selectGroupCommand.setResearchGroupId(id); } else { fillHardwareList(DEFAULT_ID); selectGroupCommand.setResearchGroupId(DEFAULT_ID); } } else { fillHardwareList(DEFAULT_ID); selectGroupCommand.setResearchGroupId(DEFAULT_ID); } model.addAttribute("userIsExperimenter", true); } else { if (!researchGroupList.isEmpty()) { if (idString != null) { int id = Integer.parseInt(idString); fillHardwareList(id); selectGroupCommand.setResearchGroupId(id); } else { int myGroup = researchGroupList.get(0).getResearchGroupId(); fillHardwareList(myGroup); selectGroupCommand.setResearchGroupId(myGroup); } model.addAttribute("userIsExperimenter", auth.userIsExperimenter()); } else { model.addAttribute("userIsExperimenter", false); } } model.addAttribute("selectGroupCommand", selectGroupCommand); model.addAttribute("hardwareList", hardwareList); model.addAttribute("researchGroupList", researchGroupList); return "lists/hardware/list"; }
From source file:com.asual.summer.core.view.HtmlView.java
protected void renderMergedOutputModel(Map<String, Object> model, HttpServletRequest request, HttpServletResponse response) throws Exception { if (lifecycleFactory == null) { lifecycleFactory = (LifecycleFactory) FactoryFinder.getFactory(FactoryFinder.LIFECYCLE_FACTORY); }/*from w w w.ja v a2s .co m*/ FacesContextFactory facesContextFactory = (FacesContextFactory) FactoryFinder .getFactory(FactoryFinder.FACES_CONTEXT_FACTORY); FacesContext facesContext = facesContextFactory.getFacesContext(RequestUtils.getServletContext(), request, response, lifecycleFactory.getLifecycle(LifecycleFactory.DEFAULT_LIFECYCLE)); facesContext.setCurrentPhaseId(PhaseId.RESTORE_VIEW); facesContext.getExternalContext().getFlash().doPrePhaseActions(facesContext); Map<String, Object> requestMap = facesContext.getExternalContext().getRequestMap(); Iterator<String> i = model.keySet().iterator(); while (i.hasNext()) { String key = i.next().toString(); if (!requestMap.containsKey(key)) { requestMap.put(key, model.get(key)); } } ViewHandler viewHandler = facesContext.getApplication().getViewHandler(); viewHandler.initView(facesContext); UIViewRoot viewRoot = viewHandler.createView(facesContext, getUrl()); viewRoot.setLocale(RequestContextUtils.getLocale(request)); viewRoot.setTransient(true); facesContext.setCurrentPhaseId(PhaseId.RENDER_RESPONSE); facesContext.setViewRoot(viewRoot); facesContext.renderResponse(); try { facesContext.getApplication().getViewHandler().renderView(facesContext, viewRoot); } catch (IOException e) { throw new FacesException("An I/O error occurred during view rendering", e); } finally { facesContext.responseComplete(); facesContext.release(); } }
From source file:nl.surfnet.coin.api.controller.Oauth1AccessConfirmationController.java
@RequestMapping("/oauth1/confirm_access") public ModelAndView getAccessConfirmation(HttpServletRequest request, HttpServletResponse response) throws Exception { String token = request.getParameter("oauth_token"); if (token == null) { throw new IllegalArgumentException("A request token to authorize must be provided."); }//from ww w. j a va 2s . co m OAuthProviderToken providerToken = tokenServices.getToken(token); ConsumerDetails client = clientDetailsService.loadConsumerByConsumerKey(providerToken.getConsumerKey()); String callback = request.getParameter("oauth_callback"); TreeMap<String, Object> model = new TreeMap<String, Object>(); model.put("oauth_token", token); if (callback != null) { model.put("oauth_callback", callback); } 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); if (client instanceof OpenConextConsumerDetails) { ClientMetaData clientMetaData = ((OpenConextConsumerDetails) client).getClientMetaData(); if (!clientMetaData.isConsentRequired()) { /* * We skip the consent screen, but to ensure that we hit all the filters and keep * the user flow intact we have implemented this using a javascript POST */ return new ModelAndView("access_confirmation_oauth1_skip_consent", model); } } return new ModelAndView("access_confirmation_oauth1", model); }
From source file:org.mifos.ui.client.controller.CreateClientController.java
protected void initBinder(HttpServletRequest request, ServletRequestDataBinder binder) throws ServletException { Locale locale = RequestContextUtils.getLocale(request); localDateEditor = new LocalDateEditor(locale); binder.registerCustomEditor(LocalDate.class, localDateEditor); }
From source file:cz.zcu.kiv.eegdatabase.logic.controller.list.personoptparamdef.PersonOptParamDefMultiController.java
@RequestMapping(value = "lists/person-optional-parameters/list.html", method = RequestMethod.GET) public String showSelectForm(WebRequest webRequest, ModelMap model, HttpServletRequest request) { log.debug("Processing personOptParamDef list controller"); SelectGroupCommand selectGroupCommand = new SelectGroupCommand(); String defaultPersonOptParamDef = messageSource.getMessage("label.defaultPersonOptParamDef", null, RequestContextUtils.getLocale(request)); fillAuthResearchGroupList(defaultPersonOptParamDef); String idString = webRequest.getParameter("groupid"); if (auth.isAdmin()) { if (idString != null) { int id = Integer.parseInt(idString); if (id != DEFAULT_ID) { fillPersonOptParamDefList(id); selectGroupCommand.setResearchGroupId(id); } else { fillPersonOptParamDefList(DEFAULT_ID); selectGroupCommand.setResearchGroupId(DEFAULT_ID); }/*from ww w . j a v a 2 s .co m*/ } else { fillPersonOptParamDefList(DEFAULT_ID); selectGroupCommand.setResearchGroupId(DEFAULT_ID); } model.addAttribute("userIsExperimenter", true); } else { if (!researchGroupList.isEmpty()) { if (idString != null) { int id = Integer.parseInt(idString); fillPersonOptParamDefList(id); selectGroupCommand.setResearchGroupId(id); } else { int myGroup = researchGroupList.get(0).getResearchGroupId(); fillPersonOptParamDefList(myGroup); selectGroupCommand.setResearchGroupId(myGroup); } model.addAttribute("userIsExperimenter", auth.userIsExperimenter()); } else { model.addAttribute("userIsExperimenter", false); } } model.addAttribute("selectGroupCommand", selectGroupCommand); model.addAttribute("personOptParamDefList", personOptParamDefList); model.addAttribute("researchGroupList", researchGroupList); return "lists/personAdditionalParams/list"; }
From source file:cz.zcu.kiv.eegdatabase.logic.controller.list.filemetadata.FileMetadataParamDefMultiController.java
@RequestMapping(value = "lists/file-metadata-definitions/list.html", method = RequestMethod.GET) public String showSelectForm(WebRequest webRequest, ModelMap model, HttpServletRequest request) { log.debug("Processing fileMetadataParamDef list controller"); SelectGroupCommand selectGroupCommand = new SelectGroupCommand(); String defaultFileMetadataParamDef = messageSource.getMessage("label.defaultFileMetadataParamDef", null, RequestContextUtils.getLocale(request)); fillAuthResearchGroupList(defaultFileMetadataParamDef); String idString = webRequest.getParameter("groupid"); if (auth.isAdmin()) { if (idString != null) { int id = Integer.parseInt(idString); if (id != DEFAULT_ID) { fillFileMetadataParamDefList(id); selectGroupCommand.setResearchGroupId(id); } else { fillFileMetadataParamDefList(DEFAULT_ID); selectGroupCommand.setResearchGroupId(DEFAULT_ID); }/*from w ww . j a va2s . c o m*/ } else { fillFileMetadataParamDefList(DEFAULT_ID); selectGroupCommand.setResearchGroupId(DEFAULT_ID); } model.addAttribute("userIsExperimenter", true); } else { if (!researchGroupList.isEmpty()) { if (idString != null) { int id = Integer.parseInt(idString); fillFileMetadataParamDefList(id); selectGroupCommand.setResearchGroupId(id); } else { int myGroup = researchGroupList.get(0).getResearchGroupId(); fillFileMetadataParamDefList(myGroup); selectGroupCommand.setResearchGroupId(myGroup); } model.addAttribute("userIsExperimenter", auth.userIsExperimenter()); } else { model.addAttribute("userIsExperimenter", false); } } model.addAttribute("selectGroupCommand", selectGroupCommand); model.addAttribute("fileMetadataParamDefList", fileMetadataParamDefList); model.addAttribute("researchGroupList", researchGroupList); return "lists/fileMetadataParams/list"; }
From source file:cz.zcu.kiv.eegdatabase.webservices.rest.user.UserServiceController.java
/** * Method for creating new person/user with auto-generated password. * * @param request incoming http request/*from w w w. j a v a2 s . c o m*/ * @param person person information * @return basic user/person information * @throws RestServiceException */ @RequestMapping(value = "/create", method = RequestMethod.POST) @ResponseStatus(HttpStatus.CREATED) public PersonData create(HttpServletRequest request, @RequestBody PersonData person) throws RestServiceException { String url = "http://" + domain + "/registration-confirm?" + ConfirmPage.CONFIRM_ACTIVATION + "="; return service.create(url, person, RequestContextUtils.getLocale(request)); }
From source file:cz.zcu.kiv.eegdatabase.logic.controller.list.experimentoptparamdef.ExperimentOptParamDefMultiController.java
@RequestMapping(value = "lists/experiment-optional-parameters/list.html", method = RequestMethod.GET) public String showSelectForm(WebRequest webRequest, ModelMap model, HttpServletRequest request) { log.debug("Processing experimentOptParamDef list controller"); SelectGroupCommand selectGroupCommand = new SelectGroupCommand(); String defaultExperimentOptParamDef = messageSource.getMessage("label.defaultExperimentOptParamDef", null, RequestContextUtils.getLocale(request)); fillAuthResearchGroupList(defaultExperimentOptParamDef); String idString = webRequest.getParameter("groupid"); if (auth.isAdmin()) { if (idString != null) { int id = Integer.parseInt(idString); if (id != DEFAULT_ID) { fillExperimentOptParamDefList(id); selectGroupCommand.setResearchGroupId(id); } else { fillExperimentOptParamDefList(DEFAULT_ID); selectGroupCommand.setResearchGroupId(DEFAULT_ID); }/*from ww w . j a v a2s. c om*/ } else { fillExperimentOptParamDefList(DEFAULT_ID); selectGroupCommand.setResearchGroupId(DEFAULT_ID); } model.addAttribute("userIsExperimenter", true); } else { if (!researchGroupList.isEmpty()) { if (idString != null) { int id = Integer.parseInt(idString); fillExperimentOptParamDefList(id); selectGroupCommand.setResearchGroupId(id); } else { int myGroup = researchGroupList.get(0).getResearchGroupId(); fillExperimentOptParamDefList(myGroup); selectGroupCommand.setResearchGroupId(myGroup); } model.addAttribute("userIsExperimenter", auth.userIsExperimenter()); } else { model.addAttribute("userIsExperimenter", false); } } model.addAttribute("selectGroupCommand", selectGroupCommand); model.addAttribute("experimentOptParamDefList", experimentOptParamDefList); model.addAttribute("researchGroupList", researchGroupList); return "lists/measurationAdditionalParams/list"; }
From source file:org.terasoluna.gfw.web.codelist.CodeListInterceptor.java
/** * Sets codelist to the attribute of {@link HttpServletRequest} * <p>// w w w .ja v a 2 s . c o m * Sets codelist to the attribute of {@link HttpServletRequest} before the execution of Controller. * </p> * @see org.springframework.web.servlet.handler.HandlerInterceptorAdapter#preHandle(javax.servlet.http.HttpServletRequest, * javax.servlet.http.HttpServletResponse, java.lang.Object) * @since 5.0.1 */ @Override public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { if (codeLists == null) { return true; } Locale locale = RequestContextUtils.getLocale(request); logger.debug("locale for I18nCodelist is '{}'.", locale); for (CodeList codeList : codeLists) { String attributeName = codeList.getCodeListId(); if (codeList instanceof I18nCodeList) { I18nCodeList i18nCodeList = (I18nCodeList) codeList; Map<String, String> codeListMap = getLocalizedCodeMap(i18nCodeList, locale); request.setAttribute(attributeName, codeListMap); } else { request.setAttribute(attributeName, codeList.asMap()); } } return true; }