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:org.jamwiki.taglib.PaginationTag.java
/** * *//*from w w w . java2 s.c o m*/ private StringBuffer numResults(Pagination pagination, String baseUrl) { HttpServletRequest request = (HttpServletRequest) this.pageContext.getRequest(); StringBuffer output = new StringBuffer(); output.append(Utilities.formatMessage("common.pagination.results", request.getLocale())).append(": "); output.append(buildOption(10, pagination, baseUrl)); output.append(" | "); output.append(buildOption(25, pagination, baseUrl)); output.append(" | "); output.append(buildOption(50, pagination, baseUrl)); output.append(" | "); output.append(buildOption(100, pagination, baseUrl)); output.append(" | "); output.append(buildOption(250, pagination, baseUrl)); output.append(" | "); output.append(buildOption(500, pagination, baseUrl)); return output; }
From source file:com.feilong.taglib.display.option.OptionTag.java
@Override protected Object buildContent(HttpServletRequest request) { OptionParam optionParam = new OptionParam(); optionParam.setBaseName(baseName);//from w w w . ja v a 2 s . c o m optionParam.setLocale(defaultIfNull(toLocale(locale), request.getLocale())); optionParam.setSelectedKey(selectedKey); return OptionBuilder.buildContent(optionParam); }
From source file:com.ibm.util.merge.web.rest.servlet.RequestData.java
public RequestData(HttpServletRequest request) { method = request.getMethod();//from ww w. j ava 2 s. c om byte[] bytes = readRequestBody(request); requestBody = bytes; contentType = request.getContentType(); preferredLocale = request.getLocale(); List<Locale> tlocales = getAllRequestLocales(request); locales = new ArrayList<>(tlocales); params = request.getParameterMap(); pathInfo = request.getPathInfo(); queryString = request.getQueryString(); Map<String, List<String>> headerValues = readHeaderValues(request); headers = headerValues; requestUrl = request.getRequestURL().toString(); }
From source file:com.healthcit.cacure.web.interceptor.MessageBundleInterceptor.java
@Override public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception { // Add the breadcrumb list to the ModelMap with the key "breadCrumbList" if (modelAndView != null) { modelAndView.getModelMap().addAttribute(MESSAGE_MAP, resourceMessageSource.getMessages(request.getLocale())); }//from ww w. j a v a 2 s. co m }
From source file:it.cilea.osd.common.controller.SimpleController.java
private ModelAndView handleDelete(HttpServletRequest request) { Map<String, Object> model = new HashMap<String, Object>(); String paramId = request.getParameter("id"); Integer id = Integer.valueOf(paramId); try {// w w w . java 2s. co m applicationService.delete(objectClass, id); saveMessage(request, getText(i18nPrefix + ".deleted", request.getLocale())); } catch (Exception e) { saveMessage(request, getText(i18nPrefix + ".notdeleted", request.getLocale())); return new ModelAndView(getErrorView(), model); } return new ModelAndView(getListView(), model); }
From source file:alpha.portal.webapp.controller.CardFileUploadController.java
/** * handles the case, if the user clicks on one of the buttons. * /*w w w.j a va 2 s .com*/ * @param fileUpload * the file upload * @param errors * the errors * @param request * the request * @return success view * @throws IOException * Signals that an I/O exception has occurred. */ @RequestMapping(method = RequestMethod.POST) public String onSubmit(final FileUpload fileUpload, final BindingResult errors, final HttpServletRequest request) throws IOException { final String caseId = request.getParameter("case"); final String cardId = request.getParameter("card"); final Locale locale = request.getLocale(); this.setCancelView("redirect:/caseform?caseId=" + caseId + "&activeCardId=" + cardId); this.setSuccessView("redirect:/caseform?caseId=" + caseId + "&activeCardId=" + cardId); final AlphaCard card = this.alphaCardManager.get(new AlphaCardIdentifier(caseId, cardId)); if (card == null) { this.saveError(request, this.getText("card.invalidId", locale)); return this.getCancelView(); } final Adornment contributor = card.getAlphaCardDescriptor() .getAdornment(AdornmentType.Contributor.getName()); if ((contributor.getValue() == null) || contributor.getValue().isEmpty()) { this.saveError(request, this.getText("adornment.noAccess", locale)); return this.getCancelView(); } 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 this.getCancelView(); } } if (request.getParameter("cancel") != null) return this.getCancelView(); if (this.validator != null) { // validator is null during testing fileUpload.setName("alphaCardPayloadFile"); this.validator.validate(fileUpload, errors); if (errors.hasErrors()) return "redirect:/cardfileupload?card=" + cardId + "&case=" + caseId; } // validate a file was entered if (fileUpload.getFile().length == 0) { final Object[] args = new Object[] { this.getText("uploadForm.file", request.getLocale()) }; errors.rejectValue("file", "errors.required", args, "File"); return "redirect:/cardfileupload?card=" + cardId + "&case=" + caseId; } final MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request; final MultipartFile file = multipartRequest.getFile("file"); Payload payload = new Payload(file.getOriginalFilename(), file.getContentType()); payload.setContent(file.getBytes()); payload = this.payloadManager.saveNewPayload(payload, card); this.saveMessage(request, this.getText("card.payloadOK", locale)); return this.getSuccessView(); }
From source file:fr.paris.lutece.portal.web.xpages.SiteMapApp.java
/** * Build or get in the cache the page which contains the site map depending * on the mode//from w ww .ja v a2 s . c om * * @param request The Http request * @param nMode The selected mode * @param plugin The plugin * @return The content of the site map */ @Override public XPage getPage(HttpServletRequest request, int nMode, Plugin plugin) { XPage page = new XPage(); String strKey = getKey(nMode, request); Locale locale = request.getLocale(); SiteMapCacheService siteMapCacheService = SiteMapCacheService.getInstance(); // Check the key in the cache String strCachedPage = siteMapCacheService.isCacheEnable() ? (String) siteMapCacheService.getFromCache(strKey) : null; if (strCachedPage == null) { // Build the HTML document String strPage = buildPageContent(nMode, request); // Add it to the cache if (siteMapCacheService.isCacheEnable()) { synchronized (strKey) { siteMapCacheService.putInCache(strKey, strPage); } } page.setPathLabel(I18nService.getLocalizedString(PROPERTY_PATH_LABEL, locale)); page.setTitle(I18nService.getLocalizedString(PROPERTY_PAGE_TITLE, locale)); page.setContent(strPage); return page; } // The document exist in the cache page.setPathLabel(I18nService.getLocalizedString(PROPERTY_PATH_LABEL, locale)); page.setTitle(I18nService.getLocalizedString(PROPERTY_PAGE_TITLE, locale)); page.setContent(strCachedPage); return page; }
From source file:alpha.portal.webapp.controller.PayloadVersionsController.java
/** * shows the list of payload versions./*from www . j a v a 2 s . c om*/ * * @param request * the request * @return ModelView * @throws Exception * the exception */ @RequestMapping(method = RequestMethod.GET) public ModelAndView handleRequest(final HttpServletRequest request) throws Exception { final ModelAndView returnMaV = new ModelAndView(); final User currentUser = this.getUserManager().getUserByUsername(request.getRemoteUser()); final Locale locale = request.getLocale(); if ((request.getParameter("card") == null) || (request.getParameter("case") == null)) { this.saveError(request, this.getText("payloadVersions.cardNotFound", locale)); returnMaV.addObject("isErrors", true); return returnMaV; } final String cardId = request.getParameter("card"); final String caseId = request.getParameter("case"); final AlphaCard currentCard = this.alphaCardManager.get(new AlphaCardIdentifier(caseId, cardId)); if (currentCard == null) { this.saveError(request, this.getText("payloadVersions.cardNotFound", locale)); returnMaV.addObject("isErrors", true); return returnMaV; } Long cardContributor = null; try { cardContributor = Long.parseLong(currentCard.getAlphaCardDescriptor() .getAdornment(AdornmentType.Contributor.getName()).getValue()); } catch (final NumberFormatException e) { cardContributor = 0L; } final Long currentUserId = currentUser.getId(); if (cardContributor != currentUserId) { this.saveError(request, this.getText("adornment.noAccess", locale)); returnMaV.addObject("isErrors", true); return returnMaV; } final List<Payload> payloads = this.payloadManager.getAllVersions(currentCard.getPayload()); if (payloads.size() < 1) { this.saveError(request, this.getText("payloadVersions.noPayloads", locale)); returnMaV.addObject("isErrors", true); return returnMaV; } returnMaV.addObject("payloadList", payloads); returnMaV.addObject("cardName", currentCard.getAlphaCardDescriptor().getTitle()); returnMaV.addObject("caseId", currentCard.getAlphaCardIdentifier().getCaseId()); returnMaV.addObject("cardId", currentCard.getAlphaCardIdentifier().getCardId()); return returnMaV; }
From source file:it.cilea.osd.jdyna.web.controller.TypeController.java
protected ModelAndView handleDelete(HttpServletRequest request) { Map<String, Object> model = new HashMap<String, Object>(); String typeId = request.getParameter("id"); Integer paramTypeId = Integer.valueOf(typeId); try {/*from w w w .j av a 2s .co m*/ applicationService.delete(tpModel, paramTypeId); saveMessage(request, getText("action.tipologia.deleted", request.getLocale())); } catch (Exception e) { saveMessage(request, getText("action.tipologia.deleted.noSuccess", request.getLocale())); } return new ModelAndView(getListView(), model); }
From source file:org.openmrs.contrib.metadatarepository.webapp.controller.PackageFormController.java
@RequestMapping(method = RequestMethod.POST) public String onSubmit(MetadataPackage pkg, BindingResult errors, HttpServletRequest request, HttpServletResponse response, ModelMap model) throws Exception { if (request.getParameter("cancel") != null) { return getCancelView(); }//www . j av a 2 s . c o m log.debug("entering 'onSubmit' method..."); String success = getSuccessView(); Locale locale = request.getLocale(); if (request.getParameter("delete") != null) { packageManager.remove(pkg.getId()); packageManager.deleteFile(pkg.getId() + ""); saveMessage(request, getText("package.deleted", locale)); } else { saveMessage(request, getText("package.saved", locale)); MetadataPackage metadataPackage = packageManager.get(pkg.getId()); metadataPackage.setName(pkg.getName()); metadataPackage.setDescription(pkg.getDescription()); packageManager.save(metadataPackage); model.addAttribute("metadataPackage", metadataPackage); } return success + "?id=" + pkg.getId(); }