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:org.squale.squaleweb.applicationlayer.action.IndexAction.java

/**
 * This method do the action needed for display the news part in the homepage.jsp
 * /*from   w ww .j  a  v  a2  s.  c  om*/
 * @param mapping The mapping
 * @param form The form
 * @param request The http request
 * @param response The servlet response
 */
private void news(ActionMapping mapping, ActionForm form, HttpServletRequest request,
        HttpServletResponse response) {

    // Flag for the valid news
    request.setAttribute("which", "current");
    // Flag for the language
    request.setAttribute("lang", request.getLocale().getLanguage());

    // Recover the news list and set them in session
    AdminNewsAction newsAction = new AdminNewsAction();
    newsAction.listNews(mapping, form, request, response);
}

From source file:it.cilea.osd.jdyna.controller.DecoratorATypeNestedController.java

protected ModelAndView handleDelete(HttpServletRequest request) {
    Map<String, Object> model = new HashMap<String, Object>();
    String paramOTipologiaProprietaId = request.getParameter("pDId");
    String boxId = request.getParameter("boxId");
    String tabId = request.getParameter("tabId");
    Integer tipologiaProprietaId = Integer.decode(paramOTipologiaProprietaId);

    try {/*from   w w w .  j a v  a2s.  com*/

        A tip = applicationService.get(targetModel, tipologiaProprietaId);

        applicationService.deleteNestedObjectByTypeID(objectModel, tipologiaProprietaId);

        IContainable containable = applicationService.findContainableByDecorable(tip.getDecoratorClass(),
                tipologiaProprietaId);
        applicationService.<H, T>deleteContainableInPropertyHolder(holderModel, containable);
        applicationService.delete(tip.getDecoratorClass(), containable.getId());

        saveMessage(request, getText("action.propertiesdefinition.deleted", request.getLocale()));
    } catch (Exception ecc) {
        saveMessage(request, getText("action.propertiesdefinition.deleted.noSuccess", request.getLocale()));
    }

    return new ModelAndView(getListView() + "?id=" + boxId + "&tabId=" + tabId + "&path="
            + Utils.getAdminSpecificPath(request, null), model);
}

From source file:com.hp.avmon.kpigetconfig.web.KpigetconfigAgentController.java

/**
 * "?"\"?"/*from   w ww . ja  v a2  s. c o m*/
 * @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);
    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);
        if ("start".equalsIgnoreCase(flag)) {
            data = "{success:true,msg:'" + bundle.getString("startSuccess") + "'}";
        } else {
            data = "{success:true,msg:'" + bundle.getString("stopSuccess") + "'}";
        }

    } catch (Exception e) {
        e.printStackTrace();
        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("?!") > -1) {
            data = "{success:false,msg:'" + bundle.getString("interfaceCallFail") + "'}";
        } else {
            data = "{success:false,msg:'" + bundle.getString("operationFail") + "'}";
        }
        return Utils.responsePrintWrite(response, data, null);
    }

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

From source file:com.hp.avmon.kpigetconfig.web.KpigetconfigAgentController.java

/**
 * ?agentwindows// w ww  .  j ava 2 s  .  c om
 * (agent???)
 * @param response
 * @param request
 * @return
 */
