List of usage examples for javax.servlet.http HttpServletRequest getLocale
public Locale getLocale();
Locale
that the client will accept content in, based on the Accept-Language header. From source file:fr.paris.lutece.plugins.stock.modules.billetterie.web.AbstractXPageApp.java
/** * Return localized message with args.//w w w. j a v a 2s . co m * * @param key i18n key * @param request the request * @param args args * @return localized message */ protected String getMessage(String key, HttpServletRequest request, String... args) { return I18nService.getLocalizedString(key, args, request.getLocale()); }
From source file:es.pode.visualizador.presentacion.recuerdoUsuario.RecuerdoControllerImpl.java
/** * @see es.pode.visualizador.presentacion.recuerdoUsuario.RecuerdoController#nuevaClave(org.apache.struts.action.ActionMapping, * es.pode.visualizador.presentacion.recuerdoUsuario.NuevaClaveForm, * javax.servlet.http.HttpServletRequest, * javax.servlet.http.HttpServletResponse) *//*from w ww. j a va 2 s . com*/ public final void nuevaClave(ActionMapping mapping, es.pode.visualizador.presentacion.recuerdoUsuario.NuevaClaveForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { String email = form.getEmail(); ResourceBundle ficheroRecursos = null; // El idioma se escogera del perfil del usuario Locale locale = request.getLocale(); ficheroRecursos = this.getFicherRecursos(locale); //String idiomaSelected = locale.getLanguage(); // El idioma se escogera del que tiene configurador en el navegador if (email.length() <= 0) { throw new ValidatorException("{errors.recuerdoUsuario.emailVacio}"); } String nif = (form.getNif()).toUpperCase(locale); if (nif.length() <= 0) { throw new ValidatorException("{errors.recuerdoUsuario.nifVacio}"); } UsuarioVO usuarioVO = (this.getSrvAdminUsuariosService()).obtenerUsuario(nif); if (usuarioVO == null) { throw new ValidatorException("{errors.recuerdoUsuario.nifNoExistente}"); } if (!(usuarioVO.getEmail().equalsIgnoreCase(email))) { throw new ValidatorException("{errors.recuerdoUsuario.emailDistinto}"); } log("Obtengo la informacion del administrador que esta gestionando el alta de usuario"); Boolean resultadoModificacion = this.getSrvAdminUsuariosService().nuevaClave(usuarioVO); if (resultadoModificacion == Boolean.FALSE) { form.setResultadoNuevaClave(ficheroRecursos.getString("errors.recuerdoUsuario")); } else { form.setResultadoNuevaClave(ficheroRecursos.getString("recuerdoUsuario.ok")); } }
From source file:de.micromata.genome.gwiki.page.impl.i18n.GWikiI18NServletFilter.java
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { HttpServletRequest hreq = (HttpServletRequest) request; HttpServletResponse hresp = (HttpServletResponse) response; HTTPCTX.set(Pair.make(hreq, hresp)); initWiki(hreq, hresp);//from ww w .j a v a 2s . c om Locale loc = hreq.getLocale(); Object ploc = request.getAttribute(LOC_KEY); if (ploc instanceof Locale) { loc = (Locale) ploc; } LocalizationContext prevLocContext = null; Object plc = hreq.getAttribute(LOCALIZATION_KEY); if (plc instanceof LocalizationContext) { prevLocContext = (LocalizationContext) plc; } Object prevfml = hreq.getAttribute(LOC_KEY); Object prevlocaiz = hreq.getAttribute(LOCALIZATION_KEY); try { hreq.setAttribute(LOC_KEY, loc); hreq.setAttribute(LOCALIZATION_KEY, new LocalizationContext( new GWikiI18NCombinedResourceBundle(loc, prevLocContext, modules), loc)); chain.doFilter(request, response); } finally { hreq.setAttribute(LOC_KEY, prevfml); hreq.setAttribute(LOCALIZATION_KEY, prevlocaiz); HTTPCTX.set(null); } }
From source file:be.iminds.aiolos.ui.CommonServlet.java
private void doGetPlugin(HttpServletRequest request, HttpServletResponse response) throws IOException { StringWriter sw = new StringWriter(); writeJSON(sw, request.getLocale()); Map<Object, Object> vars = getProperties(request); vars.put("__data__", sw.toString()); vars.put("drawDetails", drawDetails); response.getWriter().print(TEMPLATE); }
From source file:alpha.portal.webapp.controller.CardFileUploadController.java
/** * shows the card file upload site.//from w w w .j av a 2 s . c o m * * @param request * the request * @return FileUpload * @see cardfileupload.jsp */ @ModelAttribute @RequestMapping(method = RequestMethod.GET) public FileUpload showForm(final HttpServletRequest request) { final String caseId = request.getParameter("case"); final String cardId = request.getParameter("card"); final Locale locale = request.getLocale(); request.setAttribute("case", caseId); request.setAttribute("card", cardId); this.setCancelView("redirect:/caseform?caseId=" + caseId + "&activeCardId=" + cardId); this.setSuccessView("redirect:/caseform?caseId=" + caseId + "&activeCardId=" + cardId); return new FileUpload(); }
From source file:org.saiku.reporting.backend.rest.MetadataDiscoverResource.java
/** * Returns the datasources available. *///from w w w .j a va2s . c om @GET @Produces({ "application/json" }) @Path("/{locale}") public MetadataModelInfo[] getModelInfos(@Context HttpServletRequest request) { try { if (log.isDebugEnabled()) { log.debug("REST:GET " + " getModelInfos"); } return metadataRepository.getBusinessModels("", request.getLocale()); } catch (MetadataException e) { log.error(this.getClass().getName(), e); return new MetadataModelInfo[] {}; } }
From source file:nu.yona.server.rest.LocalizationFilter.java
@Override public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain chain) throws IOException, ServletException { HttpServletRequest request = (HttpServletRequest) servletRequest; HttpServletResponse response = (HttpServletResponse) servletResponse; request = new LocalizationRequestWrapper(properties, request); response.setHeader(HttpHeaders.CONTENT_LANGUAGE, Translator.getStandardLocaleString(request.getLocale())); chain.doFilter(request, response);//from w w w.j av a2 s .c o m }
From source file:fr.paris.lutece.plugins.workflow.modules.editrecord.web.EditRecordApp.java
/** * Do edit a record// w w w . j av a 2 s .c o m * @param request the HTTP request * @param editRecord the edit record * @return true if the record must be updated, false otherwise * @throws SiteMessageException a site message if there is a problem */ private boolean doEditRecord(HttpServletRequest request, EditRecord editRecord) throws SiteMessageException { if (_editRecordService.isRecordStateValid(editRecord, request.getLocale())) { // Modify record data if (_editRecordService.doEditRecordData(request, editRecord)) { // Change record state _editRecordService.doChangeRecordState(editRecord, request.getLocale()); // Change the status of the edit record to complete _editRecordService.doCompleteEditRecord(editRecord); return true; } return false; } else { _editRecordService.setSiteMessage(request, Messages.USER_ACCESS_DENIED, SiteMessage.TYPE_STOP, request.getParameter(EditRecordConstants.PARAMETER_URL_RETURN)); } return false; }
From source file:com.ewcms.component.checkcode.web.ImageCaptchaServlet.java
@Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { ByteArrayOutputStream jpegOutputStream = new ByteArrayOutputStream(); try {//from w w w . ja v a2 s . c om String captchaId = request.getSession().getId(); createCheckCodeImage(captchaId, request.getLocale(), jpegOutputStream); } catch (IllegalArgumentException e) { response.sendError(HttpServletResponse.SC_NOT_FOUND); return; } catch (CaptchaServiceException e) { response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); return; } initResponseHeader(response); responseImage(response, jpegOutputStream.toByteArray()); jpegOutputStream.close(); }
From source file:org.openmrs.contrib.metadatarepository.webapp.controller.PasswordHintController.java
@RequestMapping(method = RequestMethod.GET) public ModelAndView handleRequest(HttpServletRequest request) throws Exception { log.debug("entering 'handleRequest' method..."); String username = request.getParameter("username"); MessageSourceAccessor text = new MessageSourceAccessor(messageSource, request.getLocale()); // ensure that the username has been sent if (username == null) { log.warn("Username not specified, notifying user that it's a required field."); request.setAttribute("error", text.getMessage("errors.required", text.getMessage("user.username"))); return new ModelAndView("login"); }//from w w w .ja va 2 s.c o m log.debug("Processing Password Hint..."); // look up the user's information try { User user = userManager.getUserByUsername(username); StringBuffer msg = new StringBuffer(); msg.append("Your password hint is: ").append(user.getPasswordHint()); msg.append("\n\nLogin at: ").append(RequestUtil.getAppURL(request)); message.setTo(user.getEmail()); String subject = '[' + text.getMessage("webapp.name") + "] " + text.getMessage("user.passwordHint"); message.setSubject(subject); message.setText(msg.toString()); mailEngine.send(message); saveMessage(request, text.getMessage("login.passwordHint.sent", new Object[] { username, user.getEmail() })); } catch (UsernameNotFoundException e) { log.warn(e.getMessage()); saveError(request, text.getMessage("login.passwordHint.error", new Object[] { username })); } catch (MailException me) { log.warn(me.getMessage()); saveError(request, me.getCause().getLocalizedMessage()); } return new ModelAndView(new RedirectView(request.getContextPath())); }