Example usage for com.liferay.portal.kernel.portlet PortletPreferencesFactoryUtil getPortalPreferences

List of usage examples for com.liferay.portal.kernel.portlet PortletPreferencesFactoryUtil getPortalPreferences

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.portlet PortletPreferencesFactoryUtil getPortalPreferences.

Prototype

public static PortalPreferences getPortalPreferences(PortletRequest portletRequest) 

Source Link

Usage

From source file:com.liferay.dynamic.data.mapping.web.internal.display.context.DDMDisplayContext.java

License:Open Source License

public String getOrderByCol() {
    PortalPreferences portalPreferences = PortletPreferencesFactoryUtil.getPortalPreferences(_renderRequest);

    String orderByCol = ParamUtil.getString(_renderRequest, "orderByCol");

    if (Validator.isNull(orderByCol)) {
        orderByCol = portalPreferences.getValue(DDMPortletKeys.DYNAMIC_DATA_MAPPING, "entries-order-by-col",
                "modified-date");
    } else {/*from w w w .  ja  v a2  s  .c o m*/
        portalPreferences.setValue(DDMPortletKeys.DYNAMIC_DATA_MAPPING, "entries-order-by-col", orderByCol);
    }

    return orderByCol;
}

From source file:com.liferay.dynamic.data.mapping.web.internal.display.context.DDMDisplayContext.java

License:Open Source License

public String getOrderByType() {
    PortalPreferences portalPreferences = PortletPreferencesFactoryUtil.getPortalPreferences(_renderRequest);

    String orderByType = ParamUtil.getString(_renderRequest, "orderByType");

    if (Validator.isNull(orderByType)) {
        orderByType = portalPreferences.getValue(DDMPortletKeys.DYNAMIC_DATA_MAPPING, "entries-order-by-type",
                "asc");
    } else {//from   w  w  w.  j a  v a2s  . c o  m
        portalPreferences.setValue(DDMPortletKeys.DYNAMIC_DATA_MAPPING, "entries-order-by-type", orderByType);
    }

    return orderByType;
}

From source file:com.liferay.item.selector.taglib.servlet.taglib.RepositoryEntryBrowserTag.java

License:Open Source License

protected String getDisplayStyle() {
    PortalPreferences portalPreferences = PortletPreferencesFactoryUtil.getPortalPreferences(request);

    String displayStyle = ParamUtil.getString(request, "displayStyle");

    if (Validator.isNotNull(displayStyle)) {
        displayStyle = getSafeDisplayStyle(displayStyle);

        portalPreferences.setValue(ItemSelectorPortletKeys.ITEM_SELECTOR, "display-style", displayStyle);

        return displayStyle;
    }//  w  w w  . ja  v  a  2 s . c o m

    if (Validator.isNotNull(_displayStyle)) {
        return getSafeDisplayStyle(_displayStyle);
    }

    return portalPreferences.getValue(ItemSelectorPortletKeys.ITEM_SELECTOR, "display-style",
            DISPLAY_STYLES[0]);
}

From source file:com.liferay.journal.web.internal.display.context.JournalDisplayContext.java

License:Open Source License

public JournalDisplayContext(HttpServletRequest request, LiferayPortletRequest liferayPortletRequest,
        LiferayPortletResponse liferayPortletResponse, PortletPreferences portletPreferences) {

    _request = request;/*from w  ww .  j a  va2s.co  m*/
    _liferayPortletRequest = liferayPortletRequest;
    _liferayPortletResponse = liferayPortletResponse;
    _portletPreferences = portletPreferences;

    _portalPreferences = PortletPreferencesFactoryUtil.getPortalPreferences(_request);
}

From source file:com.liferay.journal.web.internal.display.context.JournalDisplayContext.java

License:Open Source License

public String[] getAddMenuFavItems() throws PortalException {
    if (_addMenuFavItems != null) {
        return _addMenuFavItems;
    }//from   w  w w . j a  v  a2 s.c  o m

    PortalPreferences portalPreferences = PortletPreferencesFactoryUtil.getPortalPreferences(_request);

    String key = JournalPortletUtil.getAddMenuFavItemKey(_liferayPortletRequest, _liferayPortletResponse);

    _addMenuFavItems = portalPreferences.getValues(JournalPortletKeys.JOURNAL, key, new String[0]);

    return _addMenuFavItems;
}

