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 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 int getSmallImageWidth() {
112                    return _typedSettings.getIntegerValue("smallImageWidth");
113            }
114    
115            public boolean isEmailEntryAddedEnabled() {
116                    return _typedSettings.getBooleanValue("emailEntryAddedEnabled");
117            }
118    
119            public boolean isEmailEntryUpdatedEnabled() {
120                    return _typedSettings.getBooleanValue("emailEntryUpdatedEnabled");
121            }
122    
123            private static FallbackKeys _getFallbackKeys() {
124                    FallbackKeys fallbackKeys = new FallbackKeys();
125    
126                    fallbackKeys.add(
127                            "emailEntryAddedBody", PropsKeys.BLOGS_EMAIL_ENTRY_ADDED_BODY);
128                    fallbackKeys.add(
129                            "emailEntryAddedEnabled",
130                            PropsKeys.BLOGS_EMAIL_ENTRY_ADDED_ENABLED);
131                    fallbackKeys.add(
132                            "emailEntryAddedSubject",
133                            PropsKeys.BLOGS_EMAIL_ENTRY_ADDED_SUBJECT);
134                    fallbackKeys.add(
135                            "emailEntryUpdatedBody", PropsKeys.BLOGS_EMAIL_ENTRY_UPDATED_BODY);
136                    fallbackKeys.add(
137                            "emailEntryUpdatedEnabled",
138                            PropsKeys.BLOGS_EMAIL_ENTRY_UPDATED_ENABLED);
139                    fallbackKeys.add(
140                            "emailEntryUpdatedSubject",
141                            PropsKeys.BLOGS_EMAIL_ENTRY_UPDATED_SUBJECT);
142                    fallbackKeys.add(
143                            "emailFromAddress", PropsKeys.BLOGS_EMAIL_FROM_ADDRESS,
144                            PropsKeys.ADMIN_EMAIL_FROM_ADDRESS);
145                    fallbackKeys.add(
146                            "emailFromName", PropsKeys.BLOGS_EMAIL_FROM_NAME,
147                            PropsKeys.ADMIN_EMAIL_FROM_NAME);
148    
149                    return fallbackKeys;
150            }
151    
152            static {
153                    SettingsFactoryUtil.registerSettingsMetadata(
154                            BlogsGroupServiceSettings.class, null, _getFallbackKeys());
155            }
156    
157            private final TypedSettings _typedSettings;
158    
159    }