Example usage for com.liferay.portal.kernel.servlet SessionMessages add

List of usage examples for com.liferay.portal.kernel.servlet SessionMessages add

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.servlet SessionMessages add.

Prototype

public static void add(PortletRequest portletRequest, String key) 

Source Link

Usage

From source file:com.rivetlogic.geoip.portlet.IPGeoServicesPortlet.java

License:Open Source License

public void processGeoipFiles(ActionRequest request, ActionResponse response) {
    UploadPortletRequest uploadRequest = PortalUtil.getUploadPortletRequest(request);

    File locationsFile = uploadRequest.getFile(IPGeoServicesPortletConstants.ATTR_GEOIP_LOCATIONS_CSV);
    File blocksFile = uploadRequest.getFile(IPGeoServicesPortletConstants.ATTR_GEOIP_BLOCKS_CSV);

    ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY);
    ServiceContext serviceContext = new ServiceContext();
    serviceContext.setScopeGroupId(themeDisplay.getScopeGroupId());

    try {//from  w w  w  .  j a  v a  2 s.c  om
        InputStream locations = new FileInputStream(locationsFile);
        InputStream blocks = new FileInputStream(blocksFile);

        Message message = new Message();
        message.put(IPGeoServicesPortletConstants.ATTR_GEOIP_LOCATIONS_CSV, locations);
        message.put(IPGeoServicesPortletConstants.ATTR_GEOIP_BLOCKS_CSV, blocks);
        message.put(IPGeoServicesPortletConstants.RESPONSE_RECEIVER,
                IPGeoServicesPortletConstants.MESSAGE_RESPONSE);
        message.put(IPGeoServicesPortletConstants.USER_ID, themeDisplay.getUserId());
        MessageBusUtil.sendMessage(IPGeoServicesPortletConstants.MESSAGE_DESTINATION, message);

        SessionMessages.add(request, IPGeoServicesPortletConstants.UPLOAD_SUCCESS_KEY);
    } catch (FileNotFoundException e) {
        SessionErrors.add(request, IPGeoServicesPortletConstants.ERROR_PROCESSING_CSV);
        logger.error(e);
    }
}

From source file:com.rivetlogic.hangouts.portlet.HangoutsPortlet.java

License:Open Source License

public void savePreferences(ActionRequest request, ActionResponse response)
        throws ReadOnlyException, ValidatorException, IOException {
    PreferencesBean prefBean = new PreferencesBean();
    prefBean.save(request);/*w w  w .  j a v a 2  s  . c  o m*/
    SessionMessages.add(request,
            PortalUtil.getPortletId(request) + SessionMessages.KEY_SUFFIX_UPDATED_PREFERENCES);

    String redirect = getRedirect(request, response);

    if (Validator.isNotNull(redirect)) {
        response.sendRedirect(redirect);
    }
}

From source file:com.rivetlogic.portlet.AnnouncerPortlet.java

License:Open Source License

/**
 * Default article./*from  w  ww.  ja va 2 s. c  om*/
 *
 * @param request the request
 * @param response the response
 */
public void defaultArticle(ActionRequest request, ActionResponse response) {
    String defaultArticle = ParamUtil.getString(request, ARTICLE_ID);
    PortletPreferences preferences = request.getPreferences();
    try {
        preferences.setValue(DEFAULT_ARTICLE, defaultArticle);
        preferences.store();
    } catch (ReadOnlyException e) {
        LOG.error(e);
    } catch (ValidatorException e) {
        LOG.error(e);
    } catch (IOException e) {
        LOG.error(e);
    }
    SessionMessages.add(request, ARTICLE_DEAFULT);
}

From source file:com.rivetlogic.portlet.AnnouncerPortlet.java

License:Open Source License

/**
 * Up article.//from w  ww  .  j a va2  s .  c  o  m
 *
 * @param request the request
 * @param response the response
 * @throws PortletException the portlet exception
 * @throws IOException Signals that an I/O exception has occurred.
 * @throws PortalException the portal exception
 * @throws SystemException the system exception
 */