From source file:com.liferay.journal.web.internal.display.context.JournalDisplayContext.java

License:Open Source License

protected String getDisplayStyle(HttpServletRequest request, String[] displayViews) {

    PortalPreferences portalPreferences = PortletPreferencesFactoryUtil.getPortalPreferences(request);

    String displayStyle = ParamUtil.getString(request, "displayStyle");

    if (Validator.isNull(displayStyle)) {
        JournalWebConfiguration journalWebConfiguration = (JournalWebConfiguration) _request
                .getAttribute(JournalWebConfiguration.class.getName());

        displayStyle = portalPreferences.getValue(JournalPortletKeys.JOURNAL, "display-style",
                journalWebConfiguration.defaultDisplayView());
    } else {/*  w ww.  j a va2s.  c o  m*/
        if (ArrayUtil.contains(displayViews, displayStyle)) {
            portalPreferences.setValue(JournalPortletKeys.JOURNAL, "display-style", displayStyle);

            request.setAttribute(WebKeys.SINGLE_PAGE_APPLICATION_CLEAR_CACHE, Boolean.TRUE);
        }
    }

    if (!ArrayUtil.contains(displayViews, displayStyle)) {
        displayStyle = displayViews[0];
    }

    return displayStyle;
}

From source file:com.liferay.journal.web.internal.portlet.JournalPortlet.java

License:Open Source License

public void addAddMenuFavItem(ActionRequest actionRequest, ActionResponse actionResponse) throws Exception {

    String ddmStructureKey = ParamUtil.getString(actionRequest, "ddmStructureKey");

    PortalPreferences portalPreferences = PortletPreferencesFactoryUtil.getPortalPreferences(actionRequest);

    String key = JournalPortletUtil.getAddMenuFavItemKey(actionRequest, actionResponse);

    String[] addMenuFavItems = portalPreferences.getValues(JournalPortletKeys.JOURNAL, key, new String[0]);

    if (addMenuFavItems.length >= _journalWebConfiguration.maxAddMenuItems()) {

        hideDefaultErrorMessage(actionRequest);

        throw new MaxAddMenuFavItemsException();
    }//from w  w w  .ja  v  a 2  s .  c  om

    portalPreferences.setValues(JournalPortletKeys.JOURNAL, key,
            ArrayUtil.append(addMenuFavItems, ddmStructureKey));

    SessionMessages.add(actionRequest,
            _portal.getPortletId(actionRequest) + SessionMessages.KEY_SUFFIX_REFRESH_PORTLET,
            JournalPortletKeys.JOURNAL);
}

From source file:com.liferay.journal.web.internal.portlet.JournalPortlet.java

License:Open Source License

public void removeAddMenuFavItem(ActionRequest actionRequest, ActionResponse actionResponse) throws Exception {

    String ddmStructureKey = ParamUtil.getString(actionRequest, "ddmStructureKey");

    PortalPreferences portalPreferences = PortletPreferencesFactoryUtil.getPortalPreferences(actionRequest);

    String key = JournalPortletUtil.getAddMenuFavItemKey(actionRequest, actionResponse);

    String[] addMenuFavItems = portalPreferences.getValues(JournalPortletKeys.JOURNAL, key);

    portalPreferences.setValues(JournalPortletKeys.JOURNAL, key,
            ArrayUtil.remove(addMenuFavItems, ddmStructureKey));

    SessionMessages.add(actionRequest,/*from   w  w  w  . j  a  va2s  . c om*/
            _portal.getPortletId(actionRequest) + SessionMessages.KEY_SUFFIX_REFRESH_PORTLET,
            JournalPortletKeys.JOURNAL);
}

From source file:com.liferay.journal.web.internal.search.ArticleSearch.java

License:Open Source License

