Example usage for org.springframework.web.servlet.support RequestContextUtils getLocale

List of usage examples for org.springframework.web.servlet.support RequestContextUtils getLocale

Introduction

In this page you can find the example usage for org.springframework.web.servlet.support RequestContextUtils getLocale.

Prototype

public static Locale getLocale(HttpServletRequest request) 

Source Link

Document

Retrieve the current locale from the given request, using the LocaleResolver bound to the request by the DispatcherServlet (if available), falling back to the request's accept-header Locale.

Usage

From source file:alfio.util.TemplateManager.java

public String renderServletContextResource(String servletContextResource, Map<String, Object> model,
        HttpServletRequest request, TemplateOutput templateOutput) {
    model.put("request", request);
    model.put(WebSecurityConfig.CSRF_PARAM_NAME, request.getAttribute(CsrfToken.class.getName()));
    return render(new ServletContextResource(request.getServletContext(), servletContextResource), model,
            RequestContextUtils.getLocale(request), templateOutput);
}

From source file:cz.zcu.kiv.eegdatabase.logic.controller.root.RegistrationController.java

@Override
protected ModelAndView onSubmit(HttpServletRequest request, HttpServletResponse response, Object command,
        BindException bindException) throws Exception {
    RegistrationCommand rc = (RegistrationCommand) command;

    Person person = personService.createPerson(rc);

    try {//  w  ww  .  ja  v  a 2 s  .com
        mailService.sendRegistrationConfirmMail(person, RequestContextUtils.getLocale(request));
    } catch (MailException e) {
        log.error("E-mail was NOT sent");
        log.error(e);
        e.printStackTrace();
    }

    log.debug("Returning MAV");
    ModelAndView mav = new ModelAndView(getSuccessView());
    mav.addObject("personEmail", person.getEmail());
    return mav;
}

From source file:gallery.web.controller.pages.PagesController.java

@Override
public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception {
    String lang = RequestContextUtils.getLocale(request).getLanguage();
    //getting current page
    Pages page = getCurPage(request);//from  w  w  w  .ja v  a2  s .  c o m

    request.setAttribute(Config.CURRENT_PAGE_ATTRIBUTE, page);

    //getting its type
    UrlBean url = null;

    if (page != null) {
        request.setAttribute(config.getSiteConfigAttribute(), siteConfigService.getInstance());
        //getting navigation
        List<Pages> navigation = pagesService.getAllPagesParents(page.getId(), Config.NAVIGATION_PSEUDONYMES);
        request.setAttribute(config.getNavigationDataAttribute(), navigation);

        url = getType(page).execute(request, response);

        //if url == null that meens that we do not need to render any view in this method
        // and thus we do not need to load any submodules, rubrications etc
        if (url != null) {
            makeReplacement(page, lang);

            loadSubmodules(navigation, request, url.getSubmodules());

            createRubrication(request, page);

            request.setAttribute(COUNTERS_ATTRIBUTE, pagesViewService.getCounters());
            request.setAttribute(ADVERTISEMENT_ATTRIBUTE,
                    pagesViewService.getAdvertisementForPage(page.getId()));
        }
    }
    if (url == null) {
        return null;
    } else {
        saveUrlBean(request, url);
        return new ModelAndView(config.getTemplateUrl());
    }
}

From source file:com.krawler.spring.importFunctionality.ImportController.java

