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.GroupServiceSettingsLocator;
020    import com.liferay.portal.kernel.settings.LocalizedValuesMap;
021    import com.liferay.portal.kernel.settings.ParameterMapSettings;
022    import com.liferay.portal.kernel.settings.Settings;
023    import com.liferay.portal.kernel.settings.SettingsFactoryUtil;
024    import com.liferay.portal.kernel.settings.TypedSettings;
025    import com.liferay.portal.kernel.util.LocalizationUtil;
026    import com.liferay.portal.kernel.util.PropsKeys;
027    import com.liferay.portlet.blogs.constants.BlogsConstants;
028    
029    import java.util.Map;
030    
031    /**
032     * @author Iv??n Zaera
033     */
034    @Settings.Config(settingsIds = BlogsConstants.SERVICE_NAME)
035    public class BlogsGroupServiceSettings {
036    
037            public static BlogsGroupServiceSettings getInstance(long groupId)
038                    throws PortalException {
039    
040                    Settings settings = SettingsFactoryUtil.getSettings(
041                            new GroupServiceSettingsLocator(
042                                    groupId, BlogsConstants.SERVICE_NAME));
043    
044                    return new BlogsGroupServiceSettings(settings);
045            }
046    
047            public static BlogsGroupServiceSettings getInstance(
048                            long groupId, Map<String, String[]> parameterMap)
049                    throws PortalException {
050    
051                    Settings settings = SettingsFactoryUtil.getSettings(
052                            new GroupServiceSettingsLocator(
053                                    groupId, BlogsConstants.SERVICE_NAME));
054    
055                    return new BlogsGroupServiceSettings(
056                            new ParameterMapSettings(parameterMap, settings));
057            }
058    
059            public static void registerSettingsMetadata() {
060                    SettingsFactoryUtil.registerSettingsMetadata(
061                            BlogsGroupServiceSettings.class, null, _getFallbackKeys());
062            }
063    
064            public BlogsGroupServiceSettings(Settings settings) {
065                    _typedSettings = new TypedSettings(settings);
066            }
067    
068            public LocalizedValuesMap getEmailEntryAddedBody() {
069                    return _typedSettings.getLocalizedValuesMap("emailEntryAddedBody");
070            }
071    
072            @Settings.Property(ignore = true)
073            public String getEmailEntryAddedBodyXml() {
074                    return LocalizationUtil.getXml(
075                            getEmailEntryAddedBody(), "emailEntryAddedBody");
076            }
077    
078            public LocalizedValuesMap getEmailEntryAddedSubject() {
079                    return _typedSettings.getLocalizedValuesMap("emailEntryAddedSubject");
080            }
081    
082            @Settings.Property(ignore = true)
083            public String getEmailEntryAddedSubjectXml() {
084                    return LocalizationUtil.getXml(
085                            getEmailEntryAddedSubject(), "emailEntryAddedSubject");
086            }
087    
088            public LocalizedValuesMap getEmailEntryUpdatedBody() {
089                    return _typedSettings.getLocalizedValuesMap("emailEntryUpdatedBody");
090            }
091    
092            @Settings.Property(ignore = true)
093            public String getEmailEntryUpdatedBodyXml() {
094                    return LocalizationUtil.getXml(
095                            getEmailEntryUpdatedBody(), "emailEntryUpdatedBody");
096            }
097    
098            public LocalizedValuesMap getEmailEntryUpdatedSubject() {
099                    return _typedSettings.getLocalizedValuesMap("emailEntryUpdatedSubject");
100            }
101    
102            @Settings.Property(ignore = true)
103            public String getEmailEntryUpdatedSubjectXml() {
104                    return LocalizationUtil.getXml(
105                            getEmailEntryUpdatedSubject(), "emailEntryUpdatedSubject");
106            }
107    
108            public String getEmailFromAddress() {
109                    return _typedSettings.getValue("emailFromAddress");
110            }
111    
112            public String getEmailFromName() {
113                    return _typedSettings.getValue("emailFromName");
114            }
115    
116            public int getSmallImageWidth() {
117                    return _typedSettings.getIntegerValue("smallImageWidth");
118            }
119    
120            public boolean isEmailEntryAddedEnabled() {
121                    return _typedSettings.getBooleanValue("emailEntryAddedEnabled");
122            }
123    
124            public boolean isEmailEntryUpdatedEnabled() {
125                    return _typedSettings.getBooleanValue("emailEntryUpdatedEnabled");
126            }
127    
128            private static FallbackKeys _getFallbackKeys() {
129                    FallbackKeys fallbackKeys = new FallbackKeys();
130    
131                    fallbackKeys.add(
132                            "emailEntryAddedBody", PropsKeys.BLOGS_EMAIL_ENTRY_ADDED_BODY);
133                    fallbackKeys.add(
134                            "emailEntryAddedEnabled",
135                            PropsKeys.BLOGS_EMAIL_ENTRY_ADDED_ENABLED);
136                    fallbackKeys.add(
137                            "emailEntryAddedSubject",
138                            PropsKeys.BLOGS_EMAIL_ENTRY_ADDED_SUBJECT);
139                    fallbackKeys.add(
140                            "emailEntryUpdatedBody", PropsKeys.BLOGS_EMAIL_ENTRY_UPDATED_BODY);
141                    fallbackKeys.add(
142                            "emailEntryUpdatedEnabled",
143                            PropsKeys.BLOGS_EMAIL_ENTRY_UPDATED_ENABLED);
144                    fallbackKeys.add(
145                            "emailEntryUpdatedSubject",
146                            PropsKeys.BLOGS_EMAIL_ENTRY_UPDATED_SUBJECT);
147                    fallbackKeys.add(
148                            "emailFromAddress", PropsKeys.BLOGS_EMAIL_FROM_ADDRESS,
149                            PropsKeys.ADMIN_EMAIL_FROM_ADDRESS);
150                    fallbackKeys.add(
151                            "emailFromName", PropsKeys.BLOGS_EMAIL_FROM_NAME,
152                            PropsKeys.ADMIN_EMAIL_FROM_NAME);
153    
154                    return fallbackKeys;
155            }
156    
157            static {
158                    SettingsFactoryUtil.registerSettingsMetadata(
159                            BlogsGroupServiceSettings.class, null, _getFallbackKeys());
160            }
161    
162            private final TypedSettings _typedSettings;
163    
164    }