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:com.hphoto.server.ApiServlet.java

public void addCategory(Document doc, Element channel, HttpServletRequest request) {
    assert (request.getParameter("user") != null);

    String requestUrl = request.getRequestURL().toString();
    String base = "http://" + request.getServerName()
            + (request.getLocalPort() == 80 ? "" : ":" + Integer.toString(request.getLocalPort()));
    Category[] categories = null;/*from   ww w .  j a v  a 2  s .c om*/
    UserProfile[] users = null;
    String owner = request.getParameter("user");
    String feed = request.getParameter("feed");
    String language = request.getParameter("hl");
    String kind = request.getParameter("kind");
    String albumid = request.getParameter("albumid");
    //Local local = language == null ? request.getLocale() : new Locale(language);
    boolean all = request.getParameter("acess") != null && request.getParameter("acess").equals("all");
    boolean api = feed != null && feed.equals("api");

    try {
        users = server.getUser(owner, 1);
        categories = server.getCategories(owner);
    } catch (IOException e) {
        e.printStackTrace();
        return;
    }

    if (users == null || users.length == 0) {
        return;
    }

    addNode(doc, channel, "atom", "id", base + "/feed/" + feed + "/user/" + owner);
    addNode(doc, channel, "lastBuildDate", (new Date()).toString());
    addNode(doc, channel, "title", owner + " " + I18nUtil.getText(key, "title", request.getLocale()));
    addNode(doc, channel, "description", "");
    //add base,not complete
    addNode(doc, channel, "link", base + "/" + owner);
    addNode(doc, channel, "managingEditor", owner);
    addNode(doc, channel, "generator", "hphoto.com");
    addNode(doc, channel, "opensearch", "totalResults", "" + (categories != null ? categories.length : 0));
    //addNode(doc, channel, "opensearch", "startIndex", ""+1);
    //addNode(doc, channel, "opensearch", "itemsPerPage", ""+1000);
    Element image = addNode(doc, channel, "image");
    addNode(doc, image, "url", base + "/image/" + owner + "/" + "AHHYILU" + "/s48-c/" + owner);
    addNode(doc, image, "title", owner + " " + I18nUtil.getText(key, "title", request.getLocale()));
    addNode(doc, image, "link", base + "/" + owner);

    //channel
    if (categories != null) {
        for (Category category : categories) {
            if (!all) {
                if (!category.isOpened() || category.getCount() < 1) {
                    continue;
                }
            }
            Element item = addNode(doc, channel, "item");
            addNode(doc, item, "pubDate", category.getCreatdate().toString());
            addNode(doc, item, "atom", "updated", category.getLastupload().toString());
            addNode(doc, item, "title", category.getName());
            addNode(doc, item, "description",
                    getDescription(api, base, owner, category, I18nUtil.getLoacl(request)));
            addNode(doc, item, "link", "");
            addNode(doc, item, "author", owner);
            if (api) {
                //api data here
            }
            Element media = addNode(doc, item, "media:group");
            Element title = addNode(doc, media, "media", "title", category.getName());
            addAttribute(doc, title, "type", "plain");

            Element descript = addNode(doc, media, "media", "descript", "");
            addAttribute(doc, descript, "type", "plain");

            addNode(doc, media, "media", "keywords", "");

            String lablename = category.getLablename();
            String imgurl = category.getImgurl();
            String id = imgurl.substring(imgurl.lastIndexOf('/') + 1, imgurl.lastIndexOf('.'));
            String img = "/image/" + owner + "/" + lablename + "/" + id + ".jpg";
            String thumbnailImg = "/image/" + owner + "/" + lablename + "/s" + 160 + "-c/" + id + ".jpg";
            Element content = addNode(doc, media, "media", "content", "");
            addAttribute(doc, content, "url", base + img);
            addAttribute(doc, content, "type", "image/jpeg");
            addAttribute(doc, content, "medium", "image");

            Element thum = addNode(doc, media, "media", "thumbnail", "");
            addAttribute(doc, thum, "url", base + thumbnailImg);
            addAttribute(doc, thum, "height", "160");
            addAttribute(doc, thum, "width", "160");

            addNode(doc, media, "media", "credit", owner);

        }

    }

}

