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.ticketing.modules.ticketingfacilfamilles.service.entrytype.EntryTypeFamilyPic.java
/** * {@inheritDoc}/*from w w w. j a v a2s. c o m*/ */ @Override public GenericAttributeError getResponseData(Entry entry, HttpServletRequest request, List<Response> listResponse, Locale locale) { String strValueEntry = (request.getParameter(PREFIX_ATTRIBUTE + entry.getIdEntry()) != null) ? request.getParameter(PREFIX_ATTRIBUTE + entry.getIdEntry()).trim() : null; boolean bConfirmField = entry.isConfirmField(); String strValueEntryConfirmField = null; if (bConfirmField) { strValueEntryConfirmField = request .getParameter(PREFIX_ATTRIBUTE + entry.getIdEntry() + SUFFIX_CONFIRM_FIELD).trim(); } List<RegularExpression> listRegularExpression = entry.getFields().get(0).getRegularExpressionList(); Response response = new Response(); response.setEntry(entry); if (strValueEntry != null) { response.setResponseValue(strValueEntry); if (StringUtils.isNotBlank(response.getResponseValue())) { response.setToStringValueResponse(getResponseValueForRecap(entry, request, response, locale)); } else { response.setToStringValueResponse(StringUtils.EMPTY); } listResponse.add(response); // Checks if the entry value contains XSS characters if (StringUtil.containsXssCharacters(strValueEntry)) { GenericAttributeError error = new GenericAttributeError(); error.setMandatoryError(false); error.setTitleQuestion(entry.getTitle()); error.setErrorMessage(I18nService.getLocalizedString(MESSAGE_XSS_FIELD, request.getLocale())); return error; } if (entry.isMandatory()) { if (StringUtils.isBlank(strValueEntry)) { if (StringUtils.isNotEmpty(entry.getErrorMessage())) { GenericAttributeError error = new GenericAttributeError(); error.setMandatoryError(true); error.setErrorMessage(entry.getErrorMessage()); return error; } return new MandatoryError(entry, locale); } } if ((!strValueEntry.equals(StringUtils.EMPTY)) && (listRegularExpression != null) && (listRegularExpression.size() != 0) && RegularExpressionService.getInstance().isAvailable()) { for (RegularExpression regularExpression : listRegularExpression) { if (!RegularExpressionService.getInstance().isMatches(strValueEntry, regularExpression)) { GenericAttributeError error = new GenericAttributeError(); error.setMandatoryError(false); error.setTitleQuestion(entry.getTitle()); error.setErrorMessage(regularExpression.getErrorMessage()); return error; } } } if (bConfirmField && ((strValueEntryConfirmField == null) || !strValueEntry.equals(strValueEntryConfirmField))) { GenericAttributeError error = new GenericAttributeError(); error.setMandatoryError(false); error.setTitleQuestion(entry.getConfirmFieldTitle()); error.setErrorMessage(I18nService.getLocalizedString(MESSAGE_CONFIRM_FIELD, new String[] { entry.getTitle() }, request.getLocale())); return error; } } return null; }
From source file:com.graphhopper.http.GraphHopperServlet.java
void writePath(HttpServletRequest req, HttpServletResponse res) throws Exception { List<GHPoint> infoPoints = getPoints(req); // we can reduce the path length based on the maximum differences to the original coordinates double minPathPrecision = getDoubleParam(req, "min_path_precision", 1d); boolean writeGPX = "gpx".equalsIgnoreCase(getParam(req, "type", "json")); boolean enableInstructions = writeGPX || getBooleanParam(req, "instructions", true); boolean calcPoints = getBooleanParam(req, "calc_points", true); boolean elevation = getBooleanParam(req, "elevation", false); String vehicleStr = getParam(req, "vehicle", "CAR").toUpperCase(); String weighting = getParam(req, "weighting", "fastest"); String algoStr = getParam(req, "algorithm", ""); String localeStr = getParam(req, "locale", "en"); StopWatch sw = new StopWatch().start(); GHResponse rsp;/* ww w . j a v a2 s .c o m*/ if (!hopper.getEncodingManager().supports(vehicleStr)) { rsp = new GHResponse().addError(new IllegalArgumentException("Vehicle not supported: " + vehicleStr)); } else if (elevation && !hopper.hasElevation()) { rsp = new GHResponse().addError(new IllegalArgumentException("Elevation not supported!")); } else { FlagEncoder algoVehicle = hopper.getEncodingManager().getEncoder(vehicleStr); rsp = hopper.route(new GHRequest(infoPoints).setVehicle(algoVehicle.toString()).setWeighting(weighting) .setAlgorithm(algoStr).setLocale(localeStr).putHint("calcPoints", calcPoints) .putHint("instructions", enableInstructions).putHint("douglas.minprecision", minPathPrecision)); } float took = sw.stop().getSeconds(); String infoStr = req.getRemoteAddr() + " " + req.getLocale() + " " + req.getHeader("User-Agent"); PointList points = rsp.getPoints(); String logStr = req.getQueryString() + " " + infoStr + " " + infoPoints + ", distance: " + rsp.getDistance() + ", time:" + Math.round(rsp.getMillis() / 60000f) + "min, points:" + points.getSize() + ", took:" + took + ", debug - " + rsp.getDebugInfo() + ", " + algoStr + ", " + weighting + ", " + vehicleStr; if (rsp.hasErrors()) logger.error(logStr + ", errors:" + rsp.getErrors()); else logger.info(logStr); if (writeGPX) writeGPX(req, res, rsp); else writeJson(req, res, rsp, took); }
From source file:fr.paris.lutece.plugins.crm.web.CRMApp.java
/** * Get the page to manage the notifications of a resource * @param request {@link HttpServletRequest} * @param user the {@link LuteceUser}/*from w w w. j a v a 2s. c om*/ * @return a {@link XPage} */ private XPage getManageNotificationsPage(HttpServletRequest request, LuteceUser user) { XPage page = null; CRMUser crmUser = _crmUserService.findByUserGuid(user.getName()); String strIdDemand = request.getParameter(CRMConstants.PARAMETER_ID_DEMAND); if ((crmUser != null) && StringUtils.isNotBlank(strIdDemand) && StringUtils.isNumeric(strIdDemand)) { int nIdDemand = Integer.parseInt(strIdDemand); Demand demand = _demandService.findByPrimaryKey(nIdDemand); if ((demand != null) && (crmUser.getIdCRMUser() == demand.getIdCRMUser())) { // Check the existence of the demand and the owner of the demand is indeed the current user page = new XPage(); NotificationFilter nFilter = new NotificationFilter(); nFilter.setIdDemand(nIdDemand); DemandType demandType = _demandTypeService.findByPrimaryKey(demand.getIdDemandType()); Map<String, Object> model = new HashMap<String, Object>(); model.put(CRMConstants.MARK_NOTIFICATIONS_LIST, _notificationService.findByFilter(nFilter)); model.put(CRMConstants.MARK_DEMAND_TYPE, demandType); HtmlTemplate template = AppTemplateService.getTemplate(TEMPLATE_MANAGE_NOTIFICATIONS, request.getLocale(), model); page.setTitle(I18nService.getLocalizedString(CRMConstants.PROPERTY_MANAGE_NOTIFICATIONS_PAGE_TITLE, request.getLocale())); page.setPathLabel( I18nService.getLocalizedString(CRMConstants.PROPERTY_PAGE_PATH, request.getLocale())); page.setContent(template.getHtml()); } } return page; }
From source file:com.citrix.cpbm.portal.fragment.controllers.AbstractBillingController.java
@RequestMapping(value = "/editcreditcarddetails", method = RequestMethod.POST) public ModelMap editCreditCard(@RequestParam(value = "tenant", required = false) String tenantParam, @ModelAttribute("billingInfo") BillingInfoForm form, HttpServletResponse response, HttpServletRequest request, ModelMap map) throws IOException { logger.debug("###Entering in edit(tenantId, billingAddress,response) method @POST"); Tenant effectiveTenant = tenantService.get(tenantParam); map.addAttribute("tenant", effectiveTenant); try {/* ww w. j a v a 2 s . c om*/ map.addAttribute("isAccountExistInPaymentGateway", ((PaymentGatewayService) connectorManagementService .getOssServiceInstancebycategory(ConnectorType.PAYMENT_GATEWAY)) .isAccountExistInPaymentGateway(effectiveTenant)); CreditCard creditCard = form.getCreditCard(); billingService.editCreditCard(effectiveTenant, creditCard, getRemoteUserIp(request), request.getLocale(), getCurrentUser()); } catch (CreditCardFraudCheckException ex) { response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); throw new InvalidAjaxRequestException(ex.getMessage()); } catch (PaymentGatewayServiceException e) { response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); throw new InvalidAjaxRequestException(e.getMessage()); } catch (BillingServiceException e) { response.setStatus(HttpStatus.PRECONDITION_FAILED.value()); throw new InvalidAjaxRequestException(e.getMessage()); } catch (Exception e) { logger.error("Got Exception while updating billing info : ", e); response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); throw new InvalidAjaxRequestException(messageSource .getMessage("ui.usage.billing.paymentinfo.cc.edit.errormsg", null, getSessionLocale(request))); } String redirectToURL = "/portal/portal/tenants/editcurrent?action=showcreditcardtab&tenant=" + tenantParam; map.put("redirecturl", redirectToURL); String message = "billing.info.updated"; String messageArgs = effectiveTenant.getName(); eventService.createEvent(new Date(), effectiveTenant, message, messageArgs, Source.PORTAL, Scope.ACCOUNT, Category.ACCOUNT, Severity.INFORMATION, true); return map; }
From source file:fr.paris.lutece.plugins.suggest.web.SuggestApp.java
/** * Add the suggest page frameset/*from w ww . j a v a 2 s . c o m*/ * @param strContentSuggest * @param request the {@link HttpServletRequest} * @param page {@link XPage} * @param suggest {@link Suggest} * @param model the model * @param searchFields the searchField * @param luteceUserConnected the luteceUserConnected */ private void addSuggestPageFrameset(String strContentSuggest, HttpServletRequest request, XPage page, Suggest suggest, Map<String, Object> model, SearchFields searchFields, LuteceUser luteceUserConnected) { page.setTitle(I18nService.getLocalizedString(PROPERTY_XPAGE_PAGETITLE, request.getLocale())); page.setPathLabel(I18nService.getLocalizedString(PROPERTY_XPAGE_PATHLABEL, request.getLocale())); if (suggest.isActive()) { //Filter by comment if (suggest.isAuthorizedComment() && suggest.isShowTopCommentBlock()) { SubmitFilter submmitFilterTopComment = new SubmitFilter(); submmitFilterTopComment.setIdSuggest(suggest.getIdSuggest()); submmitFilterTopComment.setIdSuggestSubmitState(_nIdSuggestSubmitStatePublish); submmitFilterTopComment.setIdCategory(searchFields.getIdFilterCategory()); SuggestUtils.initSubmitFilterBySort(submmitFilterTopComment, SubmitFilter.SORT_BY_NUMBER_COMMENT_DESC); List<SuggestSubmit> listSuggestSubmitTopComment = _suggestSubmitService.getSuggestSubmitList( submmitFilterTopComment, _plugin, suggest.getNumberSuggestSubmitInTopComment()); model.put(MARK_LIST_SUBMIT_TOP_COMMENT, listSuggestSubmitTopComment); } //Filter by popularity if (suggest.isShowTopScoreBlock()) { SubmitFilter submmitFilterTopPopularity = new SubmitFilter(); submmitFilterTopPopularity.setIdSuggest(suggest.getIdSuggest()); SuggestUtils.initSubmitFilterBySort(submmitFilterTopPopularity, SubmitFilter.SORT_BY_SCORE_DESC); submmitFilterTopPopularity.setIdSuggestSubmitState(_nIdSuggestSubmitStatePublish); submmitFilterTopPopularity.setIdCategory(searchFields.getIdFilterCategory()); List<SuggestSubmit> listSuggestSubmitTopPopularity = _suggestSubmitService.getSuggestSubmitList( submmitFilterTopPopularity, _plugin, suggest.getNumberSuggestSubmitInTopScore()); model.put(MARK_LIST_SUBMIT_TOP_POPULARITY_SUGGEST, listSuggestSubmitTopPopularity); } //category Block if (suggest.isShowCategoryBlock()) { model.put(MARK_LIST_CATEGORIES_SUGGEST, suggest.getCategories()); } ReferenceList refListSuggestSort = SuggestUtils.getRefListSuggestSort(request.getLocale(), true); ReferenceList refListFilterByPeriod = SuggestUtils.getRefListFilterByPeriod(request.getLocale()); //model model.put(MARK_ID_SUGGEST, suggest.getIdSuggest()); model.put(MARK_QUERY, searchFields.getQuery()); model.put(MARK_ID_SUGGEST_SUBMIT_SORT, searchFields.getIdSuggestSubmitSort()); model.put(MARK_ID_FILTER_PERIOD, searchFields.getIdFilterPeriod()); model.put(MARK_ID_FILTER_CATEGORY_SUGGEST, searchFields.getIdFilterCategory()); model.put(MARK_ID_FILTER_TYPE, searchFields.getIdFilterSuggestSubmitType()); if (searchFields.getIdFilterSuggestSubmitType() != SuggestUtils.CONSTANT_ID_NULL) { model.put(MARK_TYPE_SELECTED, SuggestSubmitTypeHome .findByPrimaryKey(searchFields.getIdFilterSuggestSubmitType(), _plugin)); } model.put(MARK_CONTENT_SUGGEST, strContentSuggest); model.put(MARK_LABEL_SUGGEST, suggest.getLibelleContribution()); model.put(MARK_HEADER_SUGGEST, suggest.getHeader()); model.put(MARK_AUTHORIZED_COMMENT, suggest.isAuthorizedComment()); model.put(MARK_AUTHORIZED_VOTE, !suggest.isDisableVote()); model.put(MARK_NUMBER_SHOWN_CHARACTERS, _nNumberShownCharacters); model.put(MARK_LIST_SUGGEST_SUBMIT_SORT, refListSuggestSort); model.put(MARK_LIST_FILTER_BY_PERIOD, refListFilterByPeriod); model.put(MARK_SHOW_CATEGORY_BLOCK, suggest.isShowCategoryBlock()); model.put(MARK_SHOW_TOP_SCORE_BLOCK, suggest.isShowTopScoreBlock()); model.put(MARK_SHOW_TOP_COMMENT_BLOCK, suggest.isShowTopCommentBlock()); model.put(MARK_IS_EXTEND_INSTALLED, PortalService.isExtendActivated()); } else { model.put(MARK_UNAVAILABILITY_MESSAGE, suggest.getUnavailabilityMessage()); } model.put(MARK_LUTECE_USER_CONNECTED, luteceUserConnected); HtmlTemplate template = AppTemplateService.getTemplate(TEMPLATE_XPAGE_FRAME_SUGGEST, request.getLocale(), model); page.setContent(template.getHtml()); }
From source file:alpha.portal.webapp.controller.UserFormController.java
/** * Show form./*from w w w . j a va2s .co m*/ * * @param request * the request * @param response * the response * @return the model and view * @throws Exception * the exception */ @ModelAttribute @RequestMapping(method = { RequestMethod.GET, RequestMethod.POST }) protected ModelAndView showForm(final HttpServletRequest request, final HttpServletResponse response) throws Exception { final ModelAndView model = new ModelAndView(); User user; // If not an administrator, make sure user is not trying to add or edit // another user if (!request.isUserInRole(Constants.ADMIN_ROLE) && !this.isFormSubmission(request)) { if (this.isAdd(request) || (request.getParameter("id") != null)) { response.sendError(HttpServletResponse.SC_FORBIDDEN); this.log.warn("User '" + request.getRemoteUser() + "' is trying to edit user with id '" + request.getParameter("id") + "'"); throw new AccessDeniedException("You do not have permission to modify other users."); } } if (!this.isFormSubmission(request)) { final String userId = request.getParameter("id"); // if user logged in with remember me, display a warning that they // can't change passwords this.log.debug("checking for remember me login..."); final AuthenticationTrustResolver resolver = new AuthenticationTrustResolverImpl(); final SecurityContext ctx = SecurityContextHolder.getContext(); if (ctx.getAuthentication() != null) { final Authentication auth = ctx.getAuthentication(); if (resolver.isRememberMe(auth)) { request.getSession().setAttribute("cookieLogin", "true"); // add warning message this.saveMessage(request, this.getText("userProfile.cookieLogin", request.getLocale())); } } if ((userId == null) && !this.isAdd(request)) { user = this.getUserManager().getUserByUsername(request.getRemoteUser()); } else if (!StringUtils.isBlank(userId) && !"".equals(request.getParameter("version"))) { user = this.getUserManager().getUser(userId); } else { user = new User(); user.addRole(new Role(Constants.USER_ROLE)); } user.setConfirmPassword(user.getPassword()); UserExtension userExtension; final Long uId = user.getId(); if ((uId != null) && this.userExtensionManager.exists(uId)) { userExtension = this.userExtensionManager.get(uId); } else { userExtension = new UserExtension(user); } model.addObject("userExtension", userExtension); model.addObject("contributorRoles", this.contributorRoleManager.getAll()); } else { // populate user object from database, so all fields don't need to // be hidden fields in form user = this.getUserManager().getUser(request.getParameter("id")); } model.addObject("user", user); return model; }
From source file:com.hp.avmon.config.service.AgentManageService.java
/** * ?Agent//from w w w . ja v a2 s .co m * @param request * @return * @throws Exception */ public String stopAgent(HttpServletRequest request) throws Exception { String status = request.getParameter("status"); String agentId = request.getParameter("agentId"); String result = avmonServer.stopAgent(agentId); int agentCollectFlag = 0; String updateStatus = ""; Locale locale = request.getLocale(); ResourceBundle bundle = ResourceBundle.getBundle("messages", locale); if (result.startsWith("00")) { agentCollectFlag = 1; this.updateAgentStatusByAgentId(status, agentId, agentCollectFlag); updateStatus = "{success:true,msg:'" + bundle.getString("agentStopSuccess") + "'}"; } else { this.updateAgentStatusByAgentId(status, agentId, agentCollectFlag); updateStatus = "{success:false,msg:'" + result + "'}"; } return updateStatus; }
From source file:fr.paris.lutece.plugins.stock.modules.billetterie.web.OfferJspBean.java
/** * Get the manage offers page// www. j a v a 2 s .c o m * * @param request * the request * @return the page with offers list */ public String getManageOffers(HttpServletRequest request) { setPageTitleProperty(PROPERTY_PAGE_TITLE_MANAGE_OFFER); SeanceFilter filter = (SeanceFilter) getOfferFilter(request); if ((filter.getProductId() != null) && (filter.getProductId() > 0)) { ShowDTO show = this._serviceProduct.findById(filter.getProductId()); filter.setProductName(show.getName()); } if (StringUtils.isNotEmpty(filter.getProductName())) { ProductFilter productFilter = new ProductFilter(); productFilter.setName(filter.getProductName()); List<ShowDTO> listShow = this._serviceProduct.findByFilter(productFilter); if (!listShow.isEmpty()) { filter.setProductId(listShow.get(0).getId()); } } // Fill the model Map<String, Object> model = new HashMap<String, Object>(); model.put(MARK_LOCALE, getLocale()); // if date begin is after date end, add error List<String> errors = new ArrayList<String>(); if ((filter.getDateBegin() != null) && (filter.getDateEnd() != null) && filter.getDateBegin().after(filter.getDateEnd())) { errors.add(I18nService.getLocalizedString(MESSAGE_SEARCH_PURCHASE_DATE, request.getLocale())); } model.put(MARK_ERRORS, errors); List<String> orderList = new ArrayList<String>(); orderList.add(ORDER_FILTER_DATE); orderList.add(ORDER_FILTER_PRODUCT_NAME); orderList.add(ORDER_FILTER_TYPE_NAME); filter.setOrders(orderList); filter.setOrderAsc(true); DataTableManager<SeanceDTO> dataTableToUse = getDataTable(request, filter); for (SeanceDTO seance : dataTableToUse.getItems()) { // Update quantity with quantity in session for this offer seance.setQuantity( _purchaseSessionManager.updateQuantityWithSession(seance.getQuantity(), seance.getId())); } model.put(MARK_DATA_TABLE_OFFER, dataTableToUse); // the paginator model.put(TicketsConstants.MARK_NB_ITEMS_PER_PAGE, String.valueOf(_nItemsPerPage)); // the filter model.put(TicketsConstants.MARK_FILTER, filter); // Combo ReferenceList offerGenreComboList = ListUtils.toReferenceList(_serviceOffer.findAllGenre(), BilletterieConstants.ID, BilletterieConstants.NAME, StockConstants.EMPTY_STRING); model.put(MARK_LIST_OFFER_GENRE, offerGenreComboList); // offer statut model.put(MARK_OFFER_STATUT_CANCEL, TicketsConstants.OFFER_STATUT_CANCEL); model.put(MARK_OFFER_STATUT_LOCK, TicketsConstants.OFFER_STATUT_LOCK); // currentDate model.put(MARK_CURRENT_DATE, DateUtils.getCurrentDateString()); HtmlTemplate template = AppTemplateService.getTemplate(TEMPLATE_MANAGE_OFFERS, getLocale(), model); //opration ncessaire pour eviter les fuites de mmoires dataTableToUse.clearItems(); return getAdminPage(template.getHtml()); }
From source file:org.squale.squaleweb.applicationlayer.action.results.project.ProjectResultsAction.java
/** * Exporte la liste des composants par note de pratiques au format XLS * //from w w w .ja va 2s . c o m * @param mapping le actionMapping * @param form le form * @param request la request * @param response la response * @return l'actionForward * @throws ServletException exception pouvant etre levee */ public ActionForward exportMarkToExcel(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws ServletException { // Le nom de l'utilisateur LogonBean logon = (LogonBean) request.getSession().getAttribute(WConstants.USER_KEY); try { ExcelDataMarkList data = new ExcelDataMarkList(request.getLocale(), getResources(request), (MarkForm) form, logon.getMatricule()); ExcelFactory.generateExcelToHTTPResponse(data, response, "Marks.xls"); } catch (Exception e) { throw new ServletException(e); } return null; }
From source file:com.hp.avmon.config.service.AgentManageService.java
public Map batchPushAgentAmpSchedule(HttpServletRequest request) { Map<String, Object> map = new HashMap<String, Object>(); //???AMPList// w w w.j a va 2 s . c om final List<Map<String, String>> ampListMapF = getListMapByJsonArrayString( request.getParameter("agentAmpInfo")); boolean flag = false; Locale locale = request.getLocale(); ResourceBundle bundle = ResourceBundle.getBundle("messages", locale); for (Map<String, String> ampMap : ampListMapF) { String ampInstId = ampMap.get("ampInstId"); String agentId = ampMap.get("agentId"); String result = avmonServer.deployAmpSchedule(agentId, ampInstId); if (result.startsWith("00")) { //String updateAmpStatusSql = String.format("UPDATE TD_AVMON_AMP_INST SET STATUS = 2 WHERE AMP_INST_ID ='%s' AND AMP_ID ='%s' AND AGENT_ID ='%s'",ampInstId,ampId,agentId); //jdbcTemplate.update(updateAmpStatusSql); flag = true; map.put("errorMsg", bundle.getString("dispatchIssuedSuccess")); } else { map.put("errorMsg", result); } } map.put("success", flag); return map; }