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:com.hp.avmon.config.web.AgentController.java

/**
 * "?"\"?"//  w  ww  .j a  v a  2s.com
 * @param response
 * @param request
 * @return
 */
@RequestMapping("updateVmMonitorStatus")
public String updateVmMonitorStatus(HttpServletResponse response, HttpServletRequest request) {
    String data = "";
    Locale locale = request.getLocale();
    ResourceBundle bundle = ResourceBundle.getBundle("messages", locale);
    String interfaceCallFail = bundle.getString("interfaceCallFail");
    try {
        String agentId = request.getParameter("agentId");
        String ampInstId = request.getParameter("ampInstId");
        String flag = request.getParameter("flag");
        String objIds = request.getParameter("objIds");
        agentManageService.updateVmMonitorStatus(agentId, ampInstId, flag, objIds);

        List<Map<String, String>> list = new ArrayList<Map<String, String>>();
        Map<String, String> instMap = new HashMap<String, String>();
        instMap.put("ampInstId", ampInstId);
        list.add(instMap);
        request.setAttribute("agentAmpInfo", list);
        logger.debug("==============request.setAttribute(\"agentAmpInfo\",list)=========="
                + request.getAttribute("agentAmpInfo"));

        agentManageService.pushAgentAmpConfig(request);

        if ("start".equalsIgnoreCase(flag)) {
            data = "{success:true,msg:'" + bundle.getString("startSuccess") + "'}";
        } else {
            data = "{success:true,msg:'" + bundle.getString("stopSuccess") + "'}";
        }

    } catch (Exception e) {
        logger.error(this.getClass().getName() + " updateVmMonitorStatus", e);
        if (e.toString().indexOf("license count error!") > -1) {
            data = "{success:false,msg:'" + bundle.getString("monitoringObjectHasReachedTheMaximumLimit")
                    + "'}";
        } else if (e.toString().indexOf(interfaceCallFail) > -1) {
            data = "{success:false,msg:'" + interfaceCallFail + "'}";
        } else {
            data = "{success:false,msg:'" + bundle.getString("operationFail") + "'}";
        }
        return Utils.responsePrintWrite(response, data, null);
    }

    return Utils.responsePrintWrite(response, data, null);
}

From source file:fr.paris.lutece.plugins.extend.modules.hit.web.component.HitResourceExtenderComponent.java

/**
 * {@inheritDoc}// ww w .jav a2  s . c o  m
 */
@Override
public String getPageAddOn(String strIdExtendableResource, String strExtendableResourceType,
        String strParameters, HttpServletRequest request) {
    Hit hit = _hitService.findByParameters(strIdExtendableResource, strExtendableResourceType);

    if (hit == null) {
        hit = new Hit();
        hit.setIdExtendableResource(strIdExtendableResource);
        hit.setExtendableResourceType(strExtendableResourceType);
        // By default, start hit at 0
        hit.setNbHits(0);
        _hitService.create(hit);
    }

    if (incrementInfo(strParameters)) {
        _hitService.incrementHit(hit);
    }

    // Add to the resource extender history
    _resourceHistoryService.create(HitResourceExtender.EXTENDER_TYPE, strIdExtendableResource,
            strExtendableResourceType, request);

    if (showInFO(strParameters)) {
        Map<String, Object> model = new HashMap<String, Object>();
        model.put(MARK_HIT, hit);

        HtmlTemplate template = AppTemplateService.getTemplate(TEMPLATE_HIT, request.getLocale(), model);

        return template.getHtml();
    }

    return StringUtils.EMPTY;
}

From source file:com.hp.avmon.config.web.AgentController.java

/**
 * ???AMP??/*  www.  j  av a 2  s.  c om*/
 * @param request
 * @param writer
 */
@RequestMapping(value = "/saveAgentAmp")
public void saveAgentAmp(HttpServletRequest request, PrintWriter writer) {
    String jsonData = "";
    Locale locale = request.getLocale();
    ResourceBundle bundle = ResourceBundle.getBundle("messages", locale);
    try {
        Map map = agentManageService.saveAgentAmp(request);
        jsonData = JackJson.fromObjectToJson(map);
    } catch (Exception e) {
        logger.error(this.getClass().getName() + "saveAgentAmp: " + e);
        if (e.toString().indexOf("ORA-00001") > -1) {
            jsonData = "{success:false,msg:'" + bundle.getString("ampInstanceExisted") + "'}";
        } else {
            jsonData = "{success:false,msg:'" + bundle.getString("systemException") + "'}";
        }
        writer.write(jsonData);
        writer.flush();
        writer.close();
    }
    writer.write(jsonData);
    writer.flush();
    writer.close();

}

From source file:de.iteratec.turm.servlets.TurmServlet.java

/**
 * Determines the current Locale, stores it in the session and returns it.
 * // www  .  j  a v  a  2 s  .c o m
 * It first checks, if a request parameter contains the current locale. This
 * means the user has selected a different locale. Otherwise, it tries to
 * retrieve the locale from the session. If that doesn't exist, the current
 * locale is taken from the request itself.
 * 
 * @param request The current Serlvet Request
 * @return The current Locale as set by the user, or as stored in the session.
 */
