Example usage for javax.servlet.http HttpServletRequest getLocale

List of usage examples for javax.servlet.http HttpServletRequest getLocale

Introduction

In this page you can find the example usage for javax.servlet.http HttpServletRequest getLocale.

Prototype

public Locale getLocale();

Source Link

Document

Returns the preferred Locale that the client will accept content in, based on the Accept-Language header.

Usage

From source file:org.squale.squaleweb.applicationlayer.action.results.project.TopAction.java

/**
 * Selectionne un nouveau projet courant  visualiser.
 * //from   w  w  w. j ava2  s .c  om
 * @param pMapping le mapping.
 * @param pForm le formulaire  lire.
 * @param pRequest la requte HTTP.
 * @param pResponse la rponse de la servlet.
 * @return l'action  raliser.
 */
public ActionForward display(ActionMapping pMapping, ActionForm pForm, HttpServletRequest pRequest,
        HttpServletResponse pResponse) {

    ActionForward forward = null;
    ActionErrors errors = new ActionErrors();

    try {
        TopListForm topListForm = (TopListForm) pForm;
        // recupere le "type" de top
        String ComponentType = getNonCustomizedComponentType(pRequest);
        //On place le langage dans la requte pour les pages suivantes
        pRequest.setAttribute(SqualeWebConstants.LANGUAGE, pRequest.getParameter(SqualeWebConstants.LANGUAGE));
        topListForm.setComponentType(ComponentType);
        topListForm.setTre(pRequest.getParameter("tre"));

        // et calcule les resultats
        getResults(pRequest, topListForm);
    } catch (Exception e) {
        handleException(e, errors, pRequest);
    }

    if (!errors.isEmpty()) {
        saveMessages(pRequest, errors);
        forward = pMapping.findForward("total_failure");
    } else {
        forward = pMapping.findForward("success");
    }
    // Mise en place du traceur historique
    String name = WebMessages.getString(pRequest.getLocale(), pRequest.getParameter("tre"));

    String way = pRequest.getParameter("componenttype");

    // On rcupre la cl pour le traceur en fonction du type du composant
    if (null != way) { // code dfensif
                       //int index = way.lastIndexOf( "." );
        int index = getNonCustomizedComponentType(pRequest).lastIndexOf(".");
        if (index > 0) {
            String tracker = way.substring(index, way.length());
            name = WebMessages.getString(pRequest.getLocale(), "tracker.top" + tracker) + name;
        }
    }
    updateHistTracker(name, "top.do?" + pRequest.getQueryString(), TrackerStructure.TOP_VIEW, pRequest, true);
    // Indique que l'on vient d'une vue top et pas d'une vue composant
    changeWay(pRequest, "false");
    // Pour pouvoir ajouter le composant  la fin du traceur
    needToReset(pRequest, "true");
    return forward;
}

From source file:fr.paris.lutece.util.datatable.DataTableManager.java

/**
 * Get the paginator updated with values in the request
 * @param request The request//from  ww w.  j  a  v a 2s .co m
 * @return The paginator up to date
 */
public DataTablePaginationProperties getAndUpdatePaginator(HttpServletRequest request) {
    DataTablePaginationProperties paginationProperties = null;

    if (_bEnablePaginator) {
        paginationProperties = new DataTablePaginationProperties();

        if (hasDataTableFormBeenSubmited(request)) {
            _strCurrentPageIndex = Paginator.getPageIndex(request, Paginator.PARAMETER_PAGE_INDEX,
                    _strCurrentPageIndex);
            _nItemsPerPage = Paginator.getItemsPerPage(request, Paginator.PARAMETER_ITEMS_PER_PAGE,
                    _nItemsPerPage, _nDefautlItemsPerPage);
        }

        paginationProperties.setItemsPerPage(_nItemsPerPage);

        int nCurrentPageIndex = 1;

        if (!StringUtils.isEmpty(_strCurrentPageIndex)) {
            nCurrentPageIndex = Integer.parseInt(_strCurrentPageIndex);
        }

        paginationProperties.setCurrentPageIndex(nCurrentPageIndex);
    }

    _locale = (request != null) ? request.getLocale() : Locale.getDefault();

    return paginationProperties;
}

From source file:fr.paris.lutece.plugins.mylutece.modules.database.authentication.BaseAuthentication.java

