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:mx.edu.um.mateo.rh.web.EstudiosEmpleadoController.java
private void enviaCorreo(String tipo, List<EstudiosEmpleado> estudiosEmpleados, HttpServletRequest request) throws JRException, MessagingException { log.debug("Enviando correo {}", tipo); byte[] archivo = null; String tipoContenido = null;//from www.j a va 2s . c om switch (tipo) { case "PDF": archivo = generaPdf(estudiosEmpleados); tipoContenido = "application/pdf"; break; case "CSV": archivo = generaCsv(estudiosEmpleados); tipoContenido = "text/csv"; break; case "XLS": archivo = generaXls(estudiosEmpleados); tipoContenido = "application/vnd.ms-excel"; } MimeMessage message = mailSender.createMimeMessage(); MimeMessageHelper helper = new MimeMessageHelper(message, true); helper.setTo(ambiente.obtieneUsuario().getUsername()); String titulo = messageSource.getMessage("estudiosEmpleado.lista.label", null, request.getLocale()); helper.setSubject(messageSource.getMessage("envia.correo.titulo.message", new String[] { titulo }, request.getLocale())); helper.setText(messageSource.getMessage("envia.correo.contenido.message", new String[] { titulo }, request.getLocale()), true); helper.addAttachment(titulo + "." + tipo, new ByteArrayDataSource(archivo, tipoContenido)); mailSender.send(message); }
From source file:com.flexive.shared.FxContext.java
/** * Stores the needed informations about the sessions. * * @param request the users request * @param dynamicContent is the content dynamic? * @param divisionId the division id * @param isWebdav true if this is an webdav request * @return FxContext//from w w w.j a v a 2 s. c o m */ public static FxContext storeInfos(HttpServletRequest request, boolean dynamicContent, int divisionId, boolean isWebdav) { FxContext si = storeEmptyContext(request, divisionId, isWebdav, true); // Do user ticket retrieval and store it in the threadlocal final HttpSession session = request.getSession(); if (session.getAttribute(SESSION_DIVISIONID) == null) { session.setAttribute(SESSION_DIVISIONID, divisionId); } if (dynamicContent || isWebdav) { UserTicket last = getLastUserTicket(session); // Always determine the current user ticket for dynamic pages and webdav requests. // This takes about 1 x 5ms for every request on a development machine si.setTicket(getTicketFromEJB(session)); if (si.ticket.isGuest()) { try { final FxLanguage language; if (last == null) { if (CacheAdmin.isNewInstallation()) { language = EJBLookup.getLanguageEngine().load(request.getLocale().getLanguage()); } else { language = CacheAdmin.getEnvironment().getLanguage(request.getLocale().getLanguage()); } } else { language = last.getLanguage(); } si.ticket.setLanguage(language); setLastUserTicket(session, si.ticket); // refresh ticket with new language } catch (Exception e) { if (LOG.isDebugEnabled()) { LOG.debug("Failed to use request locale from browser - unknown language: " + request.getLocale().getLanguage() + " - " + e.getMessage(), e); } } } } else { // For static content like images we use the last user ticket stored in the session // to speed up the request. si.setTicket(getLastUserTicket(session)); if (si.ticket != null) { if (si.ticket.isGuest() && (si.ticket.getACLAssignments() == null || si.ticket.getACLAssignments().length == 0)) { //reload from EJB layer if we have a guest ticket with no ACL assignments //this can happen during initial loading si.setTicket(getTicketFromEJB(session)); } } if (si.ticket == null) { si.setTicket(getTicketFromEJB(session)); } } setThreadLocal(si); return si; }
From source file:fr.paris.lutece.plugins.directory.modules.rest.service.DirectoryRestService.java
/** * {@inheritDoc}/*from w ww .j a v a 2 s. c o m*/ */ @Override public List<Record> getRecordsList(int nIdDirectory, HttpServletRequest request) throws DirectoryRestException, DirectoryErrorException { Directory directory = getDirectory(nIdDirectory); Plugin pluginDirectory = PluginService.getPlugin(DirectoryPlugin.PLUGIN_NAME); DirectoryAdminSearchFields searchFields = new DirectoryAdminSearchFields(); Enumeration paramNames = request.getParameterNames(); HashMap<String, List<RecordField>> mapQuery = null; if (paramNames.hasMoreElements()) { mapQuery = DirectoryUtils.getSearchRecordData(request, nIdDirectory, DirectoryUtils.getPlugin(), request.getLocale()); } searchFields.setMapQuery(mapQuery); searchFields.setSortParameters(request, directory, pluginDirectory); boolean bWorkflowServiceEnable = WorkflowService.getInstance().isAvailable(); List<Record> listRecords = null; List<Integer> listIdsEntry = getIdsEntry(nIdDirectory, request); List<Integer> listIdsRecord = DirectoryUtils.getListResults(request, directory, bWorkflowServiceEnable, true, searchFields, null, request.getLocale()); listRecords = new ArrayList<Record>(); Map<Integer, Field> mapFieldEntry = getMapFieldEntryByListIdEntry(listIdsEntry); if (listIdsRecord != null) { int nMaxNumber = AppPropertiesService.getPropertyInt(DirectoryRestConstants.PROPERTY_MAX_NUMBER_RECORDS, 100); for (int i = 0; (i < nMaxNumber) && (i < listIdsRecord.size()); i++) { int nIdRecord = listIdsRecord.get(i); Record record = getRecord(nIdRecord, listIdsEntry, mapFieldEntry); listRecords.add(record); } } return listRecords; }
From source file:it.cilea.osd.jdyna.web.controller.FormAnagraficaWithoutAreeController.java
@Override protected ModelAndView onSubmit(HttpServletRequest request, HttpServletResponse response, Object object, BindException errors) throws Exception { AnagraficaObjectDTO anagraficaObjectDTO = (AnagraficaObjectDTO) object; if (request.getParameter("cancel") != null) { return new ModelAndView(getListView()); }/*from w w w . ja v a2 s. c om*/ EO anagraficaObject; List<TP> tipProprieta; if (anagraficaObjectDTO.getObjectId() != null) { anagraficaObject = applicationService.get(clazzAnagraficaObject, anagraficaObjectDTO.getObjectId()); tipProprieta = applicationService.getList(clazzTipologiaProprieta); } else { anagraficaObject = clazzAnagraficaObject.newInstance(); tipProprieta = applicationService.getTipologiaOnCreation(clazzTipologiaProprieta); } AnagraficaUtils.reverseDTO(anagraficaObjectDTO, anagraficaObject, tipProprieta); anagraficaObject.pulisciAnagrafica(); applicationService.saveOrUpdate(clazzAnagraficaObject, anagraficaObject); saveMessage(request, getText("action.anagrafica.edited", request.getLocale())); return new ModelAndView(getDetailsView(), "id", anagraficaObject.getId()); }
From source file:fr.paris.lutece.plugins.mydashboard.web.MyDashboardApp.java
/** * Get the XPage to modify front office dash boards of the current user * @param request The request/*w w w. j a v a 2 s . c o m*/ * @return The XPage to display * @throws UserNotSignedException If the user has not signed in */ @View(VIEW_GET_MODIFY_DASHBOARDS) public XPage getModifyDashboards(HttpServletRequest request) throws UserNotSignedException { LuteceUser luteceUser = SecurityService.isAuthenticationEnable() ? SecurityService.getInstance().getRegisteredUser(request) : null; if (luteceUser == null) { throw new UserNotSignedException(); } MyDashboardService dashboardService = MyDashboardService.getInstance(); Map<String, Object> model = new HashMap<String, Object>(); List<MyDashboardConfiguration> listDashboardConfig = dashboardService.getUserConfig(luteceUser); List<IMyDashboardComponent> listDashboardComponents = dashboardService .getMyDashboardComponentsList(luteceUser); Map<String, String> mapComponentsDescription = new HashMap<String, String>(listDashboardComponents.size()); for (IMyDashboardComponent component : listDashboardComponents) { mapComponentsDescription.put(component.getComponentId(), component.getComponentDescription(request.getLocale())); } model.put(MARK_LIST_DASHBOARDS_CONFIG, listDashboardConfig); model.put(MARK_LIST_DASHBOARDS_COMPONENTS, listDashboardComponents); model.put(MARK_LIST_COMPONENTS_DESCRIPTION, mapComponentsDescription); model.put(MARK_LOCALE, request.getLocale()); return getXPage(TEMPLATE_GET_MODIFY_DASHBOARDS, request.getLocale(), model); }
From source file:fr.paris.lutece.plugins.search.solr.web.SolrSearchApp.java
/** * Returns search results//from w w w .j a v a2 s . c o m * * @param request The HTTP request. * @param nMode The current mode. * @param plugin The plugin * @return The HTML code of the page. * @throws SiteMessageException exception */ @Override public XPage getPage(HttpServletRequest request, int nMode, Plugin plugin) throws SiteMessageException { XPage page = new XPage(); String strConfCode = request.getParameter(PARAMETER_CONF); SolrSearchAppConf conf = SolrSearchAppConfService.loadConfiguration(strConfCode); if (conf == null) { //Use default conf if the requested one doesn't exist conf = SolrSearchAppConfService.loadConfiguration(null); } Map<String, Object> model = getSearchResultModel(request, conf); for (String beanName : conf.getAddonBeanNames()) { ISolrSearchAppAddOn solrSearchAppAddon = SpringContextService.getBean(beanName); solrSearchAppAddon.buildPageAddOn(model, request); } HtmlTemplate template = AppTemplateService.getTemplate(conf.getTemplate(), request.getLocale(), model); page.setPathLabel(I18nService.getLocalizedString(PROPERTY_PATH_LABEL, request.getLocale())); page.setTitle(I18nService.getLocalizedString(PROPERTY_PAGE_TITLE, request.getLocale())); page.setContent(template.getHtml()); return page; }
From source file:org.guanxi.sp.engine.form.RegisterIdPFormController.java
@SuppressWarnings("unchecked") public ModelAndView onSubmit(HttpServletRequest request, HttpServletResponse response, Object command, BindException errors) throws Exception { File newIdPFile = new File(config.getIdPMetadataDirectory(), request.getParameter("filename") + ".xml"); createIdPFile(newIdPFile, request.getParameter("entityID"), request.getParameter("aa"), request.getParameter("x509").replaceAll("\r", "")); EntityDescriptorDocument loadedIdPDocument = EntityDescriptorDocument.Factory.parse(newIdPFile); EntityFarm farm = (EntityFarm) config.getServletContext() .getAttribute(Guanxi.CONTEXT_ATTR_ENGINE_ENTITY_FARM); // The source is defined in config/spring/application/entity.xml EntityManager manager = farm.getEntityManagerForSource("local-metadata"); Metadata metadataHandler = manager.createNewEntityHandler(); metadataHandler.setPrivateData(loadedIdPDocument.getEntityDescriptor()); manager.addMetadata(metadataHandler); ModelAndView mAndV = new ModelAndView(); mAndV.setViewName(getSuccessView()); mAndV.getModel().put("message", messageSource.getMessage("register.idp.success.message", null, request.getLocale())); return mAndV; }
From source file:fr.paris.lutece.plugins.crm.web.demand.DemandTypeJspBean.java
/** * Returns the form to create a demand type * @param request The Http request//from w ww. j ava2s . c om * @return the html code of the demand type form */ public String getCreateDemandType(HttpServletRequest request) { setPageTitleProperty(CRMConstants.PROPERTY_CREATE_DEMAND_TYPE_PAGE_TITLE); Map<String, Object> model = new HashMap<String, Object>(); model.put(CRMConstants.MARK_CATEGORIES_LIST, _categoryService.getCategories(getLocale(), false, false)); model.put(CRMConstants.MARK_USER_WORKGROUP_REF_LIST, AdminWorkgroupService.getUserWorkgroups(getUser(), getLocale())); model.put(CRMConstants.MARK_MAX_ORDER, _demandTypeService.findMaxOrder()); model.put(CRMConstants.MARK_TARGETS_LIST, _demandTypeService.getTargetsList()); model.put(CRMConstants.MARK_LOCALE, request.getLocale()); if (SecurityService.isAuthenticationEnable()) { model.put(CRMConstants.MARK_ROLE_REF_LIST, _demandTypeService.getRolesList()); } HtmlTemplate template = AppTemplateService.getTemplate(TEMPLATE_CREATE_DEMAND_TYPE, getLocale(), model); return getAdminPage(template.getHtml()); }
From source file:fr.paris.lutece.plugins.pluginwizard.web.PluginWizardApp.java
/** * The Creation form of the plugin/* w w w. j a v a 2 s. co m*/ * * @param request The Http Request * @return The html code of the plugin */ @View(value = VIEW_CREATE_PLUGIN, defaultView = true) public XPage getCreatePlugin(HttpServletRequest request) { return getXPage(TEMPLATE_CREATE_PLUGIN, request.getLocale()); }