From source file:com.hp.avmon.config.service.AgentManageService.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("agentNewProgramMsg") + "'}";
    } else {//  w  w  w . jav a2s  .  co m
        json = "{success:false,msg:'" + result + "'}";
    }
    return json;
}

From source file:fr.paris.lutece.plugins.directory.modules.gismap.service.GismapDirectoryService.java

public String getMapTemplateWithDirectoryGismapSources(HttpServletRequest request, String viewId,
        List<DirectoryGismapSourceQuery> listGeojsonSources) {
    Map<String, Object> model = new HashMap<>();

    if (StringUtils.isEmpty(viewId)) {
        return "<span>" + I18nService.getLocalizedString(UNAVAILABILITY_MESSAGE, Locale.FRENCH) + "</span>";
    }//from  www .j  a  v a  2s. c om

    String strDefaultView = AppPropertiesService.getProperty(GISMAP_DEFAULT_VIEW_PROPERTIES, "0");

    View view = ViewHome.findByPrimaryKey(Integer.parseInt(viewId));

    MapParameter tmp = view.getMapParameter();

    String strWSUrl = AppPathService.getBaseUrl(request).concat(GISMAP_URL_REST);

    for (DirectoryGismapSourceQuery geojsonSource : listGeojsonSources) {
        String strIndex = String.valueOf(geojsonSource.getGeoJsonIndex());
        String strIdDirectory = String.valueOf(geojsonSource.getIdDirectory());
        String strIdEntryGeolocation = String.valueOf(geojsonSource.getIdGeolocationEntry());
        String strView = StringUtils.isEmpty(geojsonSource.getView()) ? strDefaultView
                : geojsonSource.getView();

        String strWSUrlWithParams = UriBuilder.fromUri(strWSUrl)
                .queryParam(PARAM_ID_GEOLOCATION_ENTRY, strIdEntryGeolocation)
                .queryParam(PARAM_ID_DIRECTORY, strIdDirectory).queryParam(PARAM_GEOJSONINDEX, strIndex)
                .queryParam(PARAM_VIEW, strView).build().toString();

        tmp.setParameters(PARAM_VIEW_URLGEOJSON.concat(strIndex), "'" + strWSUrlWithParams + "'");
    }

    view.setMapParameter(tmp);

    model.put(PARAMETER_MAP_PARAMETER, view.getMapParameter());
    model.put(PARAMETER_ADD_PARAMETER, view.getAddressParam());
    model.put(PARAMETER_DEFAULT_VIEW, strDefaultView);

    Locale locale = (request == null) ? LocaleService.getDefault() : request.getLocale();
    HtmlTemplate templateList = AppTemplateService.getTemplate(view.getMapTemplateFile(), locale, model);

    return templateList.getHtml();
}

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

/**
 * Get the XPage for sending a email to a friend
 * @param request {@link HttpServletRequest}
 * @param plugin {@link Plugin}/*w ww  .  jav  a 2  s  .c  om*/
 * @return the html
 */