private void sendUnlockLinkToUser(String strLogin, int nIntervalMinutes, HttpServletRequest request,
        Plugin plugin) {//w w w  .  j a  v  a2 s.  c o  m
    int nIdUser = DatabaseUserHome.findDatabaseUserIdFromLogin(strLogin, plugin);

    if (nIdUser > 0) {
        ReferenceItem referenceItem = DatabaseUserParameterHome.findByKey(PARAMETER_UNBLOCK_USER_MAIL_SENDER,
                plugin);
        String strSender = (referenceItem == null) ? StringUtils.EMPTY : referenceItem.getName();

        referenceItem = DatabaseUserParameterHome.findByKey(PARAMETER_UNBLOCK_USER_MAIL_SUBJECT, plugin);

        String strSubject = (referenceItem == null) ? StringUtils.EMPTY : referenceItem.getName();

        String strLink = SecurityUtils.buildResetConnectionLogUrl(nIntervalMinutes, request);

        Map<String, Object> model = new HashMap<String, Object>();
        model.put(MARK_URL, strLink);
        model.put(MARK_SITE_LINK, MailService.getSiteLink(AppPathService.getBaseUrl(request), true));

        String strTemplate = DatabaseTemplateHome.getTemplateFromKey(PROPERTY_UNBLOCK_USER);
        HtmlTemplate template = AppTemplateService.getTemplateFromStringFtl(strTemplate, request.getLocale(),
                model);

        DatabaseAccountLifeTimeService accountLifeTimeService = new DatabaseAccountLifeTimeService();

        String strUserMail = accountLifeTimeService.getUserMainEmail(nIdUser);

        if ((strUserMail != null) && StringUtils.isNotBlank(strUserMail)) {
            MailService.sendMailHtml(strUserMail, strSender, strSender, strSubject, template.getHtml());
        }
    }
}

From source file:fr.paris.lutece.plugins.calendar.web.CalendarApp.java

/**
 * Get the XPage for downloading an event
 * @param request {@link HttpServletRequest}
 * @param plugin {@link Plugin}/* w w  w  .  ja v  a  2 s .  c  o m*/
 * @return the html
 */
private XPage getDownloadPage(HttpServletRequest request, Plugin plugin) {
    XPage page = new XPage();
    Map<String, Object> model = new HashMap<String, Object>();
    model.put(Constants.MARK_LOCALE, request.getLocale());
    model.put(Constants.MARK_CALENDARS_LIST, getListAgenda(request, plugin));
    model.put(Constants.MARK_EXPORT_STYLESHEET_LIST, getExportSheetList(request, plugin));

    HtmlTemplate template = AppTemplateService.getTemplate(TEMPLATE_DOWNLOAD_CALENDAR, request.getLocale(),
            model);

    page.setContent(template.getHtml());
    page.setTitle(I18nService.getLocalizedString(Constants.PROPERTY_PAGE_DOWNLOAND_TITLE, request.getLocale()));
    page.setPathLabel(
            I18nService.getLocalizedString(Constants.PROPERTY_PAGE_DOWNLOAND_TITLE, request.getLocale()));

    return page;
}

From source file:fr.paris.lutece.plugins.mylutece.modules.database.authentication.service.DatabaseService.java

/**
 * Get th list of filteredUsers/* ww  w. ja va 2s  .  c o m*/
 * @param request the HTTP request
 * @param duFilter the filter
 * @param listUsers the list of users
 * @return a list of {@link DatabaseUser}
 */
public List<DatabaseUser> getListFilteredUsers(HttpServletRequest request, DatabaseUserFilter duFilter,
        List<DatabaseUser> listUsers) {
    Plugin plugin = PluginService.getPlugin(DatabasePlugin.PLUGIN_NAME);

    List<DatabaseUser> listFilteredUsers = DatabaseUserHome.findDatabaseUsersListByFilter(duFilter, plugin);
    List<DatabaseUser> listAvailableUsers = new ArrayList<DatabaseUser>();

    for (DatabaseUser filteredUser : listFilteredUsers) {
        for (DatabaseUser user : listUsers) {
            if (filteredUser.getUserId() == user.getUserId()) {
                listAvailableUsers.add(user);
            }
        }
    }

    Plugin myLutecePlugin = PluginService.getPlugin(MyLutecePlugin.PLUGIN_NAME);
    List<DatabaseUser> filteredUsers = new ArrayList<DatabaseUser>();

    MyLuteceUserFieldFilter mlFieldFilter = new MyLuteceUserFieldFilter();
    mlFieldFilter.setMyLuteceUserFieldFilter(request, request.getLocale());

    List<Integer> listFilteredUserIdsByUserFields = MyLuteceUserFieldHome.findUsersByFilter(mlFieldFilter,
            myLutecePlugin);

    if (listFilteredUserIdsByUserFields != null) {
        for (DatabaseUser filteredUser : listAvailableUsers) {
            for (Integer nFilteredUserIdByUserField : listFilteredUserIdsByUserFields) {
                if (filteredUser.getUserId() == nFilteredUserIdByUserField) {
                    filteredUsers.add(filteredUser);
                }
            }
        }
    } else {
        filteredUsers = listAvailableUsers;
    }

    return filteredUsers;
}

