Example usage for javax.servlet.http HttpServletRequest getLocale

List of usage examples for javax.servlet.http HttpServletRequest getLocale

Introduction

In this page you can find the example usage for javax.servlet.http HttpServletRequest getLocale.

Prototype

public Locale getLocale();

Source Link

Document

Returns the preferred Locale that the client will accept content in, based on the Accept-Language header.

Usage

From source file:fr.paris.lutece.plugins.federatedatabasefranceconnect.web.FederateFranceConnectApp.java

@View(value = VIEW_REMOVE_FEDERATION)
public XPage getRemoveFederationPage(HttpServletRequest request) {
    Map<String, Object> model = getModel();

    return getXPage(TEMPLATE_REMOVE_FEDERATE_LINK_FORM, request.getLocale(), model);
}

From source file:alpha.portal.webapp.controller.ContributorRoleController.java

/**
 * Save edited role.//from   ww w  .  j  a v a 2  s . c  o  m
 * 
 * @param request
 *            the request
 * @param response
 *            the response
 * @return the string
 */
@RequestMapping(method = RequestMethod.POST, params = { "save_edit" })
public String saveEdit(final HttpServletRequest request, final HttpServletResponse response) {

    final Locale locale = request.getLocale();
    String urlAppend = "";

    final String newRoleName = request.getParameter("newContributorRole");

    final String oldRoleIdStr = request.getParameter("oldContribRoleId");
    Long oldRoleId = null;
    try {
        oldRoleId = Long.parseLong(oldRoleIdStr);
    } catch (final NumberFormatException e) {
    }

    if (StringUtils.isEmpty(newRoleName) || StringUtils.isEmpty(oldRoleIdStr)) {

        this.saveError(request, this.getText("contributorRoles.edit_err_empty", locale));

        if (oldRoleIdStr != null) {
            urlAppend = "edit=" + oldRoleIdStr;
        }

    } else if (this.contributorRoleManager.getContributorRoleByName(newRoleName) != null) {

        this.saveError(request, this.getText("contributorRoles.edit_err_exists", locale));

        urlAppend = "edit=" + oldRoleIdStr;

    } else if ((oldRoleId != null) && !this.contributorRoleManager.exists(oldRoleId)) {
        this.saveError(request, this.getText("contributorRoles.edit_err_notexists", locale));

    } else {
        final ContributorRole editedRole = this.contributorRoleManager.get(oldRoleId);
        editedRole.setName(newRoleName);
        this.contributorRoleManager.save(editedRole);

        this.saveMessage(request, this.getText("contributorRoles.edit_success", locale));

    }

    return "redirect:/contributorRole?" + urlAppend;
}

From source file:org.jamwiki.servlets.StylesheetServlet.java

/**
 *
 *//* ww  w . j  a va2 s  . c  o  m*/
public ModelAndView handleJAMWikiRequest(HttpServletRequest request, HttpServletResponse response,
        ModelAndView next, WikiPageInfo pageInfo) throws Exception {
    String virtualWiki = pageInfo.getVirtualWikiName();
    String stylesheet = ServletUtil.cachedContent(request.getContextPath(), request.getLocale(), virtualWiki,
            WikiBase.SPECIAL_PAGE_SYSTEM_CSS, false);
    stylesheet += '\n' + ServletUtil.cachedContent(request.getContextPath(), request.getLocale(), virtualWiki,
            WikiBase.SPECIAL_PAGE_CUSTOM_CSS, false);
    response.setContentType("text/css");
    response.setCharacterEncoding("UTF-8");
    // cache for 30 minutes (60 * 30 = 1800)
    // FIXME - make configurable
    response.setHeader("Cache-Control", "max-age=1800");
    PrintWriter out = response.getWriter();
    out.print(stylesheet);
    out.close();
    // do not load defaults or redirect - return as raw CSS
    return null;
}

From source file:com.skymobi.monitor.action.ProjectAction.java

private void fixAlias(Project project, HttpServletRequest request) {
    if (project.getName().equalsIgnoreCase("flash_dog")) {
        String message = messageBundle.getMessage("app.title", null, request.getLocale());
        project.setAlias(message);/*from www .  java  2s.  co  m*/

    }
}