private Locale setAndStoreCurrentLocale(HttpServletRequest request) {
    HttpSession session = request.getSession();
    Locale currentLocaleToSet;
    if (request.getParameter(CURRENT_LOCALE_KEY) != null) {
        String parameterLocale = request.getParameter(CURRENT_LOCALE_KEY);
        if (parameterLocale.equals("de")) {
            currentLocaleToSet = Locale.GERMAN;
        } else {
            currentLocaleToSet = Locale.ENGLISH;
        }
        LOGGER.debug("Locale created from HTTP parameter: " + currentLocaleToSet);
    } else if (session.getAttribute(CURRENT_LOCALE_KEY) != null) {
        currentLocaleToSet = (Locale) session.getAttribute(CURRENT_LOCALE_KEY);
        LOGGER.debug("Locale loaded from session: " + currentLocaleToSet);
    } else {
        currentLocaleToSet = request.getLocale();
        if (currentLocaleToSet.getLanguage().toUpperCase().matches(".*DE.*")) {
            currentLocaleToSet = Locale.GERMAN;
        } else {
            currentLocaleToSet = Locale.ENGLISH;
        }
        LOGGER.debug(
                "Locale loaded from HTTP request header. Language is: " + currentLocaleToSet.getLanguage());
    }
    this.currentLocale = currentLocaleToSet;
    session.setAttribute(CURRENT_LOCALE_KEY, currentLocale);
    return currentLocale;
}

From source file:fr.paris.lutece.plugins.extend.modules.rating.web.type.VoteTypeJspBean.java

/**
 * Gets the modify vote type.// w ww  .ja  v a2  s .c  om
 *
 * @param request the request
 * @param response the response
 * @return the modify vote type
 * @throws AccessDeniedException the access denied exception
 */
public IPluginActionResult getModifyVoteType(HttpServletRequest request, HttpServletResponse response)
        throws AccessDeniedException {
    setPageTitleProperty(RatingConstants.PROPERTY_MANAGE_VOTE_TYPES_PAGE_TITLE);

    String strHtml = StringUtils.EMPTY;
    IPluginActionResult result = new DefaultPluginActionResult();
    String strIdVoteType = request.getParameter(RatingConstants.PARAMETER_ID_VOTE_TYPE);

    if (StringUtils.isNotBlank(strIdVoteType) && StringUtils.isNumeric(strIdVoteType)) {
        int nIdVoteType = Integer.parseInt(strIdVoteType);

        Map<String, Object> model = new HashMap<String, Object>();
        model.put(RatingConstants.MARK_VOTE_TYPE, _voteService.findByPrimaryKey(nIdVoteType, true));
        model.put(RatingConstants.MARK_WEBAPP_URL, AppPathService.getBaseUrl(request));
        model.put(RatingConstants.MARK_LOCALE, getLocale());

        HtmlTemplate template = AppTemplateService.getTemplate(TEMPLATE_MODIFY_VOTE_TYPE, request.getLocale(),
                model);
        strHtml = template.getHtml();
    }

    if (StringUtils.isNotBlank(strHtml)) {
        result.setHtmlContent(strHtml);
    } else {
        result.setRedirect(
                AdminMessageService.getMessageUrl(request, Messages.MANDATORY_FIELDS, AdminMessage.TYPE_STOP));
    }

    return result;
}

From source file:com.hp.avmon.config.web.AgentController.java

/**
 * ?amp ?grid?    //from  ww  w.  j a  v  a  2  s. com
 * @param request
 * @param writer
 * @throws Exception
 */
@RequestMapping(value = "saveAmpInstAttr")
public void saveAmpInstAttr(HttpServletRequest request, PrintWriter writer) throws Exception {
    String data = "";
    Locale locale = request.getLocale();
    ResourceBundle bundle = ResourceBundle.getBundle("messages", locale);
    try {
        String agentId = request.getParameter("agentId");
        String ampInstId = request.getParameter("ampInstId");
        String attrs = request.getParameter("attrs");
        agentManageService.saveAmpInstAttr(agentId, ampInstId, attrs);

        data = "{success:true,msg:'" + bundle.getString("saveSuccess") + "'}";

    } catch (Exception e) {
        logger.error(this.getClass().getName() + " saveAmpInstAttr", e);
    }
    String json = JackJson.fromObjectToJson(data);

    writer.write(json);
    writer.flush();
    writer.close();
}

From source file:org.opentides.web.controller.BaseCrudController.java

/**
 * This is the method handler that updates persisted data. The <code>command</code> object is
 * binded to the form with the name <code>formCommand</code> from the view. The  
 * data is loaded from the database through the path variable <code>id</code>. It returns
 * a map consisting of the command object and the success messages.
 * /*from w w  w .  j  a v  a  2 s  .c o m*/
 * @param command
 * @param id
 * @param bindingResult
 * @param uiModel
 * @param request
 * @param response
 * @return Map containing the following:<br />
 *          command - the command object<br />
 *          messages - list of {@link MessageResponse }
 */