From source file:fr.paris.lutece.plugins.sponsoredlinks.web.SponsoredLinksJspBean.java

/**
 * Returns the create Sponsoredlinks set page
 * @param request The HTTP request//w  w  w  .j ava  2 s. co  m
 * @return The HTML page
 */
public String getCreateSet(HttpServletRequest request) {
    if (!RBACService.isAuthorized(SponsoredLinkSet.RESOURCE_TYPE, RBAC.WILDCARD_RESOURCES_ID,
            SponsoredLinksSetResourceIdService.PERMISSION_CREATE_SET, getUser())) {
        return getManageSet(request);
    }

    setPageTitleProperty(PROPERTY_PAGE_TITLE_CREATE_SET);

    Collection<SponsoredLinkGroup> listUnusedGroup = SponsoredLinkGroupHome.findUnusedGroupList(getPlugin());

    Map<String, Object> model = new HashMap<String, Object>();

    model.put(MARK_LOCALE, request.getLocale());
    model.put(MARK_WEBAPP_URL, AppPathService.getBaseUrl(request));
    model.put(MARK_LINK_LIST, computeLinkFormEntries());
    model.put(MARK_GROUP_LIST, listUnusedGroup);

    HtmlTemplate template = AppTemplateService.getTemplate(TEMPLATE_CREATE_SET, getLocale(), model);

    return getAdminPage(template.getHtml());
}

From source file:fr.paris.lutece.plugins.stock.modules.billetterie.web.OfferJspBean.java

/**
 * Send notification for user who subscribed to the product link with an
 * offer./*from w w w .j  av a 2  s.c o m*/
 * @param offer the offer create
 * @param request The Http request
 */
public void doNotifyCreateOffer(HttpServletRequest request, SeanceDTO offer) {
    //get all subscription for product
    Product product = _serviceProduct.findById(offer.getProduct().getId()).convert();

    List<String> listUserEmail = _subscriptionProductService
            .getListEmailSubscriber(Integer.toString(offer.getProduct().getId()));

    //Generate mail content
    Map<String, Object> model = new HashMap<String, Object>();
    model.put(MARK_OFFER, offer);
    model.put(MARK_PRODUCT, product);
    model.put(MARK_BASE_URL, AppPathService.getBaseUrl(request));

    // Create mail object
    HtmlTemplate template;
    NotificationDTO notificationDTO;

    for (String strUserEmail : listUserEmail) {
        model.put(MARK_USER_NAME, strUserEmail);
        template = AppTemplateService.getTemplate(TEMPLATE_NOTIFICATION_CREATE_OFFER, request.getLocale(),
                model);

        notificationDTO = new NotificationDTO();
        notificationDTO.setRecipientsTo(strUserEmail);

        String[] args = new String[] { product.getName(), };
        notificationDTO.setSubject(
                I18nService.getLocalizedString(MESSAGE_NOTIFICATION_OFFER_PRODUCT, args, request.getLocale()));
        notificationDTO.setMessage(template.getHtml());

        // Send it
        _serviceNotification.send(notificationDTO);
    }
}

From source file:fr.paris.lutece.plugins.workflow.modules.notifydirectory.web.NotifyDirectoryTaskComponent.java

/**
 * {@inheritDoc}//from   w  ww  .j  a  v a  2s. c om
 */