private XPage getGetFriendEmailPage(HttpServletRequest request, Plugin plugin) {
    XPage page = null;
    String strCalendarId = request.getParameter(Constants.PARAM_AGENDA);
    String strEventId = request.getParameter(Constants.PARAMETER_EVENT_ID);
    if (StringUtils.isNotBlank(strCalendarId) && StringUtils.isNumeric(strCalendarId)
            && StringUtils.isNotBlank(strEventId) && StringUtils.isNumeric(strEventId)) {
        page = new XPage();
        Map<String, Object> model = new HashMap<String, Object>();
        model.put(Constants.MARK_LOCALE, request.getLocale());
        model.put(Constants.MARK_EVENT_ID, Integer.parseInt(strEventId));
        model.put(Constants.MARK_CALENDAR_ID, Integer.parseInt(strCalendarId));

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

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

    return page;
}

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

/**
 * The modification screen of a plugin application
 *
 * @param request The Http Request//  w  w  w.  j  av a2s.co m
 * @return The XPage
 */
@View(VIEW_MODIFY_APPLICATION)
public XPage getModifyApplication(HttpServletRequest request) {
    PluginModel pm = ModelService.getPluginModel(_nPluginId);
    int nApplicationId = Integer.parseInt(request.getParameter(PARAM_APPLICATION_ID));

    if ((_application == null) || (_application.getId() != nApplicationId)) {
        _application = ModelService.getApplication(_nPluginId, nApplicationId);
    }

    Map<String, Object> model = getPluginModel();
    model.put(MARK_APPLICATION, _application);
    model.put(MARK_PLUGIN_APPLICATIONS, pm.getApplications());
    model.put(MARK_BUSINESS_CLASSES_COMBO, ModelService.getComboBusinessClasses(_nPluginId));
    model.put(MARK_PLUGIN_ID, Integer.toString(_nPluginId));

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

From source file:fr.paris.lutece.plugins.mydashboard.web.MyDashboardApp.java

/**
 * Get the list of dash boards of the current user
 * @param request The request, with the user logged in
 * @return The XPage to display the list of dash boards of the user
 * @throws UserNotSignedException If the user is not logged in
 *///from  w  w w  .java 2 s .co m
@View(value = VIEW_GET_DASHBOARDS, defaultView = true)
public XPage getDashboards(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<IMyDashboardComponent> listDashboardComponents;

    if (dashboardService.isPanelEnabled()) {
        Panel panel = null;
        String strPanelCode = request.getParameter(PARAMETER_PANEL);

        if (!StringUtils.isEmpty(strPanelCode)) {
            panel = PanelHome.findByCode(strPanelCode);
        }

        if (panel == null) {
            panel = PanelHome.getDefaultPanel();
        }

        listDashboardComponents = dashboardService.getDashboardComponentListFromUser(luteceUser, panel);
        model.put(MARK_LIST_PANEL, PanelHome.getPanelsList());
        model.put(MARK_PANEL_SELECTED, panel);
    } else {
        listDashboardComponents = dashboardService.getDashboardComponentListFromUser(luteceUser);
    }

    List<String> listDashboardContent = new ArrayList<String>(listDashboardComponents.size());

    for (IMyDashboardComponent dashboardComponent : listDashboardComponents) {
        if (dashboardComponent.isAvailable(luteceUser)) {
            listDashboardContent.add(dashboardComponent.getDashboardData(request));
        }
    }

    model.put(MARK_LIST_DASHBOARDS_CONTENT, listDashboardContent);

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

From source file:fr.paris.lutece.plugins.crm.modules.form.service.draft.CRMDraftBackupService.java

/**
 * Create a draft/*ww w. j  av  a 2  s. c o  m*/
 * @param request the HTTP request
 * @param form the form
 */
private void create(HttpServletRequest request, Form form) {
    HttpSession session = request.getSession(true);

    String strDemandType = _crmParametersService.getIdTypeDemande(request, form);
    String strCrmWebAppCode = _crmParametersService.getCrmWebAppCode(request, form);

    if (StringUtils.isNotBlank(strDemandType)) {
        JSONObject json = new JSONObject();
        json.element(JSONUtils.JSON_KEY_ID_FORM, form.getIdForm());

        // the data is only the key - no need to store any other data
        String strData = _blobStoreService.store(json.toString().getBytes());

        try {
            // save user info and demand to CRM
            String strIdCRMUser = request.getParameter(Constants.PARAM_ID_CRM_USER);
            String strUserGuid = StringUtils.EMPTY;
            String strIdDemand = StringUtils.EMPTY;

            if (StringUtils.isBlank(strIdCRMUser) && SecurityService.isAuthenticationEnable()) {
                LuteceUser user = SecurityService.getInstance().getRemoteUser(request);

                if (user != null) {
                    strUserGuid = user.getName();
                }
            }

            String strStatusText = I18nService.getLocalizedString(Constants.PROPERTY_CRM_STATUS_TEXT_NEW,
                    request.getLocale());

            if (StringUtils.isNotBlank(strUserGuid)) {
                strIdDemand = _crmClientService.sendCreateDemandByUserGuid(strDemandType, strUserGuid,
                        CrmClientConstants.CRM_STATUS_DRAFT, strStatusText, strData, strCrmWebAppCode);

            } else if (StringUtils.isNotBlank(strIdCRMUser)) {
                strIdDemand = _crmClientService.sendCreateDemandByIdCRMUser(strDemandType, strIdCRMUser,
                        CrmClientConstants.CRM_STATUS_DRAFT, strStatusText, strData, strCrmWebAppCode);
            }

            if (StringUtils.isNotBlank(strIdDemand) && !Constants.INVALID_ID.equals(strIdDemand)) {

                try {
                    strUserGuid = _crmClientService.getUserGuidFromIdDemand(strIdDemand, strCrmWebAppCode);
                } catch (CRMException ex) {
                    _logger.error("Error calling WebService : " + ex.getMessage(), ex);
                }
                updateSessionAttributes(session, strIdDemand, strData, strUserGuid, strCrmWebAppCode);
            } else {
                throw new Exception("Invalid ID demand");
            }
        } catch (Exception e) {
            _logger.error("Error calling WebService : " + e.getMessage(), e);

            // Remove the blob created previously
            _blobStoreService.delete(strData);
        }
    }
}

From source file:fr.paris.lutece.plugins.workflow.modules.ticketing.web.task.EditTicketTaskComponent.java

/**
 * {@inheritDoc}/*from  w w w .  j a va  2  s.com*/
 */
@Override
public String getDisplayTaskForm(int nIdResource, String strResourceType, HttpServletRequest request,
        Locale locale, ITask task) {
    TaskEditTicketConfig config = this.getTaskConfigService().findByPrimaryKey(task.getId());

    if (config == null) {
        return AdminMessageService.getMessageUrl(request, TaskEditTicketConstants.MESSAGE_NO_CONFIGURATION,
                AdminMessage.TYPE_STOP);
    }

    MessageDirection messageDirection = config.getMessageDirection();

    Map<String, Object> model = new HashMap<String, Object>();
    model.put(MARK_CONFIG, config);
    model.put(MARK_AGENT_VIEW, messageDirection == MessageDirection.AGENT_TO_USER);

    Ticket ticket = getTicket(nIdResource, strResourceType);

    if (messageDirection == MessageDirection.AGENT_TO_USER) {
        TicketForm ticketForm = TicketFormHome.findByCategoryId(ticket.getIdTicketCategory());

        if (ticketForm != null) {
            EntryFilter filter = new EntryFilter();
            filter.setIdResource(ticketForm.getIdForm());
            filter.setResourceType(TicketForm.RESOURCE_TYPE);
            filter.setEntryParentNull(EntryFilter.FILTER_TRUE);
            filter.setFieldDependNull(EntryFilter.FILTER_TRUE);

            List<Entry> listEntryFirstLevel = EntryHome.getEntryList(filter);

            model.put(MARK_LIST_ENTRIES, listEntryFirstLevel);
        }

        TicketHelper.storeRichTextMarksIntoModel(request, model);
    } else {
        EditableTicket editableTicket = _editableTicketService.findByIdTicket(ticket.getId());

        List<Entry> listEntries = _editableTicketService.buildListEntriesToEdit(request,
                editableTicket.getListEditableTicketFields());

        String htmlForm = _ticketFormService.getHtmlForm(listEntries, request.getLocale(), false, request);

        model.put(TaskEditTicketConstants.MARK_EDITABLE_TICKET, editableTicket);
        model.put(TaskEditTicketConstants.MARK_ENTRIES_HTML_FORM, htmlForm);
    }

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

    return template.getHtml();
}