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.util.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 BlogsGroupServiceSettings(Settings settings) {
060                    _typedSettings = new TypedSettings(settings);
061            }
062    
063            public LocalizedValuesMap getEmailEntryAddedBody() {
064                    return _typedSettings.getLocalizedValuesMap("emailEntryAddedBody");
065            }
066    
067            @Settings.Property(ignore = true)
068            public String getEmailEntryAddedBodyXml() {
069                    return LocalizationUtil.getXml(
070                            getEmailEntryAddedBody(), "emailEntryAddedBody");
071            }
072    
073            public LocalizedValuesMap getEmailEntryAddedSubject() {
074                    return _typedSettings.getLocalizedValuesMap("emailEntryAddedSubject");
075            }
076    
077            @Settings.Property(ignore = true)
078            public String getEmailEntryAddedSubjectXml() {
079                    return LocalizationUtil.getXml(
080                            getEmailEntryAddedSubject(), "emailEntryAddedSubject");
081            }
082    
083            public LocalizedValuesMap getEmailEntryUpdatedBody() {
084                    return _typedSettings.getLocalizedValuesMap("emailEntryUpdatedBody");
085            }
086    
087            @Settings.Property(ignore = true)
088            public String getEmailEntryUpdatedBodyXml() {
089                    return LocalizationUtil.getXml(
090                            getEmailEntryUpdatedBody(), "emailEntryUpdatedBody");
091            }
092    
093            public LocalizedValuesMap getEmailEntryUpdatedSubject() {
094                    return _typedSettings.getLocalizedValuesMap("emailEntryUpdatedSubject");
095            }
096    
097            @Settings.Property(ignore = true)
098            public String getEmailEntryUpdatedSubjectXml() {
099                    return LocalizationUtil.getXml(
100                            getEmailEntryUpdatedSubject(), "emailEntryUpdatedSubject");
101            }
102    
103            public String getEmailFromAddress() {
104                    return _typedSettings.getValue("emailFromAddress");
105            }
106    
107            public String getEmailFromName() {
108                    return _typedSettings.getValue("emailFromName");
109            }
110    
111            public boolean isEmailEntryAddedEnabled() {
112                    return _typedSettings.getBooleanValue("emailEntryAddedEnabled");
113            }
114    
115            public boolean isEmailEntryUpdatedEnabled() {
116                    return _typedSettings.getBooleanValue("emailEntryUpdatedEnabled");
117            }
118    
119            private static FallbackKeys _getFallbackKeys() {
120                    FallbackKeys fallbackKeys = new FallbackKeys();
121    
122                    fallbackKeys.add(
123                            "emailEntryAddedBody", PropsKeys.BLOGS_EMAIL_ENTRY_ADDED_BODY);
124                    fallbackKeys.add(
125                            "emailEntryAddedEnabled",
126                            PropsKeys.BLOGS_EMAIL_ENTRY_ADDED_ENABLED);
127                    fallbackKeys.add(
128                            "emailEntryAddedSubject",
129                            PropsKeys.BLOGS_EMAIL_ENTRY_ADDED_SUBJECT);
130                    fallbackKeys.add(
131                            "emailEntryUpdatedBody", PropsKeys.BLOGS_EMAIL_ENTRY_UPDATED_BODY);
132                    fallbackKeys.add(
133                            "emailEntryUpdatedEnabled",
134                            PropsKeys.BLOGS_EMAIL_ENTRY_UPDATED_ENABLED);
135                    fallbackKeys.add(
136                            "emailEntryUpdatedSubject",
137                            PropsKeys.BLOGS_EMAIL_ENTRY_UPDATED_SUBJECT);
138                    fallbackKeys.add(
139                            "emailFromAddress", PropsKeys.BLOGS_EMAIL_FROM_ADDRESS,
140                            PropsKeys.ADMIN_EMAIL_FROM_ADDRESS);
141                    fallbackKeys.add(
142                            "emailFromName", PropsKeys.BLOGS_EMAIL_FROM_NAME,
143                            PropsKeys.ADMIN_EMAIL_FROM_NAME);
144    
145                    return fallbackKeys;
146            }
147    
148            static {
149                    SettingsFactoryUtil.registerSettingsMetadata(
150                            BlogsGroupServiceSettings.class, null, _getFallbackKeys());
151            }
152    
153            private final TypedSettings _typedSettings;
154    
155    }