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:net.duckling.ddl.web.controller.LynxEditPageController.java

@RequestMapping(params = "func=previewToEdit")
@WebLog(method = "previewReturnEdit", params = "rid")
public ModelAndView previewToEdit(HttpServletRequest request, @RequestParam("rid") Integer rid)
        throws Exception {
    int parentRid = getPatentRidFromRequest(request);
    VWBContext context = getEditPageContext(request, rid);
    PageRender render = getPageRender(rid, context);
    context.setWysiwygEditorMode(VWBContext.EDITOR_MODE);
    String innerHTML = request.getParameter("fixDomStr");
    render.getMeta().setTitle(request.getParameter("pageTitle"));
    ModelAndView mv = loadEditorWithContent(context, render, innerHTML, request.getLocale().toString());
    mv.addObject("parentRid", parentRid);
    return mv;//from   w ww.j a v  a2s .  c  o m
}

From source file:fr.paris.lutece.plugins.extend.modules.opengraph.web.component.OpengraphResourceExtenderComponent.java

/**
 * Get the social hub body of an extender
 * @param config The extender configuration
 * @param request The request//  www.j  a va  2s . c o  m
 * @return The HTML content to display
 */
private String getBody(OpengraphExtenderConfig config, HttpServletRequest request) {
    List<Integer> listSocialHubId = config.getListOpengraphSocialHubId();
    List<String> listSocialHubs;
    if (listSocialHubId.isEmpty()) {
        listSocialHubs = Collections.emptyList();
    } else {
        listSocialHubs = new ArrayList<String>(listSocialHubId.size());
        for (OpengraphSocialHub socialHub : _opengraphService.findAll()) {
            if (listSocialHubId.contains(socialHub.getOpengraphSocialHubId())) {
                listSocialHubs.add(socialHub.getContentBody());
            }
        }
    }

    Map<String, Object> model = new HashMap<String, Object>();
    model.put(MARK_SOCIALHUBS, listSocialHubs);

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

    return template.getHtml();
}

From source file:mx.edu.um.mateo.rh.web.DependienteController.java