@RequestMapping(value = "{id}", method = { RequestMethod.PUT,
        RequestMethod.POST }, produces = "application/json")
@ResponseView(Views.FormView.class)
public final @ResponseBody Map<String, Object> update(@FormBind(name = "formCommand") T command,
        @PathVariable("id") Long id, BindingResult bindingResult, Model uiModel, HttpServletRequest request,
        HttpServletResponse response) {
    Map<String, Object> model = new HashMap<String, Object>();
    List<MessageResponse> messages = new ArrayList<MessageResponse>();
    if (command.getId() == null)
        command.setId(id);
    updateTx(command, bindingResult, uiModel, request, response);
    messages.addAll(CrudUtil.buildSuccessMessage(command, "update", request.getLocale(), messageSource));
    model.put("command", command);
    model.put("messages", messages);
    return model;
}

From source file:org.opentides.web.controller.BaseCrudController.java

/**
 * This is the method handler that deletes persisted data. It
 * deletes the data with the path variable <code>id</code> from the database.
 * /*from www .j  a v  a  2 s.c o  m*/
 * @param id
 * @param command
 * @param bindingResult
 * @param uiModel
 * @param request
 * @param response
 * @return Map containing the following:<br />
 *          {@value} command - the command object<br />
 *          {@value} messages - list of MessageResponse
 */
@RequestMapping(value = "{id}", method = RequestMethod.DELETE, produces = "application/json")
public final @ResponseBody Map<String, Object> delete(@PathVariable("id") Long id, T command,
        BindingResult bindingResult, Model uiModel, HttpServletRequest request, HttpServletResponse response) {
    Map<String, Object> model = new HashMap<String, Object>();
    List<MessageResponse> messages = new ArrayList<MessageResponse>();
    if (id >= 0) {
        try {
            deleteTx(id, bindingResult, uiModel, request, response);
            messages.addAll(
                    CrudUtil.buildSuccessMessage(command, "delete", request.getLocale(), messageSource));
            model.put("messages", messages);
            return model;
        } catch (Exception e) {
            String message = "Failed to delete " + this.entityBeanType + " with id = [" + id + "]";
            _log.error(message, e);
            throw new DataAccessException(message, e);
        }
    } else {
        String message = "Invalid id = [" + id + "] for delete operation of " + this.entityBeanType;
        _log.error(message);
        throw new DataAccessException(message);
    }
}

From source file:org.squale.squaleweb.servlet.RestServlet.java

/**
 * Get method of http/*from   ww w.  ja  v  a2  s  . co  m*/
 * 
 * @param request The http servlet request
 * @param response The http servlet response
 */
public void doGet(HttpServletRequest request, HttpServletResponse response) {
    try {
        // Authentication of the user and retrieve of its informations
        UserDTO userDto = authent(request);
        // If the authentication failed then userDto has for id : -1L
        if (userDto == null) {
            // If the user authentication failed, then the servlet return a 403 error page
            String s = "Basic realm=\"Login Test Servlet Users\"";
            response.setHeader("WWW-Authenticate", s);
            response.setStatus(HttpStatus.SC_UNAUTHORIZED);
        } else {
            // Else the servlet execute the search
            String pathInfo = request.getPathInfo();
            MimeType type = returnType(request);
            Locale locale = request.getLocale();
            IRootObject dataToWrite = prepareResponse(pathInfo, userDto, locale);
            if (dataToWrite != null) {
                response.setCharacterEncoding("UTF-8");
                writeResponse(response, type, dataToWrite);
            } else {
                response.setStatus(HttpStatus.SC_NOT_IMPLEMENTED);
            }
        }
    } catch (JrafEnterpriseException e) {
        LOG.error("An error occurs during the rest execution", e);
        response.setStatus(HttpStatus.SC_INTERNAL_SERVER_ERROR);
    }
}

From source file:fr.paris.lutece.plugins.crm.web.CRMApp.java

/**
 * Get the modify crm account page/*from w w w .j  a  v  a2s .c om*/
 * @param request {@link HttpServletRequest}
 * @param user the {@link LuteceUser}
 * @return a {@link XPage}
 */
private XPage getModifyCRMUserPage(HttpServletRequest request, LuteceUser user) {
    XPage page = null;
    CRMUser crmUser = _crmUserService.findByUserGuid(user.getName());

    if (crmUser != null) {
        page = new XPage();

        Map<String, Object> model = new HashMap<String, Object>();
        model.put(CRMConstants.MARK_CRM_USER, crmUser);

        HtmlTemplate template = AppTemplateService.getTemplate(TEMPLATE_MODIFY_CRM_USER, request.getLocale(),
                model);

        page.setTitle(I18nService.getLocalizedString(CRMConstants.PROPERTY_VIEW_NOTIFICATION_PAGE_TITLE,
                request.getLocale()));
        page.setPathLabel(I18nService.getLocalizedString(CRMConstants.PROPERTY_PAGE_PATH, request.getLocale()));
        page.setContent(template.getHtml());
    }

    return page;
}