public ArticleSearch(PortletRequest portletRequest, int cur, int delta, PortletURL iteratorURL) {

    super(portletRequest, new ArticleDisplayTerms(portletRequest), new ArticleSearchTerms(portletRequest),
            "curEntry", cur, delta, iteratorURL, headerNames, null);

    PortletConfig portletConfig = (PortletConfig) portletRequest
            .getAttribute(JavaConstants.JAVAX_PORTLET_CONFIG);

    ArticleDisplayTerms displayTerms = (ArticleDisplayTerms) getDisplayTerms();
    ArticleSearchTerms searchTerms = (ArticleSearchTerms) getSearchTerms();

    String portletName = portletConfig.getPortletName();

    if (!portletName.equals(JournalPortletKeys.JOURNAL)) {
        displayTerms.setStatus(WorkflowConstants.STATUS_APPROVED);
        searchTerms.setStatus(WorkflowConstants.STATUS_APPROVED);
    }//from   www .jav a 2 s  . c om

    iteratorURL.setParameter(ArticleDisplayTerms.ARTICLE_ID, displayTerms.getArticleId());
    iteratorURL.setParameter(ArticleDisplayTerms.CONTENT, displayTerms.getContent());
    iteratorURL.setParameter(ArticleDisplayTerms.DESCRIPTION, displayTerms.getDescription());
    iteratorURL.setParameter(ArticleDisplayTerms.DDM_STRUCTURE_KEY, displayTerms.getDDMStructureKey());
    iteratorURL.setParameter(ArticleDisplayTerms.DDM_TEMPLATE_KEY, displayTerms.getDDMTemplateKey());
    iteratorURL.setParameter(ArticleDisplayTerms.FOLDER_ID, String.valueOf(displayTerms.getFolderId()));
    iteratorURL.setParameter(ArticleDisplayTerms.GROUP_ID, String.valueOf(displayTerms.getGroupId()));
    iteratorURL.setParameter(ArticleDisplayTerms.NAVIGATION, displayTerms.getNavigation());
    iteratorURL.setParameter(ArticleDisplayTerms.STATUS, String.valueOf(displayTerms.getStatus()));
    iteratorURL.setParameter(ArticleDisplayTerms.TITLE, displayTerms.getTitle());
    iteratorURL.setParameter(ArticleDisplayTerms.VERSION, String.valueOf(displayTerms.getVersion()));

    try {
        PortalPreferences preferences = PortletPreferencesFactoryUtil.getPortalPreferences(portletRequest);

        String orderByCol = ParamUtil.getString(portletRequest, "orderByCol");
        String orderByType = ParamUtil.getString(portletRequest, "orderByType");

        if (Validator.isNotNull(orderByCol) && Validator.isNotNull(orderByType)) {

            preferences.setValue(JournalPortletKeys.JOURNAL, "articles-order-by-col", orderByCol);
            preferences.setValue(JournalPortletKeys.JOURNAL, "articles-order-by-type", orderByType);
        } else {
            orderByCol = preferences.getValue(JournalPortletKeys.JOURNAL, "articles-order-by-col", "id");
            orderByType = preferences.getValue(JournalPortletKeys.JOURNAL, "articles-order-by-type", "asc");
        }

        OrderByComparator<JournalArticle> orderByComparator = JournalPortletUtil
                .getArticleOrderByComparator(orderByCol, orderByType);

        setOrderableHeaders(orderableHeaders);
        setOrderByCol(orderByCol);
        setOrderByType(orderByType);
        setOrderByComparator(orderByComparator);
    } catch (Exception e) {
        _log.error(e);
    }
}

From source file:com.liferay.layout.admin.web.internal.display.context.LayoutPageTemplateDisplayContext.java

License:Open Source License

public String getDisplayStyle() {
    if (Validator.isNotNull(_displayStyle)) {
        return _displayStyle;
    }//from  w w  w  . ja v  a 2 s  .co  m

    PortalPreferences portalPreferences = PortletPreferencesFactoryUtil.getPortalPreferences(_request);

    _displayStyle = portalPreferences.getValue(LayoutAdminPortletKeys.GROUP_PAGES, "display-style", "icon");

    return _displayStyle;
}