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:fr.paris.lutece.plugins.genericattributes.service.entrytype.AbstractEntryTypeTextArea.java

/**
 * {@inheritDoc}//  w w  w. ja  v a2 s.  com
 */
@Override
public GenericAttributeError getResponseData(Entry entry, HttpServletRequest request,
        List<Response> listResponse, Locale locale) {
    String strValueEntry = request.getParameter(PREFIX_ATTRIBUTE + entry.getIdEntry());
    Response response = new Response();
    response.setEntry(entry);

    if (strValueEntry != null) {
        int nMaxSize = entry.getFields().get(0).getMaxSizeEnter();

        if (getUseRichText(entry)) {
            response.setResponseValue(EditorBbcodeService.getInstance().parse(strValueEntry));
        } else {
            response.setResponseValue(strValueEntry);
        }

        if (StringUtils.isNotBlank(response.getResponseValue())) {
            // if we use a rich text, we set the toStringValueResponse to the BBCode string
            if (getUseRichText(entry)) {
                response.setToStringValueResponse(strValueEntry);
            } else {
                response.setToStringValueResponse(getResponseValueForRecap(entry, request, response, locale));
            }
        } else {
            response.setToStringValueResponse(StringUtils.EMPTY);
        }

        listResponse.add(response);

        // Checks if the entry value contains XSS characters
        if (StringUtil.containsXssCharacters(strValueEntry)) {
            GenericAttributeError error = new GenericAttributeError();
            error.setMandatoryError(false);
            error.setTitleQuestion(entry.getTitle());
            error.setErrorMessage(I18nService.getLocalizedString(MESSAGE_XSS_FIELD, request.getLocale()));

            return error;
        }

        // check max size for the field. 0 means no limit
        if ((nMaxSize != -1) && (strValueEntry.length() > nMaxSize)) {
            GenericAttributeError error = new GenericAttributeError();
            error.setMandatoryError(false);
            error.setTitleQuestion(entry.getTitle());

            Object[] messageArgs = new Object[] { nMaxSize, };
            error.setErrorMessage(
                    I18nService.getLocalizedString(MESSAGE_MAXLENGTH, messageArgs, request.getLocale()));

            return error;
        }

        if (entry.isMandatory() && StringUtils.isBlank(strValueEntry)) {
            return new MandatoryError(entry, locale);
        }
    }

    return null;
}

From source file:net.duckling.ddl.web.controller.LynxEditPageController.java

@RequestMapping
@WebLog(method = "loadEditMode", params = "pid,bid")
public ModelAndView prepareEditPage(HttpServletRequest request, @RequestParam("rid") Integer rid) {
    VWBContext context = getEditPageContext(request, rid);
    int tid = VWBContext.getCurrentTid();
    int parentRid = getPatentRidFromRequest(request);
    PageRender render = getPageRender(rid, context);
    context.setWysiwygEditorMode(VWBContext.EDITOR_MODE);
    int version = getRequestVersion(request);
    if (version != VWBContext.LATEST_VERSION && version != render.getMeta().getLastVersion()) {
        request.setAttribute("version", version);
        request.setAttribute("latestVersion", render.getMeta().getLastVersion());
    }//  w ww  .ja va  2 s  .c o m
    PageLock lock = pageLockService.getCurrentLock(getTeamId(context), rid);
    if (lock != null && (!isLockHolder(context, lock))) {
        return pageLocked(request, rid);
    }
    boolean isNewPage = isNewPage(render);
    Draft draft = getLastestDraft(context, rid);
    List<Tag> tags = tagService.getTagsNotInGroupForTeam(tid);
    ModelAndView mv = null;
    if (draft != null) {
        if (isNewPage) {
            mv = loadEditorWithContent(context, render, draft.getContent(), request.getLocale().toString());
        } else {
            mv = compareDraft(context, render, draft, parentRid);
            mv.addObject("draft", draft);
        }
    } else {
        if (isNewPage) {
            mv = loadEditorWithContent(context, render, "", request.getLocale().toString());
        } else {
            String innerHTML = getDPageContent(context, render, draft);
            mv = loadEditorWithContent(context, render, innerHTML, request.getLocale().toString());
        }
    }
    this.loadAttachmentList(mv, context, rid);
    // add by lvly BEGIN
    // ?
    String useTagIds = request.getParameter("tagIds");
    if (!CommonUtil.isNullStr(useTagIds)) {
        Integer[] tagIds = CommonUtil.stringArray2IntArray(useTagIds.split(","));
        tagService.addItems(tid, CommonUtil.array2List(tagIds), rid);
        for (Integer tagId : tagIds) {
            Tag tag = tagService.getTag(tagId);
            resourceService.updateTagMap(rid, tag);
        }
    }

    // ??
    resourceOperateService.addDefaultTag(rid);
    Team team = teamService.getTeamByID(tid);
    // END
    Resource res = render.getMeta();
    Map<Integer, String> tagMap = (null == res) ? new HashMap<Integer, String>() : res.getTagMap();
    mv.addObject("resource", res);
    mv.addObject("tagMap", tagMap);
    mv.addObject("rid", (null == res) ? 0 : res.getRid());
    mv.addObject("parentRid", parentRid);
    mv.addObject("tags", tags);
    mv.addObject("myspace", isMyspace(team, context.getCurrentUID()));
    return mv;
}