@RequestMapping("addAgentMo")
public String addAgentMo(HttpServletResponse response, HttpServletRequest request) {
    String data = "";
    Locale locale = request.getLocale();
    ResourceBundle bundle = ResourceBundle.getBundle("messages", locale);
    try {
        String agentId = request.getParameter("agentId");
        String moId = request.getParameter("moId");
        String result = agentManageService.addAgentMo(moId, agentId);
        if (result.equalsIgnoreCase("99")) {
            result = bundle.getString("unknownError");
        }
        if (result.startsWith("00")) {
            //agent
            agentManageService.updateAgentMoId(agentId, moId);
            data = "{success:true,msg:'" + bundle.getString("operationSuccess") + "'}";
        } else if ("1".endsWith(result)) {
            data = "{success:false,msg:'" + bundle.getString("operationSuccess") + "'}";
        } else if (result.startsWith("03")) {
            //agent
            agentManageService.updateAgentMoId(agentId, moId);
            data = "{success:true,msg:'" + bundle.getString("operationSuccess") + "'}";
        } else {
            data = "{success:false,msg:'" + result + "'}";
        }
    } catch (Exception e) {
        e.printStackTrace();
        logger.error(this.getClass().getName() + " addAgentMo", e);
        String s = e.getMessage();
        s = s.replaceAll("'", "");
        data = "{success:false,msg:'" + bundle.getString("agentAddMonitorObjectFail") + "'}";
    }

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

From source file:es.pode.gestorFlujo.presentacion.objetosPersonales.importar.ImportarControllerImpl.java

/**
 * @param form/*from www .  ja  v  a 2 s . c  om*/
 * @param request
 * @param estadoActual
 * @param formFile
 * @param caja
 * @param odeOrder
 * @throws ValidatorException
 */
private void comprobarFormFile(es.pode.gestorFlujo.presentacion.objetosPersonales.importar.ImportarODEForm form,
        HttpServletRequest request, CurrentState estadoActual, FormFile formFile, String caja, String odeOrder)
        throws ValidatorException {
    if (formFile != null && formFile.getFileName().length() != 0) {
        if (logger.isDebugEnabled())
            logger.debug("El espacio libre restante:" + form.getEspacioLibre());
        if (estadoActual.diferencia > 0) {
            estadoActual.hemoshechoalgo = true;
            try {
                ResultadoImportacion resultadoParcial = new ResultadoImportacion();
                resultadoParcial.setTitulo(formFile.getFileName());
                ResultadoOperacionVO unResultado = new ResultadoOperacionVO();
                unResultado = importarUnODE(formFile, formFile.getFileName(),
                        request.getLocale().getLanguage());
                if (unResultado.getIdResultado().equals("0.0")) {
                    resultadoParcial.setValido(null);
                    estadoActual.nr_archivos_subidos++;
                    estadoActual.archivosSubidos = estadoActual.archivosSubidos + formFile.getFileName() + ",";
                    estadoActual.diferencia = estadoActual.diferencia - unResultado.getTamainoODE();
                } else if (unResultado.getIdResultado().equals("0.1")) {
                    logger.debug("Borrados vocabularios controlados y fechas incorrectas");
                    resultadoParcial.setValido(RESULTADO_SI);
                    resultadoParcial.setMensajes(unResultado.getDescripcion().split(splitter));
                    estadoActual.nr_archivos_subidos++;
                    estadoActual.archivosSubidos = estadoActual.archivosSubidos + formFile.getFileName() + ",";
                    estadoActual.diferencia = estadoActual.diferencia - unResultado.getTamainoODE();
                } else {
                    resultadoParcial.setValido(RESULTADO_NO);
                    logger.error("El archivo de la " + caja + " no se ha podido importar: "
                            + unResultado.getDescripcion());
                    //               saveErrorMessage(request, "gestorFlujo.error.importar.validar", new String[] {
                    //                     form.getFicheroODE1().getFileName(), unResultado.getDescripcion() });               
                    resultadoParcial.setMensajes(unResultado.getDescripcion().split(splitter));
                    estadoActual.diferencia = form.getEspacioLibre();
                }
                estadoActual.resultado.add(resultadoParcial);
                //               resultado.add(resultadoParcial);

            } catch (Exception ex) {
                logger.error("Excepcion al importar el ode " + caja + ": ", ex);
                throw new ValidatorException("{gestorFlujo.error.inesperado}");
            }
        } else {
            //            diferencia=form.getEspacioLibre();
            ResultadoImportacion resultadoParcial = new ResultadoImportacion();
            String[] textos = new String[1];
            String texto = "El " + odeOrder
                    + " no se ha podido importar, pues excede la cuota libre del usuario:"
                    + estadoActual.diferencia;
            textos[0] = texto;
            logger.error("El " + odeOrder + " no se ha podido importar, pues excede la cuota libre del usuario:"
                    + estadoActual.diferencia);
            resultadoParcial.setMensajes(textos);
            resultadoParcial.setTitulo(formFile.getFileName());
            resultadoParcial.setValido(RESULTADO_NO);
            estadoActual.resultado.add(resultadoParcial);
            //            resultado.add(resultadoParcial);

        }

    }
}

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

/**
 * //from ww w. j  a va 2s.co m
 * This is the method handler that persists/create new data. The <code>command</code> object is
 * binded to the form with the name <code>formCommand</code> from the view. It returns
 * a map consisting of the command object and the success messages.
 * 
 * @param command
 * @param bindingResult
 * @param uiModel
 * @param request
 * @param response
 * @return Map containing the following:<br />
 *          command - the command object<br />
 *          messages - list of MessageResponse
 */
@RequestMapping(value = { "", "0" }, method = RequestMethod.POST, produces = "application/json")
@ResponseView(Views.FormView.class)
public final @ResponseBody Map<String, Object> create(@FormBind(name = "formCommand") T command,
        BindingResult bindingResult, Model uiModel, HttpServletRequest request, HttpServletResponse response) {
    Map<String, Object> model = new HashMap<String, Object>();
    List<MessageResponse> messages = new ArrayList<MessageResponse>();
    createTx(command, bindingResult, uiModel, request, response);
    messages.addAll(CrudUtil.buildSuccessMessage(command, "add", request.getLocale(), messageSource));
    model.put("command", command);
    model.put("messages", messages);
    return model;
}

From source file:com.hp.avmon.kpigetconfig.web.KpigetconfigAgentController.java

/**
 * ???AMP??/*w ww  .j  av  a 2 s  .  c o m*/
 * @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) {
        e.printStackTrace();
        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:org.wallride.web.support.PathVariableLocaleResolver.java

@Override
public Locale resolveLocale(HttpServletRequest request) {
    Blog blog = blogService.getBlogById(Blog.DEFAULT_ID);
    String defaultLanguage = (blog != null) ? blog.getDefaultLanguage() : null;

    Map<String, Object> pathVariables = (Map<String, Object>) request
            .getAttribute(HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE);
    String currentLanguage = (String) pathVariables.get("language");
    if (currentLanguage == null) {
        currentLanguage = defaultLanguage;
    } else {//from w ww.  j  a v  a 2 s.  com
        boolean correct = false;
        if (blog != null) {
            for (BlogLanguage blogLanguage : blog.getLanguages()) {
                if (blogLanguage.getLanguage().equals(currentLanguage)) {
                    correct = true;
                    break;
                }
            }
        }
        if (!correct) {
            currentLanguage = defaultLanguage;
        }
    }

    return (currentLanguage != null) ? Locale.forLanguageTag(currentLanguage) : request.getLocale();
}

From source file:fr.paris.lutece.plugins.mylutece.modules.database.authentication.service.DatabaseService.java

/**
 * Get the filtered list of database users
 * @param duFilter The filter//from w w  w .  j  a  va  2 s.  c om
 * @param bIsSearch True if the user used search filters, false otherwise
 * @param listUsers the initial list to filter
 * @param request HttpServletRequest
 * @param model Map
 * @param url UrlItem
 * @return the filtered list
 */
public List<DatabaseUser> getFilteredUsersInterface(DatabaseUserFilter duFilter, boolean bIsSearch,
        List<DatabaseUser> listUsers, HttpServletRequest request, Map<String, Object> model, UrlItem url) {
    Plugin myLutecePlugin = PluginService.getPlugin(MyLutecePlugin.PLUGIN_NAME);
    List<DatabaseUser> filteredUsers = getListFilteredUsers(request, duFilter, listUsers);
    MyLuteceUserFieldFilter mlFieldFilter = new MyLuteceUserFieldFilter();
    mlFieldFilter.setMyLuteceUserFieldFilter(request, request.getLocale());

    List<IAttribute> listAttributes = AttributeHome.findAll(request.getLocale(), myLutecePlugin);

    for (IAttribute attribute : listAttributes) {
        List<AttributeField> listAttributeFields = AttributeFieldHome
                .selectAttributeFieldsByIdAttribute(attribute.getIdAttribute(), myLutecePlugin);
        attribute.setListAttributeFields(listAttributeFields);
    }

    String strSortSearchAttribute = StringUtils.EMPTY;

    if (bIsSearch) {
        duFilter.setUrlAttributes(url);

        if (duFilter.getUrlAttributes() != StringUtils.EMPTY) {
            strSortSearchAttribute = AMPERSAND + duFilter.getUrlAttributes();
        }

        mlFieldFilter.setUrlAttributes(url);

        if (mlFieldFilter.getUrlAttributes() != StringUtils.EMPTY) {
            strSortSearchAttribute += (AMPERSAND + mlFieldFilter.getUrlAttributes());
        }
    }

    model.put(MARK_SEARCH_IS_SEARCH, bIsSearch);
    model.put(MARK_SEARCH_USER_FILTER, duFilter);
    model.put(MARK_SORT_SEARCH_ATTRIBUTE, strSortSearchAttribute);
    model.put(MARK_SEARCH_MYLUTECE_USER_FIELD_FILTER, mlFieldFilter);
    model.put(MARK_ATTRIBUTES_LIST, listAttributes);

    return filteredUsers;
}

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

@RequestMapping("saveIloHost")
public String saveIloHost(HttpServletResponse response, HttpServletRequest request) {
    String data = "";
    Locale locale = request.getLocale();
    ResourceBundle bundle = ResourceBundle.getBundle("messages", locale);
    try {/*from w w w  .j  ava  2  s.  c o m*/
        data = agentManageService.saveIloHost(request);
        //data="{success:true,msg:" + msg + "}";

    } catch (Exception e) {
        logger.error(this.getClass().getName() + " saveIloHost", e);
        data = "{success:false,msg:'" + bundle.getString("saveFail") + "'}";
    }

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