private void enviaCorreo(String tipo, List<Dependiente> dependientes, HttpServletRequest request)
        throws JRException, MessagingException {
    log.debug("Enviando correo {}", tipo);
    byte[] archivo = null;
    String tipoContenido = null;//from  w ww. ja v  a 2  s  . c o  m
    switch (tipo) {
    case "PDF":
        archivo = generaPdf(dependientes);
        tipoContenido = "application/pdf";
        break;
    case "CSV":
        archivo = generaCsv(dependientes);
        tipoContenido = "text/csv";
        break;
    case "XLS":
        archivo = generaXls(dependientes);
        tipoContenido = "application/vnd.ms-excel";
    }

    MimeMessage message = mailSender.createMimeMessage();
    MimeMessageHelper helper = new MimeMessageHelper(message, true);
    String titulo = messageSource.getMessage("dependiente.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:fr.paris.lutece.plugins.extend.modules.opengraph.web.component.OpengraphResourceExtenderComponent.java

/**
 * Get the social hub footer of an extender
 * @param config The config/*  w ww.jav a  2  s .  co  m*/
 * @param request The request
 * @return The HTML content to display
 */
private String getFooter(OpengraphExtenderConfig config, HttpServletRequest request) {
    List<Integer> listSocialHubId = config.getListOpengraphSocialHubId();
    List<String> listSocialHubs;
    if (listSocialHubId.isEmpty()) {
        listSocialHubs = Collections.emptyList();
    } else {
        listSocialHubs = new ArrayList<String>(listSocialHubId.size());
        for (OpengraphSocialHub socialHub : _opengraphService.findAll()) {
            if (listSocialHubId.contains(socialHub.getOpengraphSocialHubId())) {
                listSocialHubs.add(socialHub.getContentFooter());
            }
        }
    }

    Map<String, Object> model = new HashMap<String, Object>();
    model.put(MARK_SOCIALHUBS, listSocialHubs);

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

    return template.getHtml();
}

From source file:fr.paris.lutece.plugins.crm.modules.mylutece.web.CRMMyLuteceSearchFields.java

/**
 * {@inheritDoc}/* ww w .  j  a va 2  s . c o m*/
 */
@Override
public void fillModel(String strBaseUrl, HttpServletRequest request, Map<String, Object> model)
        throws AccessDeniedException {
    initFilter(request);

    // SORT
    UrlItem url = new UrlItem(strBaseUrl);
    url.addParameter(PARAMETER_SESSION, PARAMETER_SESSION);

    // PAGINATOR
    _strCurrentPageIndex = Paginator.getPageIndex(request, Paginator.PARAMETER_PAGE_INDEX,
            _strCurrentPageIndex);
    _nDefaultItemsPerPage = AppPropertiesService.getPropertyInt(PROPERTY_DEFAULT_LIST_USERS_PER_PAGE, 50);
    _nItemsPerPage = Paginator.getItemsPerPage(request, Paginator.PARAMETER_ITEMS_PER_PAGE, _nItemsPerPage,
            _nDefaultItemsPerPage);

    CRMUserService crmUserService = CRMUserService.getService();
    List<Integer> listIdsCRMUser = crmUserService.findListIdsByFilter(_filter);

    LocalizedPaginator<Integer> paginator = new LocalizedPaginator<Integer>(listIdsCRMUser, getItemsPerPage(),
            url.getUrl(), Paginator.PARAMETER_PAGE_INDEX, getCurrentPageIndex(), request.getLocale());

    List<CRMUser> listUsers = crmUserService.findByListIds(paginator.getPageItems());

    model.put(MARK_LIST_CRM_USERS, listUsers);
    model.put(MARK_FILTER, _filter);
    model.put(MARK_PAGINATOR, paginator);
    model.put(MARK_NB_ITEMS_PER_PAGE, Integer.toString(paginator.getItemsPerPage()));
}

From source file:fr.paris.lutece.plugins.workflow.modules.editrecord.web.EditRecordApp.java

/**
 * {@inheritDoc}/*from w  w  w.  j a  v a2s  . c  om*/
 */
public XPage getPage(HttpServletRequest request, int nMode, Plugin plugin)
        throws UserNotSignedException, SiteMessageException {
    XPage page = null;

    if (_editRecordService.isRequestAuthenticated(request)) {
        String strIdHistory = request.getParameter(EditRecordConstants.PARAMETER_ID_HISTORY);
        String strIdTask = request.getParameter(EditRecordConstants.PARAMETER_ID_TASK);

        if (StringUtils.isNotBlank(strIdHistory) && StringUtils.isNumeric(strIdHistory)
                && StringUtils.isNotBlank(strIdTask) && StringUtils.isNumeric(strIdTask)) {
            int nIdHistory = Integer.parseInt(strIdHistory);
            int nIdTask = Integer.parseInt(strIdTask);
            EditRecord editRecord = _editRecordService.find(nIdHistory, nIdTask);

            if ((editRecord != null) && !editRecord.isComplete()) {
                if (_editRecordService.isRecordStateValid(editRecord, request.getLocale())) {
                    doAction(request, editRecord);
                    page = getEditRecordPage(request, editRecord);
                } else {
                    _editRecordService.setSiteMessage(request, Messages.USER_ACCESS_DENIED,
                            SiteMessage.TYPE_STOP,
                            request.getParameter(EditRecordConstants.PARAMETER_URL_RETURN));
                }
            } else {
                _editRecordService.setSiteMessage(request, EditRecordConstants.MESSAGE_RECORD_ALREADY_COMPLETED,
                        SiteMessage.TYPE_INFO, request.getParameter(EditRecordConstants.PARAMETER_URL_RETURN));
            }
        } else {
            _editRecordService.setSiteMessage(request, Messages.MANDATORY_FIELDS, SiteMessage.TYPE_STOP,
                    request.getParameter(EditRecordConstants.PARAMETER_URL_RETURN));
        }
    } else {
        _editRecordService.setSiteMessage(request, Messages.USER_ACCESS_DENIED, SiteMessage.TYPE_STOP,
                request.getParameter(EditRecordConstants.PARAMETER_URL_RETURN));
    }

    return page;
}

From source file:mx.edu.um.mateo.rh.web.JefeRHController.java

private void enviaCorreo(String tipo, List<Jefe> jefes, HttpServletRequest request)
        throws JRException, MessagingException {
    log.debug("Enviando correo {}", tipo);
    byte[] archivo = null;
    String tipoContenido = null;/*from w  w w  .  ja  va 2 s. com*/
    switch (tipo) {
    case "PDF":
        archivo = generaPdf(jefes);
        tipoContenido = "application/pdf";
        break;
    case "CSV":
        archivo = generaCsv(jefes);
        tipoContenido = "text/csv";
        break;
    case "XLS":
        archivo = generaXls(jefes);
        tipoContenido = "application/vnd.ms-excel";
    }

    MimeMessage message = mailSender.createMimeMessage();
    MimeMessageHelper helper = new MimeMessageHelper(message, true);
    helper.setTo(ambiente.obtieneUsuario().getUsername());
    String titulo = messageSource.getMessage("jefe.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:fr.paris.lutece.plugins.document.web.DocumentContentJspBean.java

/**
 * Return the view of an document before printing
 * @param request  Http request/*from   ww w.ja v a  2  s  .  co  m*/
 * @return the HTML page
 */
public String getPrintDocumentPage(HttpServletRequest request) {
    String strDocumentId = request.getParameter(PARAMETER_DOCUMENT_ID);
    int nDocumentId = IntegerUtils.convert(strDocumentId);
    Document document = DocumentHome.findByPrimaryKeyWithoutBinaries(nDocumentId);

    if (document == null) {
        return StringUtils.EMPTY;
    }

    DocumentType type = DocumentTypeHome.findByPrimaryKey(document.getCodeDocumentType());

    XmlTransformerService xmlTransformerService = new XmlTransformerService();

    String strPreview = xmlTransformerService.transformBySourceWithXslCache(document.getXmlValidatedContent(),
            type.getContentServiceXslSource(), XSL_UNIQUE_PREFIX + type.getContentServiceStyleSheetId(), null,
            null);

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

    model.put(MARK_BASE_URL, AppPathService.getBaseUrl(request));
    model.put(MARK_PREVIEW, strPreview);
    model.put(MARK_PORTAL_DOMAIN, request.getServerName());

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

    return template.getHtml();
}

From source file:fr.paris.lutece.plugins.extend.service.content.ExtendableContentPostProcessor.java

/**
 * {@inheritDoc}/*from w ww.  ja  v  a 2  s.  c  o  m*/
 */
@Override
public String process(HttpServletRequest request, String strContent) {
    String strHtmlContent = strContent;

    // Check if the process is carried out in client or server side
    boolean bClientSide = Boolean.valueOf(AppPropertiesService.getProperty(PROPERTY_CLIENT_SIDE, "false"));

    if (bClientSide) {
        // CLIENT SIDE
        int nPos = strHtmlContent.indexOf(END_BODY);

        if (nPos < 0) {
            AppLogService.error("ExtendableContentPostProcessor Service : no BODY end tag found");

            return strHtmlContent;
        }

        Map<String, Object> model = new HashMap<String, Object>();
        model.put(MARK_BASE_URL, AppPathService.getBaseUrl(request));
        model.put(MARK_REGEX_PATTERN, _strRegexPattern);

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

        StringBuilder sb = new StringBuilder();
        sb.append(strHtmlContent.substring(0, nPos));
        sb.append(template.getHtml());
        sb.append(strHtmlContent.substring(nPos));
        strHtmlContent = sb.toString();
    } else {
        // SERVER SIDE

        /**
         * Replace all makers @Extender[<idResource>,<resourceType>,<extenderType>,<params>]@ to
         * the correct HTML content of the extender.
         * 1) First parse the content of the markers
         * 2) Get all information (idResource, resourceType, extenderType, params)
         * 3) Get the html content from the given information
         * 4) Replace the markers by the html content
         */

        // 1) First parse the content of the markers
        Matcher match = _regexPattern.matcher(strHtmlContent);
        Matcher parameterMatch = null;
        StringBuffer strResultHTML = new StringBuffer(strHtmlContent.length());
        while (match.find()) {
            String strMarker = match.group();

            // 2) Get all information (idResource, resourceType, extenderType, params)
            ResourceExtenderDTO resourceExtender = _mapper.map(match.group(1));
            boolean bParameteredId = StringUtils.equalsIgnoreCase(resourceExtender.getIdExtendableResource(),
                    EXTEND_PARAMETERED_ID);

            if (bParameteredId) {
                if (parameterMatch == null) {
                    parameterMatch = _extendedParameterRegexPattern.matcher(strHtmlContent);
                } else {
                    parameterMatch.reset();
                }

                while (parameterMatch.find()) {
                    ResourceExtenderDTO realResourceExtender = _mapper.map(parameterMatch.group(1));

                    if (StringUtils.equals(realResourceExtender.getExtendableResourceType(),
                            resourceExtender.getExtendableResourceType())
                            && StringUtils.equals(realResourceExtender.getExtenderType(),
                                    resourceExtender.getExtenderType())) {
                        resourceExtender
                                .setIdExtendableResource(realResourceExtender.getIdExtendableResource());

                        break;
                    }
                }
            }

            String strHtml = StringUtils.EMPTY;

            if (!bParameteredId || !StringUtils.equalsIgnoreCase(resourceExtender.getIdExtendableResource(),
                    EXTEND_PARAMETERED_ID)) {
                // 3) Get the html content from the given information
                if (!StringUtils.equals(resourceExtender.getExtendableResourceType(), Page.RESOURCE_TYPE)
                        || (StringUtils.isBlank(request.getParameter(PARAM_PAGE))
                                && StringUtils.isBlank(request.getParameter(PARAM_PORTLET_ID)))) {
                    strHtml = _extenderService.getContent(resourceExtender.getIdExtendableResource(),
                            resourceExtender.getExtendableResourceType(), resourceExtender.getExtenderType(),
                            resourceExtender.getParameters(), request);
                }
            }

            // 4) Replace the markers by the html content
            match.appendReplacement(strResultHTML, Matcher.quoteReplacement(strHtml));
        }
        match.appendTail(strResultHTML);
        strHtmlContent = strResultHTML.toString();
    }

    if (StringUtils.isNotBlank(_strExtenderParameterRegexPattern)) {
        strHtmlContent = _extendedParameterRegexPattern.matcher(strHtmlContent).replaceAll("");
    }

    return strHtmlContent;
}

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

/**
 * Permet de rcuprer les rsultats pour les tops
 * //from ww w  .  ja v  a  2s.  c  o m
 * @param pRequest requete HTTP
 * @param pTopListForm TopListForm formulaire a lire
 * @throws Exception exception
 */
private void getResults(final HttpServletRequest pRequest, final TopListForm pTopListForm) throws Exception {

    IApplicationComponent ac = AccessDelegateHelper.getInstance("Results");

    // recupere l'audit courant
    List auditDTOs = ActionUtils.getCurrentAuditsAsDTO(pRequest);
    AuditDTO audit = null;
    if (auditDTOs != null) {
        audit = (AuditDTO) (auditDTOs.get(0));
    }

    // et le projet courant
    ComponentDTO project = (ComponentDTO) pRequest.getSession().getAttribute(BaseDispatchAction.PROJECT_DTO);

    // appelle getTopResults de squaleCommon
    Object[] paramIn = { project, pTopListForm.getComponentType(), audit, pTopListForm.getTre(),
            new Integer(WebMessages.getString(pRequest.getLocale(), "component.max")) };
    // Limitation du nombre de rsultats
    ResultsDTO result = (ResultsDTO) ac.execute("getTopResults", paramIn);

    ArrayList components = new ArrayList();

    // et met les resultats en formes pour la jsp (Bean)
    if (result != null) {
        List componentDtoList = (List) result.getResultMap().get(null);
        result.getResultMap().remove(null);

        AuditDTO nextKey = (AuditDTO) result.getResultMap().keySet().iterator().next();
        List valuesList = (List) result.getResultMap().get(nextKey);

        // Conversion des ComponentDTO en Form
        ComponentDTO dto = null;
        ComponentForm form = null;
        // Parcours de chacun des composants
        for (int i = 0; i < componentDtoList.size(); i++) {
            dto = (ComponentDTO) componentDtoList.get(i);
            form = new ComponentForm();
            form.setId(dto.getID());
            form.setName(dto.getName());
            form.setFullName(dto.getFullName());
            if (valuesList.get(i) == null) {
                // Placement d'une chane par dfaut
                form.getMetrics().add(0, WebMessages.getString(pRequest.getLocale(), "result.cant_display"));
            } else {
                form.getMetrics().add(0, valuesList.get(i) + "");
            }
            components.add(form);
        }

    }
    pTopListForm.setComponentListForm(components);

}