public void upArticle(ActionRequest request, ActionResponse response)
        throws PortletException, IOException, PortalException, SystemException {

    ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY);
    long groupId = themeDisplay.getScopeGroupId();
    request.setAttribute(GROUP_ID, groupId);

    String articleId = ParamUtil.getString(request, ARTICLE_ID);
    PortletPreferences preferences = request.getPreferences();

    String[] ids = preferences.getValue(ARTICLE_ID, LR_EMPTY_VALUE).split(ARTICLE_SELECTION_DELIMITER);
    List<String> currentArticles = new ArrayList<String>();
    for (int i = 0; i < ids.length; i++) {
        currentArticles.add(ids[i]);
    }

    int index = currentArticles.indexOf(articleId);
    if (index != 0) {
        Collections.swap(currentArticles, index, index - 1);
    }

    String articlesRaw = StringPool.BLANK;
    for (int i = 0; i < currentArticles.size(); i++) {
        articlesRaw += currentArticles.get(i) + StringPool.SPACE;
    }

    updatePreferences(request, response, articlesRaw);
    ids = preferences.getValue(ARTICLE_ID, LR_EMPTY_VALUE).split(ARTICLE_SELECTION_DELIMITER);
    request.setAttribute(IDS, ids);

    String defaultArticle = preferences.getValue(DEFAULT_ARTICLE, LR_EMPTY_VALUE);
    request.setAttribute(DEFAULT_ARTICLE, defaultArticle);

    SessionMessages.add(request, ARTICLE_UP_DOWN);

    sendRedirect(request, response);
}

From source file:com.rivetlogic.portlet.AnnouncerPortlet.java

License:Open Source License

/**
 * Down article./*w  w w .j  ava2s.  c o  m*/
 *
 * @param request the request
 * @param response the response
 * @throws PortletException the portlet exception
 * @throws IOException Signals that an I/O exception has occurred.
 * @throws PortalException the portal exception
 * @throws SystemException the system exception
 */
public void downArticle(ActionRequest request, ActionResponse response)
        throws PortletException, IOException, PortalException, SystemException {

    ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY);
    long groupId = themeDisplay.getScopeGroupId();
    request.setAttribute(GROUP_ID, groupId);

    String articleId = ParamUtil.getString(request, ARTICLE_ID);
    PortletPreferences preferences = request.getPreferences();

    String[] ids = preferences.getValue(ARTICLE_ID, LR_EMPTY_VALUE).split(ARTICLE_SELECTION_DELIMITER);
    List<String> currentArticles = new ArrayList<String>();
    for (int i = 0; i < ids.length; i++) {
        currentArticles.add(ids[i]);
    }

    int index = currentArticles.indexOf(articleId);
    if (index != (currentArticles.size() - 1)) {
        Collections.swap(currentArticles, index, index + 1);
    }

    String articlesRaw = StringPool.BLANK;
    for (int i = 0; i < currentArticles.size(); i++) {
        articlesRaw += currentArticles.get(i) + StringPool.SPACE;
    }

    updatePreferences(request, response, articlesRaw);
    ids = preferences.getValue(ARTICLE_ID, LR_EMPTY_VALUE).split(ARTICLE_SELECTION_DELIMITER);
    request.setAttribute(IDS, ids);

    String defaultArticle = preferences.getValue(DEFAULT_ARTICLE, LR_EMPTY_VALUE);
    request.setAttribute(DEFAULT_ARTICLE, defaultArticle);

    SessionMessages.add(request, ARTICLE_UP_DOWN);

    sendRedirect(request, response);
}

From source file:com.rivetlogic.portlet.GoogleDriveQuickLinks.java

License:Open Source License

@Override
public void doView(RenderRequest request, RenderResponse response) throws IOException, PortletException {

    addDriveParamsToRequest(request);/* w w w.j a v a 2  s .com*/

    ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY);
    if (!themeDisplay.isSignedIn()) {
        SessionMessages.add(request, request.getAttribute(WebKeys.PORTLET_ID)
                + SessionMessages.KEY_SUFFIX_HIDE_DEFAULT_ERROR_MESSAGE);
        SessionErrors.add(request, "portlet-user-not-logged");
    }
    super.doView(request, response);
}

From source file:com.rivetlogic.portlet.TipOfTheDayDockbarPortlet.java

License:Open Source License

/**
 * Sets the article to display./*from w  w  w.j  av  a  2s.  co m*/
 *
 * @param request the new article to display
 */
