001    /**
002     * Copyright (c) 2000-present Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portlet.journal.context;
016    
017    import com.liferay.portal.kernel.portlet.LiferayPortletRequest;
018    import com.liferay.portal.kernel.util.PrefsParamUtil;
019    import com.liferay.portal.kernel.util.StringUtil;
020    import com.liferay.portal.util.PropsValues;
021    import com.liferay.portlet.journal.util.JournalUtil;
022    
023    import javax.portlet.PortletPreferences;
024    
025    /**
026     * @author Eudaldo Alonso
027     */
028    public class JournalDisplayContext {
029    
030            public JournalDisplayContext(
031                    LiferayPortletRequest liferayPortletRequest,
032                    PortletPreferences portletPreferences) {
033    
034                    _liferayPortletRequest = liferayPortletRequest;
035                    _portletPreferences = portletPreferences;
036            }
037    
038            public String getDisplayStyle() {
039                    if (_displayStyle == null) {
040                            _displayStyle = JournalUtil.getDisplayStyle(
041                                    _liferayPortletRequest, getDisplayViews());
042                    }
043    
044                    return _displayStyle;
045            }
046    
047            public String[] getDisplayViews() {
048                    if (_displayViews == null) {
049                            _displayViews = StringUtil.split(
050                                    PrefsParamUtil.getString(
051                                            _portletPreferences, _liferayPortletRequest, "displayViews",
052                                            StringUtil.merge(PropsValues.JOURNAL_DISPLAY_VIEWS)));
053                    }
054    
055                    return _displayViews;
056            }
057    
058            private String _displayStyle;
059            private String[] _displayViews;
060            private final LiferayPortletRequest _liferayPortletRequest;
061            private final PortletPreferences _portletPreferences;
062    
063    }