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:dtu.ds.warnme.ws.rest.json.AbstractRestWS.java
@ExceptionHandler(ServiceException.class) @ResponseBody// w w w . java2 s . c o m String handleServiceExceptions(Exception ex, HttpServletRequest request, HttpServletResponse response) { log.info(ex.getMessage(), ex); response.setStatus(HttpServletResponse.SC_FORBIDDEN); String responseBody = getMessage(ex, request.getLocale()); RestUtils.decorateResponseHeaderWithMD5(response, responseBody); RestUtils.decorateResponseHeaderForJsonContentType(response); return responseBody; }
From source file:dtu.ds.warnme.ws.rest.json.AbstractRestWS.java
@ExceptionHandler({ BadRequestException.class, MissingServletRequestParameterException.class }) @ResponseBody/* w w w . j a va 2s. c o m*/ String handleBadRequestExceptions(Exception ex, HttpServletRequest request, HttpServletResponse response) { log.info(ex.getMessage(), ex); response.setStatus(HttpServletResponse.SC_BAD_REQUEST); String responseBody = getMessage(ex, request.getLocale()); RestUtils.decorateResponseHeaderWithMD5(response, responseBody); RestUtils.decorateResponseHeaderForJsonContentType(response); return responseBody; }
From source file:alpha.portal.webapp.controller.ContributorRoleController.java
/** * Show list of user roles./*from w ww .j a v a2 s.c om*/ * * @param request * The http-request parameters * @return Possible object names: contributorRolesList, messageId, * showEditingForm, roleToEdit * @throws Exception * the exception */ @RequestMapping(method = RequestMethod.GET) public ModelAndView showPage(final HttpServletRequest request) throws Exception { final Locale locale = request.getLocale(); final ModelAndView returnData = new ModelAndView(); if (request.getParameter("delete") != null) { final Long roleToDelete = new Long(request.getParameter("delete")); if (this.contributorRoleManager.exists(roleToDelete)) { try { this.contributorRoleManager.remove(roleToDelete); this.saveMessage(request, this.getText("contributorRoles.del_success", locale)); } catch (final DataIntegrityViolationException e) { this.saveError(request, this.getText("contributorRoles.del_in_use", locale)); } } else { this.saveError(request, this.getText("contributorRoles.del_err", locale)); } } if (request.getParameter("edit") != null) { final Long roleId = new Long(request.getParameter("edit")); if (this.contributorRoleManager.exists(roleId)) { final ContributorRole roleObj = this.contributorRoleManager.get(roleId); returnData.addObject("showEditingForm", true); returnData.addObject("roleToEditId", request.getParameter("edit")); returnData.addObject("roleToEdit", new String(roleObj.getName())); } } if (request.getParameter("edit") == null) { final List<ContributorRole> contribList = this.contributorRoleManager.getAll(); returnData.addObject("contributorRolesList", contribList); } return returnData; }
From source file:org.openmrs.contrib.metadatarepository.webapp.controller.FileUploadController.java
@RequestMapping(method = RequestMethod.POST) public String onSubmit(MetadataPackage metadataPackage, BindingResult errors, HttpServletRequest request) throws Exception { if (request.getParameter("cancel") != null) { return getCancelView(); }//from w ww . ja v a2s . c o m Locale locale = request.getLocale(); if (validator != null) { // validator is null during testing validator.validate(metadataPackage, errors); if (errors.hasErrors()) { return "packageupload"; } } // validate a file was entered if (metadataPackage.getFile().length == 0) { Object[] args = new Object[] { getText("uploadForm.file", request.getLocale()) }; errors.rejectValue("file", "errors.required", args, "File"); return "packageupload"; } saveMessage(request, getText("package.uploaded", locale)); User uname; log.debug("" + userManager.getUserByUsername(request.getRemoteUser())); uname = userManager.getUserByUsername(request.getRemoteUser()); // Deserializing the package MetadataPackage pkg = packageManager.deserializePackage(metadataPackage.getFile()); metadataPackage.setUser(uname); metadataPackage.setFields(pkg); MetadataPackage meta = packageManager.savePackage(metadataPackage); Long id = meta.getId(); return getSuccessView() + "?id=" + meta.getId(); }
From source file:com.stimulus.struts.BaseBean.java
protected Locale getLocale() { Locale locale = Locale.getDefault(); String country = locale.getCountry(); ActionContext context = ActionContext.getActionContext(); if (context != null) { HttpServletRequest request = context.getRequest(); if (request != null) locale = request.getLocale(); }//from ww w.ja va 2 s . c o m if (locale.getCountry().length() < 1 && locale.getLanguage().length() > 0) { locale = new Locale(locale.getLanguage(), Locale.getDefault().getCountry()); } String country2 = locale.getCountry(); //if (locale.getCountry().equalsIgnoreCase("ZA")) // locale = Locale.UK; // bug in JVM concerning date formatting in South Africa return locale; }
From source file:fr.paris.lutece.plugins.unittree.modules.profiles.web.unit.ProfilesUnitUserAttributeComponent.java
/** * {@inheritDoc}/* w w w . ja v a2 s.co m*/ */ @Override public void fillModel(HttpServletRequest request, Map<String, Object> model) { List<IAttribute> listAttributes = AttributeService.getInstance() .getPluginAttributesWithFields(ProfilesPlugin.PLUGIN_NAME, request.getLocale()); String strIdUser = request.getParameter(PARAMETER_ID_USER); if (StringUtils.isNotBlank(strIdUser) && StringUtils.isNumeric(strIdUser) && (listAttributes != null) && !listAttributes.isEmpty()) { int nIdUser = Integer.parseInt(strIdUser); Map<String, Object> map = AdminUserFieldService.getAdminUserFields(listAttributes, nIdUser, request.getLocale()); model.put(MARK_MAP_LIST_ATTRIBUTE_DEFAULT_VALUES, map); } model.put(MARK_ATTRIBUTES_LIST, listAttributes); model.put(MARK_LOCALE, request.getLocale()); }
From source file:alpha.portal.webapp.controller.ContributorRoleController.java
/** * Create new role.//w w w . ja va 2 s. c o m * * @param request * the request * @param response * the response * @return the string */ @RequestMapping(method = RequestMethod.POST, params = { "save_new" }) public String saveNew(final HttpServletRequest request, final HttpServletResponse response) { final Locale locale = request.getLocale(); final String newRoleName = request.getParameter("newContributorRole"); if ((newRoleName == null) || newRoleName.isEmpty()) { this.saveError(request, this.getText("contributorRoles.add_err_empty", locale)); } else if (this.contributorRoleManager.getContributorRoleByName(newRoleName) != null) { this.saveError(request, this.getText("contributorRoles.add_err_exists", locale)); } else { ContributorRole newRole = new ContributorRole(newRoleName); newRole = this.contributorRoleManager.save(newRole); System.out.println(newRole.toString()); this.saveMessage(request, this.getText("contributorRoles.add_success", locale)); } return "redirect:/contributorRole"; }
From source file:ips1ap101.lib.base.bundle.ResourceBundleHandler.java
private Locale getRequestLocale() { HttpServletRequest request = JSF.getRequest(); return request == null ? null : request.getLocale(); }
From source file:alpha.portal.webapp.controller.PayloadVersionsController.java
/** * Gets the payload.//from w ww .j ava 2s . co m * * @param request * the request * @param response * the response * @return the payload * @throws IOException * Signals that an I/O exception has occurred. */ @RequestMapping(method = RequestMethod.GET, params = { "seqNumber" }) public String getPayload(final HttpServletRequest request, final HttpServletResponse response) throws IOException { final Locale locale = request.getLocale(); if ((request.getParameter("card") == null) || (request.getParameter("case") == null)) { this.saveError(request, this.getText("payloadVersions.cardNotFound", locale)); return ""; } final String cardId = request.getParameter("card"); final String caseId = request.getParameter("case"); final AlphaCard currentCard = this.alphaCardManager.get(new AlphaCardIdentifier(caseId, cardId)); final Payload payload = this.payloadManager .getVersion(new PayloadIdentifier(currentCard.getPayload().getPayloadIdentifier().getPayloadId(), Long.parseLong(request.getParameter("seqNumber")))); if (payload != null) { final BufferedInputStream in = new BufferedInputStream(new ByteArrayInputStream(payload.getContent())); response.setBufferSize(payload.getContent().length); response.setContentType(payload.getMimeType()); response.setHeader("Content-Disposition", "attachment; filename=\"" + payload.getFilename() + "\""); response.setContentLength(payload.getContent().length); FileCopyUtils.copy(in, response.getOutputStream()); in.close(); response.getOutputStream().flush(); response.getOutputStream().close(); } return "redirect:/payloadVersions?case=" + currentCard.getAlphaCardIdentifier().getCaseId() + "&card=" + currentCard.getAlphaCardIdentifier().getCardId(); }
From source file:com.ibm.ids.example.ShowResult.java
public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException { String safename = StringEscapeUtils.escapeHtml4(request.getParameter("name")); Locale locale = request.getLocale(); ResourceBundle messages = ResourceBundle.getBundle("com.ibm.ids.example.Messages", locale); response.setContentType("text/html"); PrintWriter out = response.getWriter(); // log what we received in a vulnerable way try {// w w w .j av a 2s. c o m writeToVulnerableSink(getVulnerableSource(safename)); } catch (Exception e) { // ignore this, we're just logging, right? } out.println("<HTML><HEAD><TITLE>Hello World</TITLE></HEAD><BODY>"); if (safename == null) { String nobody = messages.getString("nobody"); out.println(nobody); } else { out.println("Hello, " + safename); } out.println("</BODY></HTML>"); }