private void setArticleToDisplay(RenderRequest request) {

    String articleIdsString = ParamUtil.getString(request, WebKeys.ARTICLE_IDS);
    request.setAttribute(WebKeys.ARTICLE_IDS, articleIdsString);
    String[] articleIds = StringUtil.split(articleIdsString);
    String articleId = ParamUtil.getString(request, WebKeys.ARTICLE_ID);
    request.setAttribute(WebKeys.ARTICLE_ID, articleId);
    request.setAttribute(WebKeys.SHOW_ARTICLE_TITLE, getShowArticleTitle(PortalUtil.getCompanyId(request)));

    if (articleIds.length > 0) {

        if (articleIds.length != 1) {
            selectTip(request, articleIds, articleId);

        } else {
            request.setAttribute(WebKeys.DISABLE_PREV, true);
            request.setAttribute(WebKeys.DISABLE_NEXT, true);
        }

    } else {
        SessionMessages.add(request, ERROR_MESSAGE_NO_TIPS_DISPLAY);
        request.setAttribute(WebKeys.DISABLE_PREV, true);
        request.setAttribute(WebKeys.DISABLE_NEXT, true);
    }
}

From source file:com.rivetlogic.speech.portlet.SpeechPortlet.java

License:Open Source License

/**
 * Action to add new speech command and its value.
 *
 * @param request ActionRequest/* ww  w . ja v  a2  s  .c  o m*/
 * @param response ActionResponse
 * @throws PortalException
 * @throws SystemException
 */
public void addCommandAction(ActionRequest request, ActionResponse response)
        throws PortalException, SystemException {
    PortletPreferences preference;
    try {
        String voiceCommand = ParamUtil.getString(request, SpeechConstants.DELETE_VOICE_COMMAND);
        if (voiceCommand != null && !voiceCommand.trim().isEmpty()) {
            preference = SpeechUtil.deleteVoiceCommand(request, voiceCommand);
        } else {
            preference = request.getPreferences();
        }
        preference.setValue(SpeechConstants.KEY_PHRASE,
                ParamUtil.getString(request, SpeechConstants.KEY_PHRASE));
        preference.setValue(ParamUtil.getString(request, SpeechConstants.VOICE_COMMAND),
                ParamUtil.getString(request, SpeechConstants.VOICE_COMMAND_VALUE));
        preference.store();

        SessionMessages.add(request, SESSION_MESSAGE_SUCCESS);
    } catch (ReadOnlyException e) {
        _log.error(e);
    } catch (ValidatorException e) {
        _log.error(e);
    } catch (IOException e) {
        _log.error(e);
    }
}

From source file:com.stc.poc.controller.StcPocController.java

License:Open Source License

/**
 * //w  w w.j av  a 2 s.c o m
 * @param actionRequest
 * @param actionResponse
 * @param model 
 */
public void cancelDeduction(RenderRequest actionRequest, RenderResponse actionResponse, ModelMap model) {

    String deductionId = ParamUtil.get(actionRequest, "idDeduction", "");
    if (deductionId != null) {
        try {

            String message = facade.cancelDeduction(deductionId, actionRequest);
            if (SessionErrors.isEmpty(actionRequest)) {
                SessionMessages.add(actionRequest, "cancel-succes");
                model.addAttribute("message", message);
            } else {
                SessionErrors.add(actionRequest, "succes-cancel-deduction");
                model.addAttribute("message", message);
            }

        } catch (NumberFormatException e) {
            _log.error(e.getMessage(), e);
            SessionErrors.add(actionRequest, "poc-stc-error");
        } catch (ServicesConnectException e) {
            _log.error(e.getMessage(), e);
            SessionErrors.add(actionRequest, "poc-stc-error");
        } catch (PortalException e) {
            _log.error(e.getMessage(), e);
            SessionErrors.add(actionRequest, "poc-stc-error");
        } catch (SystemException e) {
            _log.error(e.getMessage(), e);
            SessionErrors.add(actionRequest, "poc-stc-error");
        }
    }
}

From source file:com.stc.poc.controller.StcPocController.java

License:Open Source License

@RenderMapping(params = "action=editDeduction")
public String editDeduction(RenderRequest actionRequest, RenderResponse actionResponse) {

    String deductionId = ParamUtil.get(actionRequest, "deductionId", "");
    if (deductionId != null) {
        try {/*from   w ww  .j  a v  a  2  s .co m*/

            //facade.editDeduction(deductionId, actionRequest);
            if (!SessionErrors.isEmpty(actionRequest)) {
                SessionErrors.add(actionRequest, "error-edit-deduction");
            } else {
                SessionMessages.add(actionRequest, "succes-delete-deduction");
            }

        } catch (NumberFormatException e) {
            _log.error(e.getMessage(), e);
        }
    }
    return "EditDeduction";
}