public ModelAndView getColumnConfig(HttpServletRequest request, HttpServletResponse response) {
    JSONObject jobj = new JSONObject();
    boolean issuccess = false;
    String msg = "";
    try {/*from  w  w w.  j  a v a 2 s. c o m*/
        String moduleName = request.getParameter("module");

        String ModuleId = null;
        String companyId = sessionHandlerImpl.getCompanyid(request);
        try {
            List list = importDao.getModuleObject(moduleName);
            Modules module = (Modules) list.get(0); //Will throw null pointer if no module entry found
            ModuleId = module.getId();
        } catch (Exception ex) {
            throw new DataInvalidateException(
                    "Column config entries are not available for " + moduleName + " module.");
        }
        JSONObject job = null;
        JSONArray DataJArr = ImportUtil.getModuleColumnConfig1(ModuleId, companyId, fieldManagerDAOobj,
                moduleName, false);
        for (int k = 0; k < DataJArr.length(); k++) {
            job = DataJArr.getJSONObject(k);
            if (job.has("columnName") && job.has("localekey")
                    && !StringUtil.isNullOrEmpty(job.getString("localekey"))) {
                job.put("columnName", mSource.getMessage(job.getString("localekey"), null,
                        RequestContextUtils.getLocale(request)));
                DataJArr.put(k, job);
            }
        }
        jobj.put("data", DataJArr);
        jobj.put("count", DataJArr.length());
        issuccess = true;
    } catch (Exception ex) {
        msg = "" + ex.getMessage();
        Logger.getLogger(ImportController.class.getName()).log(Level.SEVERE, null, ex);
    } finally {
        try {
            jobj.put("success", issuccess);
            jobj.put("msg", msg);
        } catch (JSONException ex) {
            Logger.getLogger(ImportController.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
    return new ModelAndView("jsonView", "model", jobj.toString());
}

From source file:cz.zcu.kiv.eegdatabase.logic.controller.list.weather.AddWeatherController.java

@RequestMapping(value = "lists/weather-definitions/add.html", method = RequestMethod.GET)
protected String showAddForm(@RequestParam("groupid") String idString, ModelMap model,
        HttpServletRequest request) throws Exception {
    AddWeatherCommand data = new AddWeatherCommand();
    if (auth.userIsExperimenter() || auth.isAdmin()) {
        if (idString != null) {
            int id = Integer.parseInt(idString);
            data.setResearchGroupId(id);
            if (id != DEFAULT_ID) {
                String title = researchGroupDao.getResearchGroupTitle(id);
                data.setResearchGroupTitle(title);
            } else {
                String defaultWeather = messageSource.getMessage("label.defaultWeather", null,
                        RequestContextUtils.getLocale(request));
                data.setResearchGroupTitle(defaultWeather);
            }/*from   ww w  . j  a v a2s  .  c  o  m*/
        }
        model.addAttribute("userIsExperimenter", auth.userIsExperimenter());
        model.addAttribute("addWeather", data);
        return "lists/weather/addItemForm";
    } else {
        return "lists/userNotExperimenter";
    }
}

From source file:cz.zcu.kiv.eegdatabase.logic.controller.list.hardware.HardwareMultiController.java

@RequestMapping(value = "lists/hardware-definitions/list.html", method = RequestMethod.POST)
public String onSubmit(@ModelAttribute("selectGroupCommand") SelectGroupCommand selectGroupCommand,
        ModelMap model, HttpServletRequest request) {
    String defaultHardware = messageSource.getMessage("label.defaultHardware", null,
            RequestContextUtils.getLocale(request));
    fillAuthResearchGroupList(defaultHardware);
    if (!researchGroupList.isEmpty()) {
        fillHardwareList(selectGroupCommand.getResearchGroupId());
    }// w  w  w .j  a va2  s.  c om
    boolean canEdit = auth.isAdmin() || auth.userIsExperimenter();
    model.addAttribute("userIsExperimenter", canEdit);
    model.addAttribute("researchGroupList", researchGroupList);
    model.addAttribute("hardwareList", hardwareList);
    return "lists/hardware/list";
}

From source file:cz.zcu.kiv.eegdatabase.logic.controller.list.hardware.AddHardwareController.java

@RequestMapping(value = "lists/hardware-definitions/add.html", method = RequestMethod.GET)
protected String showAddForm(@RequestParam("groupid") String idString, ModelMap model,
        HttpServletRequest request) throws Exception {
    AddHardwareCommand data = new AddHardwareCommand();
    if (auth.userIsExperimenter() || auth.isAdmin()) {
        if (idString != null) {
            int id = Integer.parseInt(idString);
            data.setResearchGroupId(id);
            if (id != DEFAULT_ID) {
                String title = researchGroupDao.getResearchGroupTitle(id);
                data.setResearchGroupTitle(title);
            } else {
                String defaultHardware = messageSource.getMessage("label.defaultHardware", null,
                        RequestContextUtils.getLocale(request));
                data.setResearchGroupTitle(defaultHardware);
            }// w  w  w  .  jav  a2 s  . c o m
        }
        model.addAttribute("userIsExperimenter", auth.userIsExperimenter());
        model.addAttribute("addHardware", data);
        return "lists/hardware/addItemForm";
    } else {
        return "lists/userNotExperimenter";
    }
}

From source file:com.vh.ds.iam.web.front.jxl.AbstractJxlView.java

/**
 * Create the workbook from an existing XLS document.
 * @param url the URL of the Excel template without localization part nor extension
 * @param request current HTTP request/*from   w ww .  j  av a 2  s.c o m*/
 * @return the template workbook
 * @throws Exception in case of failure
 */
protected Workbook getTemplateSource(String url, HttpServletRequest request) throws Exception {
    LocalizedResourceHelper helper = new LocalizedResourceHelper(getApplicationContext());
    Locale userLocale = RequestContextUtils.getLocale(request);
    Resource inputFile = helper.findLocalizedResource(url, EXTENSION, userLocale);

    // Create the Excel document from the source.
    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug("Loading Excel workbook from {}", inputFile);
    }
    return Workbook.getWorkbook(inputFile.getInputStream());
}

From source file:cz.zcu.kiv.eegdatabase.logic.controller.list.personoptparamdef.PersonOptParamDefMultiController.java

@RequestMapping(value = "lists/person-optional-parameters/list.html", method = RequestMethod.POST)
public String onSubmit(@ModelAttribute("selectGroupCommand") SelectGroupCommand selectGroupCommand,
        ModelMap model, HttpServletRequest request) {
    String defaultPersonOptParamDef = messageSource.getMessage("label.defaultPersonOptParamDef", null,
            RequestContextUtils.getLocale(request));
    fillAuthResearchGroupList(defaultPersonOptParamDef);
    if (!researchGroupList.isEmpty()) {
        fillPersonOptParamDefList(selectGroupCommand.getResearchGroupId());
    }//  w ww. j a v a2 s  .  co m
    boolean canEdit = auth.isAdmin() || auth.userIsExperimenter();
    model.addAttribute("userIsExperimenter", canEdit);
    model.addAttribute("researchGroupList", researchGroupList);
    model.addAttribute("personOptParamDefList", personOptParamDefList);
    return "lists/personAdditionalParams/list";
}