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