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:eu.europa.ejusticeportal.dss.demo.web.portal.PortalFacadeImpl.java
@Override public Map<String, String> getLocalisedMessages(HttpServletRequest request, List<String> codes) { HashMap<String, String> map = new HashMap<String, String>(); Properties p = new Properties(); InputStream is = PortalFacadeImpl.class.getClassLoader().getResourceAsStream("i18n/messages_en.xml"); try {// ww w .ja va 2s.c o m p.loadFromXML(is); for (Object o : p.keySet()) { map.put((String) o, messageSource.getMessage((String) o, null, request.getLocale())); } } catch (Exception e) { LOG.error("Error getting messages", e); } return map; }
From source file:fr.paris.lutece.plugins.workflow.modules.rest.rs.ActionRest.java
/** * Check if the action can be executed or not * @param nIdAction the id action/*from w w w . j a v a 2 s .c om*/ * @param nIdResource the id resource * @param strResourceType the resource type * @param request the HTTP request * @return null if the action can be executed, a {@link FailedActionResult} object otherwise */ private IActionResult checkDoAction(int nIdAction, int nIdResource, String strResourceType, HttpServletRequest request) { // Check the availability of the workflow service if (!WorkflowService.getInstance().isAvailable()) { new FailedActionResult(nIdAction, nIdResource, strResourceType, WorkflowRestConstants.MESSAGE_ERROR_WORKFLOW_NOT_AVAILABLE); } // Check if the action does not require intermediate step if (WorkflowService.getInstance().isDisplayTasksForm(nIdAction, request.getLocale())) { return new FailedActionResult(nIdAction, nIdResource, strResourceType, WorkflowRestConstants.MESSAGE_ERROR_ACTION_NEEDS_INTERMEDIATE_STEP); } // Check the existence of the action Action action = _workflowRestService.getAction(nIdAction); if (action == null) { return new FailedActionResult(nIdAction, nIdResource, strResourceType, WorkflowRestConstants.MESSAGE_ERROR_ACTION_NONEXISTENT); } // Check the existence of the resource ResourceWorkflow resource = _workflowRestService.getResourceWorkflow(nIdResource, strResourceType, action.getWorkflow().getId()); if (resource == null) { return new FailedActionResult(nIdAction, nIdResource, strResourceType, WorkflowRestConstants.MESSAGE_ERROR_RESOURCE_NONEXISTENT); } // Check if the resource has the right state to perform the action if (!WorkflowService.getInstance().canProcessAction(nIdResource, strResourceType, nIdAction, resource.getExternalParentId(), request, true)) { return new FailedActionResult(nIdAction, nIdResource, strResourceType, WorkflowRestConstants.MESSAGE_ERROR_RESOURCE_STATE); } return null; }
From source file:alpha.portal.webapp.controller.CardFormController.java
/** * Delete payload./*from w w w.ja v a 2 s . co m*/ * * @param jspCard * the jsp card * @param request * the request * @return the string * @throws IOException * Signals that an I/O exception has occurred. */ @RequestMapping(method = RequestMethod.POST, params = { "payloadDelete" }) public String deletePayload(final AlphaCard jspCard, final HttpServletRequest request) throws IOException { final AlphaCard alphaCard = this.alphaCardManager.get(jspCard.getAlphaCardIdentifier()); alphaCard.setPayload(null); this.alphaCardManager.save(alphaCard); final Locale locale = request.getLocale(); this.saveMessage(request, this.getText("card.updated", locale)); final AlphaCardIdentifier identifier = alphaCard.getAlphaCardIdentifier(); return "redirect:/caseform?caseId=" + identifier.getCaseId() + "&activeCardId=" + identifier.getCardId(); }
From source file:alpha.portal.webapp.controller.CardFormController.java
/** * Save card./*from www. j a v a 2s. c o m*/ * * @param jspCard * the jsp card * @param errors * the errors * @param request * the request * @param response * the response * @return the string * @throws Exception * the exception */ @RequestMapping(method = RequestMethod.POST, params = { "saveCard" }) public String saveCard(final AlphaCard jspCard, final BindingResult errors, final HttpServletRequest request, final HttpServletResponse response) throws Exception { AlphaCard alphaCard = null; AlphaCardIdentifier identifier = null; final Locale locale = request.getLocale(); if (!StringUtils.isBlank(jspCard.getAlphaCardIdentifier().getCardId())) { alphaCard = this.alphaCardManager.get(jspCard.getAlphaCardIdentifier()); identifier = alphaCard.getAlphaCardIdentifier(); final String cardId = identifier.getCardId(); final String caseId = identifier.getCaseId(); final Adornment contributor = alphaCard.getAlphaCardDescriptor() .getAdornment(AdornmentType.Contributor.getName()); if ((contributor.getValue() == null) || contributor.getValue().isEmpty()) { this.saveError(request, this.getText("adornment.noAccess", locale)); return "redirect:/caseform?activeCardId=" + cardId + "&caseId=" + caseId; } else { final Long contributorID = Long.parseLong(contributor.getValue()); final User currentUser = this.getUserManager().getUserByUsername(request.getRemoteUser()); if (contributorID != currentUser.getId()) { this.saveError(request, this.getText("adornment.noAccess", locale)); return "redirect:/caseform?activeCardId=" + cardId + "&caseId=" + caseId; } } /** * Check if card has been deleted */ final Adornment delAdornment = alphaCard.getAlphaCardDescriptor() .getAdornment(AdornmentType.Deleted.getName()); if (delAdornment != null) { final String delIsTrue = AdornmentTypeDeleted.TRUE.value(); if (delAdornment.getValue().equals(delIsTrue)) { this.saveError(request, this.getText("adornment.errorChange", locale)); return "redirect:/caseform?activeCardId=" + cardId + "&caseId=" + caseId; } } alphaCard.getAlphaCardDescriptor().setTitle(jspCard.getAlphaCardDescriptor().getTitle()); } else { alphaCard = this.alphaCardManager.createAlphaCard(jspCard.getAlphaCardIdentifier().getCaseId()); final User currentUser = this.userManager.getUserByUsername(request.getRemoteUser()); alphaCard.getAlphaCardDescriptor().setContributor(currentUser.getId()); for (final Adornment a : jspCard.getAlphaCardDescriptor().getAllAdornments()) { alphaCard.getAlphaCardDescriptor().setAdornment(a.getName(), a.getValue()); } identifier = alphaCard.getAlphaCardIdentifier(); final AlphaCase alphaCase = this.caseManager.get(identifier.getCaseId()); alphaCase.addAlphaCard(alphaCard); } alphaCard = this.alphaCardManager.save(alphaCard); this.saveMessage(request, this.getText("card.updated", locale)); return "redirect:/caseform?caseId=" + identifier.getCaseId() + "&activeCardId=" + identifier.getCardId(); }
From source file:es.pode.administracion.presentacion.adminusuarios.bajaGrupo.BajaControllerImpl.java
/** * @see es.pode.administracion.presentacion.adminusuarios.bajaGrupo.BajaController#bajaGrupo(org.apache.struts.action.ActionMapping, * es.pode.administracion.presentacion.adminusuarios.bajaGrupo.BajaGrupoForm, * javax.servlet.http.HttpServletRequest, * javax.servlet.http.HttpServletResponse) *//* w w w . j a v a2s . c o m*/ public final void bajaGrupo(ActionMapping mapping, es.pode.administracion.presentacion.adminusuarios.bajaGrupo.BajaGrupoForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { String listaId = request.getParameter("listaId"); if (log.isDebugEnabled()) log.debug("los ids de usuario que se quieren eliminar son " + listaId); Object[] objeto = listaId.split(" "); ResourceBundle ficheroRecursos = null; try { SrvAdminUsuariosService srvAdminUsuariosService = this.getSrvAdminUsuariosService(); ValidaBajaGrupoVO validaBaja = srvAdminUsuariosService.bajaGrupo(obtenerIds(objeto)); Locale locale = request.getLocale(); ficheroRecursos = this.getFicherRecursos(locale); form.setDescripcionBaja(ficheroRecursos.getString(validaBaja.getDescripcion())); form.setGruposDeleted(validaBaja.getItemsDeleted()); } catch (Exception e) { log.error("Se ha producido un error al eliminar el usuario " + e); throw new ValidatorException("{errors.borrarUsuario}"); } }
From source file:fr.paris.lutece.plugins.extend.web.action.CreateExtenderFromResourcePluginAction.java
/** * {@inheritDoc}//from www . ja v a 2s. c o m */ @Override public void fillModel(HttpServletRequest request, AdminUser adminUser, Map<String, Object> model) { String strIdExtendableResource = (String) model .get(ExtendableResourcePluginActionManager.MARK_ID_EXTENDABLE_RESOURCE); String strExtendableResourceType = (String) model .get(ExtendableResourcePluginActionManager.MARK_EXTENDABLE_RESOURCE_TYPE); // TODO : Display the action only if the user has the permission model.put(MARK_EXTENDER_TYPES, _resourceExtenderService.getExtenderTypes(request.getLocale())); model.put(MARK_EXTENDER_TYPES_INSTALLED, _resourceExtenderService.getExtenderTypesInstalled(strIdExtendableResource, strExtendableResourceType, PluginService.getPlugin(ExtendPlugin.PLUGIN_NAME))); }
From source file:fr.paris.lutece.plugins.stock.modules.billetterie.web.StockBilletterieApp.java
/** * {@inheritDoc}/*from ww w.j a v a2s .c o m*/ */ @Override public XPage getPage(HttpServletRequest request, int nMode, Plugin plugin) throws UserNotSignedException, SiteMessageException { XPage page = new XPage(); Locale locale = request.getLocale(); String strAction = request.getParameter(PARAMETER_ACTION); if (ACTION_SHOW_PAGE.equals(strAction)) { page = getShowPage(page, request, locale); } if (ACTION_CURRENT_SHOW_LIST.equals(strAction)) { page = getCurrentListShowPage(page, request, locale); } if (ACTION_COME_SHOW_LIST.equals(strAction)) { page = getComeListShowPage(page, request, locale); } return page; }
From source file:com.tapas.evidence.fe.controller.CaptchaController.java
@RequestMapping("/captcha.jpg") public void showForm(HttpServletRequest request, HttpServletResponse response) throws Exception { byte[] captchaChallengeAsJpeg = null; // the output stream to render the captcha image as jpeg into ByteArrayOutputStream jpegOutputStream = new ByteArrayOutputStream(); try {/*from w w w . j a va2 s . co m*/ // get the session id that will identify the generated captcha. // the same id must be used to validate the response, the session id is a good candidate! String captchaId = request.getSession().getId(); BufferedImage challenge = captchaService.getImageChallengeForID(captchaId, request.getLocale()); ImageIO.write(challenge, CAPTCHA_IMAGE_FORMAT, jpegOutputStream); } catch (IllegalArgumentException e) { response.sendError(HttpServletResponse.SC_NOT_FOUND); return; } catch (CaptchaServiceException e) { response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); return; } captchaChallengeAsJpeg = jpegOutputStream.toByteArray(); // flush it in the response response.setHeader("Cache-Control", "no-store"); response.setHeader("Pragma", "no-cache"); response.setDateHeader("Expires", 0); response.setContentType("image/" + CAPTCHA_IMAGE_FORMAT); ServletOutputStream responseOutputStream = response.getOutputStream(); responseOutputStream.write(captchaChallengeAsJpeg); responseOutputStream.flush(); responseOutputStream.close(); }
From source file:it.jugpadova.controllers.JCaptchaController.java
@RequestMapping public void image(HttpServletRequest req, HttpServletResponse res) throws IOException { byte[] captchaChallengeAsJpeg = null; // the output stream to render the captcha image as jpeg into ByteArrayOutputStream jpegOutputStream = new ByteArrayOutputStream(); // get the session id that will identify the generated captcha. //the same id must be used to validate the res, the session id is a good candidate! String captchaId = req.getSession().getId(); // call the ImageCaptchaService getChallenge method BufferedImage challenge = captchaService.getImageChallengeForID(captchaId, req.getLocale()); // a jpeg encoder JPEGImageEncoder jpegEncoder = JPEGCodec.createJPEGEncoder(jpegOutputStream); jpegEncoder.encode(challenge);//from w w w .j av a2s. co m captchaChallengeAsJpeg = jpegOutputStream.toByteArray(); // flush it in the res res.setHeader("Cache-Control", "no-store"); res.setHeader("Pragma", "no-cache"); res.setDateHeader("Expires", 0); res.setContentType("image/jpeg"); ServletOutputStream resOutputStream = res.getOutputStream(); resOutputStream.write(captchaChallengeAsJpeg); resOutputStream.flush(); resOutputStream.close(); }
From source file:es.pode.administracion.presentacion.catalogacion.bajaCatalogadores.BajaCatalogadoresControllerImpl.java
/** * @see es.pode.administracion.presentacion.catalogacion.bajaCatalogadores.BajaCatalogadoresController#bajaCatalogadores(org.apache.struts.action.ActionMapping, es.pode.administracion.presentacion.catalogacion.bajaCatalogadores.BajaCatalogadoresForm, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse) *///from w w w. ja v a2 s .c om public final void bajaCatalogadores(ActionMapping mapping, es.pode.administracion.presentacion.catalogacion.bajaCatalogadores.BajaCatalogadoresForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { String listaId = request.getParameter("listaId"); if (log.isDebugEnabled()) log.debug("los ids de usuario que se quieren eliminar son " + listaId); Object[] objeto = listaId.split(" "); ResourceBundle ficheroRecursos = null; try { SrvAdminUsuariosService srvAdminUsuariosService = this.getSrvAdminUsuariosService(); ValidaBajaGrupoTrabajoVO validaBaja = srvAdminUsuariosService.bajaGrupoTrabajo(obtenerIds(objeto)); Locale locale = request.getLocale(); ficheroRecursos = this.getFicherRecursos(locale); form.setDescripcionBaja(ficheroRecursos.getString(validaBaja.getDescripcion())); form.setGruposTrabajoBorrados(validaBaja.getItemsDeleted()); } catch (Exception e) { log.error("Se ha producido un error al eliminar el usuario " + e); throw new ValidatorException("{errors.borrarUsuario}"); } }