From source file:fr.paris.lutece.plugins.extend.web.component.ResourceExtenderComponentManager.java

/**
 * {@inheritDoc}/*from   w ww. j  av a2 s .  c  o m*/
 */
@Override
public String getHistoryHtml(ResourceExtenderDTO resourceExtender, Locale locale, HttpServletRequest request) {
    if (resourceExtender != null) {
        ResourceExtenderHistoryFilter filter = new ResourceExtenderHistoryFilter();
        filter.setExtenderType(resourceExtender.getExtenderType());
        filter.setIdExtendableResource(resourceExtender.getIdExtendableResource());
        filter.setExtendableResourceType(resourceExtender.getExtendableResourceType());
        filter.setSortedAttributeName(ORDER_BY_DATE_CREATION);
        filter.setAscSort(true);

        List<ResourceExtenderHistory> listHistories = _resourceHistoryService.findByFilter(filter);

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

        UrlItem url = new UrlItem(JSP_URL_VIEW_EXTENDER_HISTORY);
        url.addParameter(PARAMETER_ID_EXTENDER, resourceExtender.getIdExtender());

        LocalizedPaginator<ResourceExtenderHistory> paginator = new LocalizedPaginator<ResourceExtenderHistory>(
                listHistories, _nItemsPerPage, url.getUrl(), Paginator.PARAMETER_PAGE_INDEX,
                _strCurrentPageIndex, request.getLocale());

        Map<String, Object> model = new HashMap<String, Object>();
        model.put(MARK_LIST_HISTORIES, paginator.getPageItems());
        model.put(MARK_RESOURCE_EXTENDER, resourceExtender);
        model.put(MARK_LOCALE, locale);
        model.put(MARK_PAGINATOR, paginator);
        model.put(MARK_NB_ITEMS_PER_PAGE, Integer.toString(paginator.getItemsPerPage()));

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

        return template.getHtml();
    }

    return StringUtils.EMPTY;
}

From source file:com.hp.avmon.kpigetconfig.service.KpigetconfigAgentManageService.java

public String upgradeAgent(HttpServletRequest request) {
    String status = request.getParameter("status");
    String agentId = request.getParameter("agentId");
    String json = "";
    String result = avmonServer.upgradeAgent(agentId);
    Locale locale = request.getLocale();
    ResourceBundle bundle = ResourceBundle.getBundle("messages", locale);

    if (result.startsWith("00")) {
        json = "{success:true,msg:'" + bundle.getString("agentNewProcedureMsg") + "'}";
    } else {/* w  w w .ja  v  a 2s  . c  o  m*/
        json = "{success:false,msg:'" + result + "'}";
    }
    return json;
}

From source file:fr.paris.lutece.plugins.extend.web.ResourceExtenderJspBean.java

/**
 * Gets the creates the default extender resource.
 *
 * @param request the request//w  ww  . j a v  a 2  s . c o m
 * @param response the response
 * @return the creates the default extender resource
 */
public IPluginActionResult getCreateDefaultResourceExtender(HttpServletRequest request,
        HttpServletResponse response) {
    setPageTitleProperty(PROPERTY_CREATE_DEFAULT_RESOURCE_PAGE_TITLE);

    ResourceExtenderDTO resourceExtender = new ResourceExtenderDTO();

    // Populate the bean
    populate(resourceExtender, request);

    // Validate the form
    String strJspError = ExtendUtils.validateResourceExtender(request, resourceExtender);

    if (StringUtils.isNotBlank(strJspError)) {
        IPluginActionResult result = new DefaultPluginActionResult();

        result.setRedirect(strJspError);

        return result;
    }

    Map<String, Object> model = new HashMap<String, Object>();
    model.put(MARK_RESOURCE_EXTENDER, resourceExtender);

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

    IPluginActionResult result = new DefaultPluginActionResult();

    result.setHtmlContent(getAdminPage(template.getHtml()));

    return result;
}

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

