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.calendar.business.portlet.MiniCalendarPortlet.java
/** * Returns the Xml code of the Calendar portlet without XML heading * //from w ww .j a v a 2 s .c om * @param request The HTTP servlet request * @return the Xml code of the Archive portlet content */ public String getXml(HttpServletRequest request) { StringBuffer strXml = new StringBuffer(); Locale locale = null; if (_cal == null) { _cal = new GregorianCalendar(); } if (request != null) { locale = request.getLocale(); if ((request.getParameter(Constants.PARAMETER_MONTH) != null) && (request.getParameter(Constants.PARAMETER_MONTH)).equals(Constants.PARAMETER_NEXT)) { _cal.add(Calendar.MONTH, 1); } else if ((request.getParameter(Constants.PARAMETER_MONTH) != null) && (request.getParameter(Constants.PARAMETER_MONTH)).equals(Constants.PARAMETER_PREV)) { _cal.add(Calendar.MONTH, -1); } XmlUtil.addElement(strXml, TAG_URL, AppPathService.getBaseUrl(request) + JSP_PORTAL_URL + POINT_INTERROGATION + PARAM_PAGE_ID + EGAL); } else { locale = I18nService.getDefaultLocale(); } //Load the xml calendar strXml.append(XMLUtils.getXMLPortletCalendar(locale, _cal, request)); //Top event section Plugin plugin = PluginService.getPlugin(Constants.PLUGIN_NAME); boolean topevent = MiniCalendarPortletHome.showTopEvent(); if (topevent) { XmlUtil.beginElement(strXml, TAG_TOP_EVENTS); List<SimpleEvent> listEvents = CalendarHome.findTopEventList(plugin); Iterator<SimpleEvent> i = listEvents.iterator(); while (i.hasNext()) { XmlUtil.beginElement(strXml, TAG_TOP_EVENT); SimpleEvent event = i.next(); XmlUtil.addElement(strXml, TAG_TOP_EVENT_TITLE, (event.getTitle() != null) ? event.getTitle() : ""); XmlUtil.addElement(strXml, TAG_EVENT_ID, event.getId()); XmlUtil.addElement(strXml, TAG_AGENDA_ID, event.getIdCalendar()); XmlUtil.endElement(strXml, TAG_TOP_EVENT); //Register the image EventImageResourceService.getInstance().getResourceImageEvent(event.getId()); } XmlUtil.endElement(strXml, TAG_TOP_EVENTS); } String strDateBegin = request != null ? request.getParameter(Constants.PARAMETER_DATE) : StringUtils.EMPTY; // If there is no date begin in the parameter, then get today's date if (StringUtils.isBlank(strDateBegin)) { strDateBegin = DateUtil.getCurrentDateString(locale); } String[] arrayCategory = null; String[] arrayCalendar = Utils.getCalendarIds(request); String strQuery = StringUtils.EMPTY; List<Event> listEvent = null; Plugin pluginCalendar = PluginService.getPlugin(CalendarPlugin.PLUGIN_NAME); Date dateBegin = DateUtil.formatDate(strDateBegin, request != null ? request.getLocale() : Locale.getDefault()); // If there is a date end, then it is a search on a date interval String strDateEnd = request != null ? request.getParameter(Constants.PARAMETER_DATE_END) : StringUtils.EMPTY; Date dateEnd = null; if (StringUtils.isNotBlank(strDateEnd)) { dateEnd = DateUtil.formatDate(strDateEnd, request != null ? request.getLocale() : Locale.getDefault()); } if (dateEnd == null) { dateEnd = dateBegin; } listEvent = CalendarSearchService.getInstance().getSearchResults(arrayCalendar, arrayCategory, strQuery, dateBegin, dateEnd, pluginCalendar); if (listEvent != null) { //Sort events by DateTimeStart using bubble sort SimpleDateFormat sdf = new SimpleDateFormat("HH:mm"); boolean bisModification; Date date1; Date date2; Event temporaryEvent; do { bisModification = true; for (int j = 0; j < listEvent.size() - 1; j++) { try { date1 = sdf.parse(listEvent.get(j).getDateTimeStart()); } catch (Exception e) { date1 = new Date(0); } try { date2 = sdf.parse(listEvent.get(j + 1).getDateTimeStart()); } catch (Exception e) { date2 = new Date(0); } if (date1.after(date2)) { temporaryEvent = listEvent.get(j + 1); listEvent.set(j + 1, listEvent.get(j)); listEvent.set(j, temporaryEvent); bisModification = false; } } } while (!bisModification); XmlUtil.beginElement(strXml, TAG_EVENTS); for (Event event : listEvent) { XmlUtil.beginElement(strXml, TAG_EVENT); // Search on date interval, then display date begin and date end if (StringUtils.isNotBlank(strDateEnd) && !strDateBegin.equals(strDateEnd)) { XmlUtil.addElement(strXml, TAG_DATE, DateUtil.getDateString(event.getDate(), locale)); XmlUtil.addElement(strXml, TAG_DATE_END, DateUtil.getDateString(event.getDateEnd(), locale)); } // Else only display the date on which the user has clicked else { XmlUtil.addElement(strXml, TAG_DATE, strDateBegin); XmlUtil.addElement(strXml, TAG_DATE_END, StringUtils.EMPTY); } XmlUtil.addElementHtml(strXml, TAG_EVENT_TITLE, (event.getTitle() != null) ? event.getTitle() : StringUtils.EMPTY); XmlUtil.addElement(strXml, TAG_EVENT_DATETIME_BEGIN, (event.getDateTimeStart() != null) ? event.getDateTimeStart() : StringUtils.EMPTY); XmlUtil.addElementHtml(strXml, TAG_EVENT_DESCRIPTION, (event.getDescription() != null) ? event.getDescription() : StringUtils.EMPTY); XmlUtil.addElement(strXml, TAG_EVENT_ID, event.getId()); XmlUtil.endElement(strXml, TAG_EVENT); } XmlUtil.endElement(strXml, TAG_EVENTS); } String str = addPortletTags(strXml); return str; }
From source file:jp.terasoluna.fw.web.struts.action.SystemExceptionHandler.java
/** * ?bZ?[W\?[X?bZ?[WL?[w//from w ww . j av a 2s .c o m * G?[?bZ?[W?B * * @param req HTTPNGXg * @param se SystemException * @param resources ?bZ?[W\?[X * * @return G?[?bZ?[W */ private String getErrorMessage(HttpServletRequest req, SystemException se, MessageResources resources) { String errorCode = se.getErrorCode(); // ?bZ?[WL?[w?Anullp?B if (errorCode == null) { return null; } String[] options = se.getOptions(); if (options == null) { return resources.getMessage(req.getLocale(), errorCode); } return resources.getMessage(req.getLocale(), errorCode, options); }
From source file:org.springside.modules.security.jcaptcha.JCaptchaFilter.java
/** * ???.//from ww w.ja v a 2s. co m */ protected void genernateCaptchaImage(final HttpServletRequest request, final HttpServletResponse response) throws IOException { ServletUtils.setDisableCacheHeader(response); response.setContentType("image/jpeg"); ServletOutputStream out = response.getOutputStream(); try { String captchaId = request.getSession(true).getId(); BufferedImage challenge = (BufferedImage) captchaService.getChallengeForID(captchaId, request.getLocale()); ImageIO.write(challenge, "jpg", out); out.flush(); } catch (CaptchaServiceException e) { logger.error(e.getMessage(), e); } finally { out.close(); } }
From source file:fr.paris.lutece.plugins.workflow.modules.mappings.web.CodeMappingJspBean.java
/** * Get error// w w w . j a va2 s .c o m * @param request the HTTP request * @return the HTML code */ public String getError(HttpServletRequest request) { String strErrorMessage = request.getParameter(PARAMETER_ERROR_MESSAGE); if (StringUtils.isBlank(strErrorMessage)) { strErrorMessage = I18nService.getLocalizedString(MESSAGE_ERROR_GENERIC_MESSAGE, request.getLocale()); } return getError(request, strErrorMessage); }
From source file:fr.paris.lutece.plugins.workflow.modules.ticketing.web.EditTicketXPage.java
/** * Get the page//w ww. j a v a 2s .c om * @param request teh request * @param nIdHistory the history id * @param nIdTask the task id * @param nIdAction the action id * @param strUrlReturn the URL to return * @return the page * @throws SiteMessageException if there is an exception */ private XPage getPage(HttpServletRequest request, int nIdHistory, int nIdTask, int nIdAction, String strUrlReturn) throws SiteMessageException { XPage page = null; EditableTicket editableTicket = _editableTicketService.find(nIdHistory, nIdTask); if ((editableTicket != null) && !editableTicket.isEdited()) { if (_editableTicketService.isStateValid(editableTicket, request.getLocale())) { if (doProcessWorkflowAction(request, nIdAction, editableTicket)) { // Back to home page setSiteMessage(request, MESSAGE_EDITION_COMPLETE, SiteMessage.TYPE_INFO, strUrlReturn); } else { page = getEditTicketPage(request, editableTicket); } } else { setSiteMessage(request, Messages.USER_ACCESS_DENIED, SiteMessage.TYPE_STOP, strUrlReturn); } } else { setSiteMessage(request, MESSAGE_TICKET_ALREADY_EDITED, SiteMessage.TYPE_INFO, strUrlReturn); } return page; }
From source file:fr.paris.lutece.plugins.workflow.modules.notifycrm.service.NotifyCRMService.java
/** * {@inheritDoc}/*from w w w . j a v a 2 s .c om*/ */ @Override public Locale getLocale(HttpServletRequest request) { Locale locale = null; if (request != null) { locale = request.getLocale(); } else { locale = I18nService.getDefaultLocale(); } return locale; }
From source file:fr.paris.lutece.plugins.mydashboard.modules.nickname.service.MyDashboardComponentNickname.java
/** * {@inheritDoc}/*from ww w .j ava2s . c o m*/ */ @Override public String getDashboardData(HttpServletRequest request) { if (SecurityService.isAuthenticationEnable()) { LuteceUser user = SecurityService.getInstance().getRegisteredUser(request); if (user != null) { String strUserNickName = UserPreferencesService.instance().getNickname(user); Map<String, Object> model = new HashMap<String, Object>(); model.put(MARK_USER_NICKNACME, strUserNickName); HtmlTemplate template = AppTemplateService.getTemplate(TEMPLATE_DASHBOARD_COMPONENT_PSEUDO, request.getLocale(), model); return template.getHtml(); } } return StringUtils.EMPTY; }
From source file:org.smigo.user.UserSetLocaleResolver.java
@Override public Locale resolveLocale(HttpServletRequest req) { final Principal userPrincipal = req.getUserPrincipal(); if (userPrincipal != null) { User user = userDao.getUsersByUsername(userPrincipal.getName()).get(0); if (user.getLocale() != null) { return user.getLocale(); }//w w w . j a v a2s . co m } final String subDomain = req.getServerName().split("\\.")[0]; for (Language language : Language.values()) { if (language.getLocale().getLanguage().equals(subDomain)) { return new Locale(subDomain); } } return req.getLocale() == null ? Locale.ENGLISH : req.getLocale(); }
From source file:fr.paris.lutece.plugins.extend.modules.rating.web.component.RatingResourceExtenderComponent.java
/** * {@inheritDoc}// w w w. j a v a2s .c o m */ @Override public String getInfoHtml(ResourceExtenderDTO resourceExtender, Locale locale, HttpServletRequest request) { if (resourceExtender != null) { Map<String, Object> model = new HashMap<String, Object>(); model.put(RatingConstants.MARK_RATING, _ratingService.findByResource( resourceExtender.getIdExtendableResource(), resourceExtender.getExtendableResourceType())); HtmlTemplate template = AppTemplateService.getTemplate(TEMPLATE_RATING_INFO, request.getLocale(), model); return template.getHtml(); } return StringUtils.EMPTY; }
From source file:fr.paris.lutece.plugins.extend.modules.statistics.web.StatisticsJspBean.java
/** * Gets the view stats./*from w w w . jav a 2s . c o m*/ * * @param request the request * @param response the response * @return the view stats * @throws AccessDeniedException the access denied exception */ public IPluginActionResult getViewStats(HttpServletRequest request, HttpServletResponse response) throws AccessDeniedException { setPageTitleProperty(PROPERTY_VIEW_STATS_PAGE_TITLE); // RESOURCE TYPES ReferenceList listResourceTypes = _resourceTypeService.findAllAsRef(AdminUserService.getLocale(request)); listResourceTypes.addItem(StringUtils.EMPTY, I18nService.getLocalizedString(PROPERTY_LABEL_ALL, request.getLocale())); // EXTENDER TYPES ReferenceList listExtenderTypes = _resourceExtenderService.getExtenderTypes(request.getLocale()); listExtenderTypes.addItem(StringUtils.EMPTY, I18nService.getLocalizedString(PROPERTY_LABEL_ALL, request.getLocale())); // RESOURCE EXTENDER HISTORY FILTER initFilter(request); _filter.setGroupByAttributeName(GROUP_BY_ATTRIBUTE); _filter.setSortedAttributeName(request); _filter.setAscSort(request); // PAGINATOR _strCurrentPageIndex = Paginator.getPageIndex(request, Paginator.PARAMETER_PAGE_INDEX, _strCurrentPageIndex); _nItemsPerPage = Paginator.getItemsPerPage(request, Paginator.PARAMETER_ITEMS_PER_PAGE, _nItemsPerPage, _nDefaultItemsPerPage); int nNbStats = _statService.getNbStats(_filter); if (StringUtils.isNotBlank(_strCurrentPageIndex) && StringUtils.isNumeric(_strCurrentPageIndex)) { // Define the current page index // If the current page index is > ( nCurrentPageIndex - 1 ) * _nItemsPerPage ), then display the first page index int nCurrentPageIndex = Integer.parseInt(_strCurrentPageIndex); if (((nCurrentPageIndex - 1) * _nItemsPerPage) > nNbStats) { nCurrentPageIndex = 1; } _filter.setItemsPerPage(_nItemsPerPage); _filter.setPageIndex(nCurrentPageIndex); } UrlItem url = new UrlItem(AppPathService.getBaseUrl(request) + JSP_URL_VIEW_STATS); url.addParameter(PARAMETER_SESSION, PARAMETER_SESSION); if (_filter.containsAttributeName()) { url.addParameter(Parameters.SORTED_ATTRIBUTE_NAME, _filter.getSortedAttributeName()); url.addParameter(Parameters.SORTED_ASC, Boolean.toString(_filter.isAscSort())); } IPaginator<ResourceExtenderStat> paginator = new LocalizedDelegatePaginator<ResourceExtenderStat>( _statService.findStats(_filter), _nItemsPerPage, url.getUrl(), Paginator.PARAMETER_PAGE_INDEX, _strCurrentPageIndex, nNbStats, request.getLocale()); Map<String, Object> model = new HashMap<String, Object>(); model.put(MARK_LIST_RESOURCE_TYPES, listResourceTypes); model.put(MARK_LIST_EXTENDER_TYPES, listExtenderTypes); model.put(MARK_FILTER, _filter); model.put(MARK_LIST_STATS, paginator.getPageItems()); model.put(MARK_PAGINATOR, paginator); model.put(MARK_NB_ITEMS_PER_PAGE, Integer.toString(paginator.getItemsPerPage())); model.put(MARK_TOTAL_NUMBERS, _statService.getTotalNumbers(_filter)); HtmlTemplate template = AppTemplateService.getTemplate(TEMPLATE_VIEW_STATS, request.getLocale(), model); IPluginActionResult result = new DefaultPluginActionResult(); result.setHtmlContent(getAdminPage(template.getHtml())); return result; }