From source file:fr.paris.lutece.plugins.stock.modules.billetterie.web.AbstractXPageApp.java

/**
 * Return localized message./*from w w w  .  ja  va2  s.  co m*/
 *
 * @param key i18n key
 * @param request the request
 * @return localized message
 */
protected String getMessage(String key, HttpServletRequest request) {
    return I18nService.getLocalizedString(key, request.getLocale());
}

From source file:es.pode.administracion.presentacion.monitorizarnodos.monitorizar.MonitorizarNodosControllerImpl.java

/**
 * @see es.pode.administracion.presentacion.monitorizarnodos.monitorizar.MonitorizarNodosController#estadoNodos(org.apache.struts.action.ActionMapping, es.pode.administracion.presentacion.monitorizarnodos.monitorizar.EstadoNodosForm, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
 *///w  w  w  .  j  a  v  a2  s .  c o  m
public final void estadoNodos(ActionMapping mapping,
        es.pode.administracion.presentacion.monitorizarnodos.monitorizar.EstadoNodosForm form,
        HttpServletRequest request, HttpServletResponse response) throws Exception {

    try {

        SrvMonitorizarService service = this.getSrvMonitorizarService();
        EstadoNodoVO[] estados = service.obtenerEstadoNodos();
        prepararInformacion(estados, request.getLocale());
        form.setEstadosAsArray(estados);
    } catch (Exception e) {
        log.error("Se ha producido un error al monitorizar los nodos: " + e);
        throw new ValidatorException("{errors.monitorizarnodos}");
    }

}

From source file:de.iew.web.controllers.TreeController.java

public DomainModelVisitor<Node, NodeModel> getNodeTransformer(HttpServletRequest request) {
    LocaleStringResolver localeStringResolver = new LocaleStringResolver();
    localeStringResolver.setLocale(request.getLocale());

    NodeToNodelModelTransformer nodeToNodelVisitorVisitor = new NodeToNodelModelTransformer();
    nodeToNodelVisitorVisitor.setStringResolver(localeStringResolver);
    return nodeToNodelVisitorVisitor;
}

From source file:de.otto.mongodb.profiler.web.I18nInterceptor.java

@Override
public void postHandle(final HttpServletRequest request, final HttpServletResponse response,
        final Object handler, final ModelAndView modelAndView) throws Exception {

    if (modelAndView == null) {
        return;/*from ww  w  .java2s.  c  o m*/
    }

    final Locale locale = request.getLocale();
    final ResourceBundle bundle = ResourceBundle.getBundle(baseName, locale);
    final ForgivingResourceBundleModel bundleModel = new ForgivingResourceBundleModel(bundle,
            BeansWrapper.getDefaultInstance());

    modelAndView.addObject(modelName, bundleModel);
}

From source file:dtu.ds.warnme.ws.rest.json.AbstractRestWS.java

@ExceptionHandler(Exception.class)
@ResponseBody//  w  w w  .  ja v a 2  s  .  c o  m
String handleOtherExceptions(Exception ex, HttpServletRequest request, HttpServletResponse response) {
    log.error("Internal server error!", ex);
    response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
    String responseBody = getMessage(ex, "exceptions.internalServerError", request.getLocale());
    RestUtils.decorateResponseHeaderWithMD5(response, responseBody);
    RestUtils.decorateResponseHeaderForJsonContentType(response);
    return responseBody;
}

From source file:com.webapp.controller.SampleController.java

/**
 * This shows how to create a simple MVC endpoint.
 * @param m/*  w w w  . j  a v  a2s.  c  om*/
 * @return
 */
@RequestMapping("home")
public String loadHomePage(HttpServletRequest request, final HttpServletResponse response, Model model) {
    response.setHeader("Cache-Control", "max-age=0, no-cache, no-store");

    // Get the title of the application in the request's locale
    model.addAttribute("title", webapp.getMessage("webapp.subtitle", null, request.getLocale()));

    return "home";
}