@Override
public String getDisplayConfigForm(HttpServletRequest request, Locale locale, ITask task) {
    TaskNotifyDirectoryConfig config = _taskNotifyDirectoryConfigService.findByPrimaryKey(task.getId());

    String strDefaultSenderName = AppPropertiesService
            .getProperty(NotifyDirectoryConstants.PROPERTY_NOTIFY_MAIL_DEFAULT_SENDER_NAME);
    Plugin pluginWorkflow = PluginService.getPlugin(WorkflowPlugin.PLUGIN_NAME);

    Map<String, Object> model = new HashMap<String, Object>();

    model.put(NotifyDirectoryConstants.MARK_CONFIG, config);
    model.put(NotifyDirectoryConstants.MARK_DEFAULT_SENDER_NAME, strDefaultSenderName);
    model.put(NotifyDirectoryConstants.MARK_LIST_ENTRIES_EMAIL_SMS,
            _notifyDirectoryService.getListEntriesEmailSMS(task.getId(), locale));
    model.put(NotifyDirectoryConstants.MARK_LIST_ENTRIES_FREEMARKER,
            _notifyDirectoryService.getListEntriesFreemarker(task.getId()));
    model.put(NotifyDirectoryConstants.MARK_DIRECTORY_LIST, _notifyDirectoryService.getListDirectories());
    model.put(NotifyDirectoryConstants.MARK_STATE_LIST,
            _notifyDirectoryService.getListStates(task.getAction().getId()));
    model.put(NotifyDirectoryConstants.MARK_WEBAPP_URL, AppPathService.getBaseUrl(request));
    model.put(NotifyDirectoryConstants.MARK_LOCALE, request.getLocale());
    model.put(NotifyDirectoryConstants.MARK_IS_USER_ATTRIBUTE_WS_ACTIVE, _userAttributesManager.isEnabled());
    model.put(NotifyDirectoryConstants.MARK_LIST_ENTRIES_USER_GUID,
            _notifyDirectoryService.getListEntriesUserGuid(task.getId(), locale));
    model.put(NotifyDirectoryConstants.MARK_LIST_ENTRIES_FILE,
            _notifyDirectoryService.getListEntriesFile(task.getId(), locale));

    if (config != null) {
        model.put(NotifyDirectoryConstants.MARK_LIST_POSITION_ENTRY_FILE_CHECKED,
                config.getListPositionEntryFile());
    }

    model.put(NotifyDirectoryConstants.MARK_MAILING_LIST, _notifyDirectoryService.getMailingList(request));
    model.put(NotifyDirectoryConstants.MARK_PLUGIN_WORKFLOW, pluginWorkflow);
    model.put(NotifyDirectoryConstants.MARK_TASKS_LIST,
            _notifyDirectoryService.getListBelowTasks(task, locale));

    HtmlTemplate template = AppTemplateService.getTemplate(TEMPLATE_TASK_NOTIFY_DIRECTORY_CONFIG, locale,
            model);

    return template.getHtml();
}

From source file:fr.paris.lutece.plugins.pluginwizard.web.PluginWizardApp.java

/**
 * The modification page of the portlet//from  ww w  .  ja v  a  2 s  . c o  m
 *
 * @param request The Http Request
 * @return The XPage
 */
@View(VIEW_MODIFY_PORTLET)
public XPage getModifyPortlet(HttpServletRequest request) {
    int nPortletId = Integer.parseInt(request.getParameter(PARAM_PORTLET_ID));

    if ((_portlet == null) || (_portlet.getId() != nPortletId)) {
        _portlet = ModelService.getPortlet(_nPluginId, nPortletId);
    }

    Map<String, Object> model = getModel();
    model.put(MARK_PORTLET, _portlet);

    return getXPage(TEMPLATE_MODIFY_PLUGIN_PORTLET, request.getLocale(), model);
}

From source file:fr.paris.lutece.plugins.pluginwizard.web.PluginWizardApp.java

/**
 * Gets the create plugin description page
 *
 * @param request The HTTP request/*from  ww  w .  ja  va 2s .  c  om*/
 * @return The page
 */
@View(VIEW_CREATE_DESCRIPTION)
public XPage getCreatePluginDescription(HttpServletRequest request) {
    Map<String, Object> model = getPluginModel();

    _description = new DescriptionFormBean();

    for (ConfigurationKey key : ConfigurationKeyHome.getConfigurationKeysList()) {
        model.put(key.getKeyDescription().trim(), key.getKeyValue());
    }

    model.put(MARK_PLUGIN_ID, _nPluginId);

    return getXPage(TEMPLATE_CREATE_PLUGIN_DESCRIPTION, request.getLocale(), model);
}