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.blogs;
016    
017    import com.liferay.portal.kernel.exception.PortalException;
018    import com.liferay.portal.kernel.settings.FallbackKeys;
019    import com.liferay.portal.kernel.settings.ParameterMapSettings;
020    import com.liferay.portal.kernel.settings.PortletInstanceSettingsLocator;
021    import com.liferay.portal.kernel.settings.Settings;
022    import com.liferay.portal.kernel.settings.SettingsFactoryUtil;
023    import com.liferay.portal.kernel.settings.TypedSettings;
024    import com.liferay.portal.kernel.util.PropsKeys;
025    import com.liferay.portal.model.Layout;
026    import com.liferay.portal.util.PortalUtil;
027    import com.liferay.portal.util.PortletKeys;
028    
029    import java.util.Map;
030    
031    /**
032     * @author Iv??n Zaera
033     */
034    @Settings.Config(settingsIds = {PortletKeys.BLOGS, PortletKeys.BLOGS_ADMIN})
035    public class BlogsPortletInstanceSettings {
036    
037            public static BlogsPortletInstanceSettings getInstance(
038                            Layout layout, String portletId)
039                    throws PortalException {
040    
041                    Settings settings = SettingsFactoryUtil.getSettings(
042                            new PortletInstanceSettingsLocator(layout, portletId));
043    
044                    return new BlogsPortletInstanceSettings(settings);
045            }
046    
047            public static BlogsPortletInstanceSettings getInstance(
048                            Layout layout, String portletId, Map<String, String[]> parameterMap)
049                    throws PortalException {
050    
051                    Settings settings = SettingsFactoryUtil.getSettings(
052                            new PortletInstanceSettingsLocator(layout, portletId));
053    
054                    return new BlogsPortletInstanceSettings(
055                            new ParameterMapSettings(parameterMap, settings));
056            }
057    
058            public BlogsPortletInstanceSettings(Settings settings) {
059                    _typedSettings = new TypedSettings(settings);
060            }
061    
062            public String getDisplayStyle() {
063                    return _typedSettings.getValue("displayStyle");
064            }
065    
066            public long getDisplayStyleGroupId(long defaultDisplayStyleGroupId) {
067                    return _typedSettings.getLongValue(
068                            "displayStyleGroupId", defaultDisplayStyleGroupId);
069            }
070    
071            public int getPageDelta() {
072                    return _typedSettings.getIntegerValue("pageDelta");
073            }
074    
075            @Settings.Property(name = "rssDelta")
076            public int getRssDelta() {
077                    return _typedSettings.getIntegerValue("rssDelta");
078            }
079    
080            @Settings.Property(name = "rssDisplayStyle")
081            public String getRssDisplayStyle() {
082                    return _typedSettings.getValue("rssDisplayStyle");
083            }
084    
085            @Settings.Property(name = "rssFeedType")
086            public String getRssFeedType() {
087                    return _typedSettings.getValue("rssFeedType");
088            }
089    
090            public String getSocialBookmarksDisplayPosition() {
091                    return _typedSettings.getValue("socialBookmarksDisplayPosition");
092            }
093    
094            public String getSocialBookmarksDisplayStyle() {
095                    return _typedSettings.getValue("socialBookmarksDisplayStyle");
096            }
097    
098            public String getSocialBookmarksTypes() {
099                    return _typedSettings.getValue("socialBookmarksTypes");
100            }
101    
102            public boolean isEnableCommentRatings() {
103                    return _typedSettings.getBooleanValue("enableCommentRatings");
104            }
105    
106            public boolean isEnableComments() {
107                    return _typedSettings.getBooleanValue("enableComments");
108            }
109    
110            public boolean isEnableFlags() {
111                    return _typedSettings.getBooleanValue("enableFlags");
112            }
113    
114            public boolean isEnableRatings() {
115                    return _typedSettings.getBooleanValue("enableRatings");
116            }
117    
118            public boolean isEnableRelatedAssets() {
119                    return _typedSettings.getBooleanValue("enableRelatedAssets");
120            }
121    
122            @Settings.Property(name = "enableRss")
123            public boolean isEnableRSS() {
124                    if (!PortalUtil.isRSSFeedsEnabled()) {
125                            return false;
126                    }
127    
128                    return _typedSettings.getBooleanValue("enableRss");
129            }
130    
131            public boolean isEnableSocialBookmarks() {
132                    return _typedSettings.getBooleanValue("enableSocialBookmarks");
133            }
134    
135            private static FallbackKeys _getFallbackKeys() {
136                    FallbackKeys fallbackKeys = new FallbackKeys();
137    
138                    fallbackKeys.add(
139                            "enableComments", PropsKeys.BLOGS_ENTRY_COMMENTS_ENABLED);
140                    fallbackKeys.add(
141                            "enableCommentRatings", PropsKeys.BLOGS_COMMENT_RATINGS_ENABLED);
142                    fallbackKeys.add("enableFlags", PropsKeys.BLOGS_FLAGS_ENABLED);
143                    fallbackKeys.add("enableRatings", PropsKeys.BLOGS_RATINGS_ENABLED);
144                    fallbackKeys.add(
145                            "enableRelatedAssets", PropsKeys.BLOGS_RELATED_ASSETS_ENABLED);
146                    fallbackKeys.add("enableRss", PropsKeys.BLOGS_RSS_ENABLED);
147                    fallbackKeys.add(
148                            "enableSocialBookmarks", PropsKeys.BLOGS_SOCIAL_BOOKMARKS_ENABLED);
149                    fallbackKeys.add("displayStyle", PropsKeys.BLOGS_DISPLAY_STYLE);
150                    fallbackKeys.add(
151                            "pageDelta", PropsKeys.SEARCH_CONTAINER_PAGE_DEFAULT_DELTA);
152                    fallbackKeys.add(
153                            "rssDelta", PropsKeys.SEARCH_CONTAINER_PAGE_DEFAULT_DELTA);
154                    fallbackKeys.add(
155                            "rssDisplayStyle", PropsKeys.RSS_FEED_DISPLAY_STYLE_DEFAULT);
156                    fallbackKeys.add("rssFeedType", PropsKeys.RSS_FEED_TYPE_DEFAULT);
157                    fallbackKeys.add(
158                            "socialBookmarksDisplayPosition",
159                            PropsKeys.BLOGS_SOCIAL_BOOKMARKS_DISPLAY_POSITION);
160                    fallbackKeys.add(
161                            "socialBookmarksDisplayStyle",
162                            PropsKeys.BLOGS_SOCIAL_BOOKMARKS_DISPLAY_STYLE);
163                    fallbackKeys.add(
164                            "socialBookmarksTypes", PropsKeys.SOCIAL_BOOKMARK_TYPES);
165    
166                    return fallbackKeys;
167            }
168    
169            static {
170                    SettingsFactoryUtil.registerSettingsMetadata(
171                            BlogsPortletInstanceSettings.class, null, _getFallbackKeys());
172            }
173    
174            private final TypedSettings _typedSettings;
175    
176    }