/**
 * Delete an account and logout user/*from www. j a v a2 s. co m*/
 * @param request The request
 */
private void deleteAccount(HttpServletRequest request) {
    // Get remote user
    DatabaseUser user = getRemoteUser(request);
    if (user == null) {
        return;
    }

    DatabaseUserHome.remove(user, PluginService.getPlugin(MyLutecePlugin.PLUGIN_NAME));
    DatabaseHome.removeGroupsForUser(user.getUserId(), _plugin);
    DatabaseHome.removeRolesForUser(user.getUserId(), _plugin);
    MyLuteceUserFieldService.doRemoveUserFields(user.getUserId(), request, request.getLocale());
    DatabaseUserKeyService.getService().removeByIdUser(user.getUserId());
    SecurityService.getInstance().logoutUser(request);
}

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

/**
 * Get the XPage for searching an event//from   ww w .  ja  v  a 2  s . co  m
 * @param request {@link HttpServletRequest}
 * @param plugin {@link Plugin}
 * @return the html form
 */
private XPage getSearchPage(HttpServletRequest request, Plugin plugin) {
    XPage page = new XPage();
    Map<String, Object> model = new HashMap<String, Object>();

    model.put(Constants.MARK_NB_ITEMS_PER_PAGE, Integer.toString(_nDefaultItemsPerPage));
    model.put(Constants.MARK_CALENDARS_LIST, getListAgenda(request, plugin));
    model.put(Constants.MARK_AGENDA, Constants.SPACE);
    model.put(Constants.MARK_LOCALE, request.getLocale());

    Collection<Category> categoryList = _categoryService.getCategories(plugin);
    model.put(Constants.MARK_CATEGORY_LIST, getReferenceListCategory(categoryList));

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

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

    return page;
}

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

/**
 * The modification screen of the admin _feature
 *
 * @param request The Http Request//w  w w .ja  v  a 2 s  .co  m
 * @return The html code of the admin _feature
 */
@View(VIEW_MODIFY_ADMIN_FEATURE)
public XPage getModifyAdminFeature(HttpServletRequest request) {
    PluginModel pm = ModelService.getPluginModel(_nPluginId);
    int nFeatureId = Integer.parseInt(request.getParameter(PARAM_FEATURE_ID));

    if ((_feature == null) || (_feature.getId() != nFeatureId)) {
        _feature = ModelService.getFeature(_nPluginId, nFeatureId);
    }

    Map<String, Object> model = getModel();
    model.put(MARK_FEATURE, _feature);
    model.put(MARK_ADMIN_FEATURES, pm.getFeatures());
    model.put(MARK_BUSINESS_CLASSES_COMBO, ModelService.getComboBusinessClasses(_nPluginId));

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

From source file:org.squale.squaleweb.applicationlayer.action.results.audit.AuditAction.java

/**
 * Permet la rcupration de tous les audits de l'application
 * /*from  w ww .j  a  v a  2s. co m*/
 * @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 list(ActionMapping pMapping, ActionForm pForm, HttpServletRequest pRequest,
        HttpServletResponse pResponse) {

    ActionErrors errors = new ActionErrors();
    ActionForward forward = pMapping.findForward("total_failure");
    String kind = pRequest.getParameter("kind");
    try {
        // On efface ces forms contenant car si on passe par ici
        // Ces forms ne peuvent que contenir les informations pour une autre application
        pRequest.getSession().removeAttribute("applicationErrorForm");
        pRequest.getSession().removeAttribute("resultListForm");
        List audits = getAudits(pRequest, getMethodForKind(kind));
        WTransformerFactory.objToForm(AuditListTransformer.class, (SplitAuditsListForm) pForm, audits);
        forward = pMapping.findForward("list");
        // Place l'attribut dans la forme pour etre recuper dans la jsp
        ((SplitAuditsListForm) pForm).setKind(kind);
    } catch (Exception e) {
        handleException(e, errors, pRequest);
    }
    if (!errors.isEmpty()) {
        saveMessages(pRequest, errors);
    }
    // On est pass par un menu donc on rinitialise le traceur
    // et on rajoute la page courante
    String displayName = WebMessages.getString(pRequest.getLocale(), "tracker.audits.list." + kind);
    updateHistTracker(displayName, "audits.do?action=list&kind=" + kind, TrackerStructure.UNDEFINED, pRequest,
            true);
    return (forward);
}