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.helpdesk.web.HelpdeskApp.java
/** * Returns the Helpdesk XPage content depending on the request parameters and the current mode. * * @param request The HTTP request.//from w w w . ja v a2 s. co m * @param nMode The current mode. * @param plugin The plugin. * @return The page content. * @throws SiteMessageException The Site message exception */ public XPage getPage(HttpServletRequest request, int nMode, Plugin plugin) throws SiteMessageException { XPage page = new XPage(); String strContact = request.getParameter(PARAMETER_CONTACT); String strIdFaq = request.getParameter(PARAMETER_FAQ_ID); // Check if faq_id is specified if ((strIdFaq == null) || !strIdFaq.matches(REGEX_ID)) { page.setContent(getFaqList(request, plugin)); page.setPathLabel(I18nService.getLocalizedString(MESSAGE_HELPDESK_PATH_LABEL, request.getLocale())); page.setTitle(I18nService.getLocalizedString(MESSAGE_FAQ_LIST, request.getLocale())); return page; } // Check if faq exists and user have access int nIdFaq = Integer.parseInt(strIdFaq); Faq faq = FaqHome.load(nIdFaq, plugin); if (faq == null) { SiteMessageService.setMessage(request, MESSAGE_ACCESS_DENIED, SiteMessage.TYPE_STOP); } if (SecurityService.isAuthenticationEnable()) { LuteceUser user = SecurityService.getInstance().getRegisteredUser(request); if (!faq.getRoleKey().equals(Faq.ROLE_NONE) && ((user == null) || !SecurityService.getInstance().isUserInRole(request, faq.getRoleKey()))) { SiteMessageService.setMessage(request, MESSAGE_ACCESS_DENIED, SiteMessage.TYPE_STOP); } } // generate pages if ((strContact != null) && strContact.equals(PARAMETER_CONTACT)) { page.setContent(getContactForm(request, plugin, faq)); page.setPathLabel(I18nService.getLocalizedString(MESSAGE_HELPDESK_PATH_LABEL, request.getLocale())); page.setTitle(I18nService.getLocalizedString(MESSAGE_SUBJECT_LIST, request.getLocale())); } else if ((strContact != null) && strContact.equals(PARAMETER_CONTACT_RESULT)) { page.setContent(getContactFormResult(request, faq)); page.setPathLabel(I18nService.getLocalizedString(MESSAGE_HELPDESK_PATH_LABEL, request.getLocale())); page.setTitle(I18nService.getLocalizedString(MESSAGE_SUBJECT_LIST, request.getLocale())); } else { page.setContent(getSubjectListSearch(request, plugin, faq)); page.setPathLabel(I18nService.getLocalizedString(MESSAGE_HELPDESK_PATH_LABEL, request.getLocale())); page.setTitle(I18nService.getLocalizedString(MESSAGE_SUBJECT_LIST_RESULTS, request.getLocale())); } return page; }
From source file:com.criticalsoftware.mobics.presentation.extension.DefaultExceptionHandler.java
/** * Send the user to the global error page. * //from ww w . j a va2s . com * @param sourcePageNotFoundException when someone needs the source page resolution, but no source page was supplied * in the request * @param request The HttpServletRequest * @param response The HttpServletResponse * @return A ForwardResolution */ public Resolution handle(SourcePageNotFoundException sourcePageNotFoundException, HttpServletRequest request, HttpServletResponse response) { LOGGER.warn(sourcePageNotFoundException.getMessage()); ActionBean bean = (ActionBean) request.getAttribute(StripesConstants.REQ_ATTR_ACTION_BEAN); if (bean != null && bean.getContext().getValidationErrors() != null) { for (Entry<String, List<ValidationError>> validationErrors : bean.getContext().getValidationErrors() .entrySet()) { for (ValidationError validationError : validationErrors.getValue()) { LOGGER.warn(validationError.getMessage(request.getLocale())); } } } return new ForwardResolution("/WEB-INF/error.jsp"); }
From source file:fr.paris.lutece.plugins.extend.modules.actionhit.web.component.ActionHitResourceExtenderComponent.java
/** * {@inheritDoc}//from w ww.jav a2 s . c o m */ @Override public String getPageAddOn(String strIdExtendableResource, String strExtendableResourceType, String strParameters, HttpServletRequest request) { // Method to get the html code of the extension in front office ActionHit actionsHit; String strActionName = getActionNameFromParameters(strParameters); // If there is no action name, we return an empty string if (strActionName == null) { return StringUtils.EMPTY; } actionsHit = _actionHitService.findActionHit(strActionName, strIdExtendableResource, strExtendableResourceType); if (actionsHit == null) { // If no action hit was found, we create a new one with 0 hit actionsHit = new ActionHit(strActionName, strIdExtendableResource, strExtendableResourceType, 0); } Map<String, Object> model = new HashMap<String, Object>(); model.put(MARK_ACTION_HIT, actionsHit); HtmlTemplate template = AppTemplateService.getTemplate(TEMPLATE_ACTION_HIT, request.getLocale(), model); return template.getHtml(); }
From source file:com.haulmont.cuba.web.sys.CubaApplicationServlet.java
protected Locale resolveLocale(HttpServletRequest req, Messages messages, GlobalConfig globalConfig) { Map<String, Locale> locales = globalConfig.getAvailableLocales(); if (globalConfig.getLocaleSelectVisible()) { String lastLocale = getCookieValue(req, "LAST_LOCALE"); if (lastLocale != null) { for (Locale locale : locales.values()) { if (locale.toLanguageTag().equals(lastLocale)) { return locale; }/* w w w . jav a 2s.c om*/ } } } Locale requestLocale = req.getLocale(); if (requestLocale != null) { Locale requestTrimmedLocale = messages.getTools().trimLocale(requestLocale); if (locales.containsValue(requestTrimmedLocale)) { return requestTrimmedLocale; } // if not found and application locale contains country, try to match by language only if (!StringUtils.isEmpty(requestLocale.getCountry())) { Locale appLocale = Locale.forLanguageTag(requestLocale.getLanguage()); for (Locale locale : locales.values()) { if (Locale.forLanguageTag(locale.getLanguage()).equals(appLocale)) { return locale; } } } } return messages.getTools().getDefaultLocale(); }
From source file:org.openmrs.module.diabetesmanagement.web.controller.PatientObsFormController.java
/** * @see org.springframework.web.servlet.mvc.SimpleFormController#referenceData(javax.servlet.http.HttpServletRequest, * java.lang.Object, org.springframework.validation.BindException) * @param request Current HTTP request.// w w w .ja v a 2 s. c o m * @param command Form object with request parameters bound onto it. * @param errors Validation errors holder. * @return A Map with reference data entries, or null if none. * @throws Exception In case of invalid state or arguments. */ protected Map<String, Object> referenceData(HttpServletRequest request, Object command, Errors errors) throws Exception { Obs obs = (Obs) command; String conceptName = request.getParameter("conceptName"); Map<String, Object> map = new HashMap<String, Object>(); String defaultVerbose = "false"; if (Context.isAuthenticated() && Context.hasPrivilege("Add Own Observations")) { if (obs.getConcept() != null) // Cannot just do 'obs.getConcept().getBestName(request.getLocale())' anymore // (LazyInitException) map.put("conceptName", Context.getConceptService().getConcept(obs.getConcept().getConceptId()) .getBestName(request.getLocale())); defaultVerbose = Context.getAuthenticatedUser() .getUserProperty(OpenmrsConstants.USER_PROPERTY_SHOW_VERBOSE); } map.put("defaultVerbose", defaultVerbose.equals("true") ? true : false); String editReason = request.getParameter("editReason"); if (editReason == null) editReason = ""; map.put("editReason", editReason); // Adding concept if name has been passed if (conceptName != null && conceptName.length() > 0) { if (conceptName.equals("weight")) { String conceptIdWeight = Context.getAdministrationService().getGlobalProperty("concept.weight"); if (conceptIdWeight != null && conceptIdWeight.length() > 0) map.put("selectedConcept", Context.getConceptService().getConcept(Integer.valueOf(conceptIdWeight))); } else { DiabetesManagementConfig config = new DiabetesManagementConfig(); map.put("selectedConcept", config.getRelevantConcepts().get(conceptName)); } } // Adding list of unresolved problems try { Context.addProxyPrivilege(OpenmrsConstants.PRIV_VIEW_PATIENTS); Context.addProxyPrivilege(OpenmrsConstants.PRIV_VIEW_USERS); Context.addProxyPrivilege(OpenmrsConstants.PRIV_VIEW_PERSON_ATTRIBUTE_TYPES); Context.addProxyPrivilege("View Problems"); Patient patient = Context.getPatientService().getPatient(Context.getAuthenticatedUser().getPersonId()); if (patient != null) { List<Problem> problems = ((ProblemService) Context.getService(ProblemService.class)) .getOpenProblemsByPatient(patient); map.put("problemList", problems); } } finally { Context.removeProxyPrivilege(OpenmrsConstants.PRIV_VIEW_PATIENTS); Context.removeProxyPrivilege(OpenmrsConstants.PRIV_VIEW_USERS); Context.removeProxyPrivilege(OpenmrsConstants.PRIV_VIEW_PERSON_ATTRIBUTE_TYPES); Context.removeProxyPrivilege("View Problems"); } String datePattern = OpenmrsUtil.getDateFormat().toPattern() + " HH:mm"; map.put("datePattern", datePattern); String datePatternNoSeparators = datePattern.replace("/", ""); datePatternNoSeparators = datePatternNoSeparators.replace("-", ""); datePatternNoSeparators = datePatternNoSeparators.replace(".", ""); map.put("datePatternNoSeparators", datePatternNoSeparators); return map; }
From source file:com.hp.avmon.kpigetconfig.web.KpigetconfigAgentController.java
@RequestMapping("saveIloHost") public String saveIloHost(HttpServletResponse response, HttpServletRequest request) { String data = ""; Locale locale = request.getLocale(); ResourceBundle bundle = ResourceBundle.getBundle("messages", locale); try {/*from w w w. ja va 2 s .c om*/ data = agentManageService.saveIloHost(request); //data="{success:true,msg:" + msg + "}"; } catch (Exception e) { e.printStackTrace(); logger.error(this.getClass().getName() + " saveIloHost", e); data = "{success:false,msg:'" + bundle.getString("saveFail") + "'}"; } return Utils.responsePrintWrite(response, data, null); }
From source file:org.inbio.modeling.web.controller.ExportController.java
@Override protected ModelAndView processFormSubmission(HttpServletRequest request, HttpServletResponse response, Object command, BindException errors) { HttpSession session = null;//from w ww . java2s.c om String type = null; if (errors.hasErrors()) return showForm(request, response, errors); CurrentInstanceData currentInstanceData = null; ExportData exportForm = (ExportData) command; // retrieve the type. type = exportForm.getType(); // retrieve the session Information. session = request.getSession(); currentInstanceData = SessionUtils.isSessionAlive(session); if (currentInstanceData != null) { if (exportForm.getType().equals("PDF")) { // PDF File try { this.exportPDF(currentInstanceData, response, request.getLocale()); } catch (Exception ex) { ex = new Exception("errors.cantExportPDF", ex); Logger.getLogger(ColumnController.class.getName()).log(Level.SEVERE, null, ex); errors.reject(ex.getMessage()); return showForm(request, response, errors); } } else if (exportForm.getType().equals("SHP")) { // Shapefile try { response = this.exportShapefile(currentInstanceData, response); } catch (Exception ex) { ex = new Exception("errors.cantExportShape", ex); Logger.getLogger(ColumnController.class.getName()).log(Level.SEVERE, null, ex); errors.reject(ex.getMessage()); return showForm(request, response, errors); } } else { // PNG try { response = this.exportImage(currentInstanceData, response); } catch (Exception ex) { ex = new Exception("errors.cantExportImage", ex); Logger.getLogger(ColumnController.class.getName()).log(Level.SEVERE, null, ex); errors.reject(ex.getMessage()); return showForm(request, response, errors); } } } else { Exception ex = new Exception("errors.noSession"); Logger.getLogger(ColumnController.class.getName()).log(Level.SEVERE, null, ex); errors.reject(ex.getMessage()); return showForm(request, response, errors); } return showMapControllerImpl.showForm(request, response, errors); }
From source file:com.hp.avmon.kpigetconfig.web.KpigetconfigAgentController.java
@RequestMapping("deleteIloHostByIps") public String deleteIloHostByIps(HttpServletResponse response, HttpServletRequest request) { String data = ""; Locale locale = request.getLocale(); ResourceBundle bundle = ResourceBundle.getBundle("messages", locale); try {// w ww.j ava 2 s. com String agentId = request.getParameter("agentId"); String ampInstId = request.getParameter("ampInstId"); String ips = request.getParameter("ips"); agentManageService.deleteIloHostByIps(agentId, ampInstId, ips); data = "{success:true,msg:'" + bundle.getString("deleteSuccess") + "'}"; } catch (Exception e) { e.printStackTrace(); logger.error(this.getClass().getName() + " deleteIloHostByIps", e); data = "{success:false,msg:'" + bundle.getString("deleteFail") + "'}"; } return Utils.responsePrintWrite(response, data, null); }
From source file:com.hp.avmon.kpigetconfig.web.KpigetconfigAgentController.java
/** * ""// w ww .j a v a 2 s.com * @param response * @param request * @return */ @RequestMapping("deleteVmHost") public String deleteVmHost(HttpServletResponse response, HttpServletRequest request) { String data = ""; Locale locale = request.getLocale(); ResourceBundle bundle = ResourceBundle.getBundle("messages", locale); try { String agentId = request.getParameter("agentId"); String ampInstId = request.getParameter("ampInstId"); String objIds = request.getParameter("objIds"); agentManageService.deleteVmHost(agentId, ampInstId, objIds); data = "{success:true,msg:'" + bundle.getString("removeSuccess") + "'}"; } catch (Exception e) { e.printStackTrace(); logger.error(this.getClass().getName() + " deleteVmHost", e); data = "{success:false,msg:'" + bundle.getString("removeFail") + "'}"; } return Utils.responsePrintWrite(response, data, null); }
From source file:se.vgregion.portal.requestlogger.RequestLoggerController.java
private Map<String, String> getRequestInfo(PortletRequest request) { Map<String, String> requestResult = new TreeMap<String, String>(); HttpServletRequest httpRequest = PortalUtil.getHttpServletRequest(request); requestResult.put("RemoteUser", httpRequest.getRemoteUser()); requestResult.put("P3P.USER_LOGIN_ID", getRemoteUserId(request)); requestResult.put("RemoteAddr", httpRequest.getRemoteAddr()); requestResult.put("RemoteHost", httpRequest.getRemoteHost()); requestResult.put("RemotePort", String.valueOf(httpRequest.getRemotePort())); requestResult.put("AuthType", httpRequest.getAuthType()); requestResult.put("CharacterEncoding", httpRequest.getCharacterEncoding()); requestResult.put("ContentLength", String.valueOf(httpRequest.getContentLength())); requestResult.put("ContentType", httpRequest.getContentType()); requestResult.put("ContextPath", httpRequest.getContextPath()); requestResult.put("LocalAddr", httpRequest.getLocalAddr()); requestResult.put("Locale", httpRequest.getLocale().toString()); requestResult.put("LocalName", httpRequest.getLocalName()); requestResult.put("LocalPort", String.valueOf(httpRequest.getLocalPort())); requestResult.put("Method", httpRequest.getMethod()); requestResult.put("PathInfo", httpRequest.getPathInfo()); requestResult.put("PathTranslated", httpRequest.getPathTranslated()); requestResult.put("Protocol", httpRequest.getProtocol()); requestResult.put("QueryString", httpRequest.getQueryString()); requestResult.put("RequestedSessionId", httpRequest.getRequestedSessionId()); requestResult.put("RequestURI", httpRequest.getRequestURI()); requestResult.put("Scheme", httpRequest.getScheme()); requestResult.put("ServerName", httpRequest.getServerName()); requestResult.put("ServerPort", String.valueOf(httpRequest.getServerPort())); requestResult.put("ServletPath", httpRequest.getServletPath()); return requestResult; }