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.documentlibrary;
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.documentlibrary.constants.DLConstants;
028    
029    import java.util.Map;
030    
031    /**
032     * @author Adolfo P??rez
033     */
034    @Settings.Config(settingsIds = DLConstants.SERVICE_NAME)
035    public class DLGroupServiceSettings {
036    
037            public static DLGroupServiceSettings getInstance(long groupId)
038                    throws PortalException {
039    
040                    Settings settings = SettingsFactoryUtil.getSettings(
041                            new GroupServiceSettingsLocator(groupId, DLConstants.SERVICE_NAME));
042    
043                    return new DLGroupServiceSettings(settings);
044            }
045    
046            public static DLGroupServiceSettings getInstance(
047                            long groupId, Map<String, String[]> parameterMap)
048                    throws PortalException {
049    
050                    Settings settings = SettingsFactoryUtil.getSettings(
051                            new GroupServiceSettingsLocator(groupId, DLConstants.SERVICE_NAME));
052    
053                    Settings parameterMapSettings = new ParameterMapSettings(
054                            parameterMap, settings);
055    
056                    return new DLGroupServiceSettings(parameterMapSettings);
057            }
058    
059            public DLGroupServiceSettings(Settings settings) {
060                    _typedSettings = new TypedSettings(settings);
061            }
062    
063            public LocalizedValuesMap getEmailFileEntryAddedBody() {
064                    return _typedSettings.getLocalizedValuesMap("emailFileEntryAddedBody");
065            }
066    
067            @Settings.Property(ignore = true)
068            public String getEmailFileEntryAddedBodyXml() {
069                    return LocalizationUtil.getXml(
070                            getEmailFileEntryAddedBody(), "emailFileEntryAdded");
071            }
072    
073            public LocalizedValuesMap getEmailFileEntryAddedSubject() {
074                    return _typedSettings.getLocalizedValuesMap(
075                            "emailFileEntryAddedSubject");
076            }
077    
078            @Settings.Property(ignore = true)
079            public String getEmailFileEntryAddedSubjectXml() {
080                    return LocalizationUtil.getXml(
081                            getEmailFileEntryAddedSubject(), "emailFileEntryAddedSubject");
082            }
083    
084            public LocalizedValuesMap getEmailFileEntryUpdatedBody() {
085                    return _typedSettings.getLocalizedValuesMap(
086                            "emailFileEntryUpdatedBody");
087            }
088    
089            @Settings.Property(ignore = true)
090            public String getEmailFileEntryUpdatedBodyXml() {
091                    return LocalizationUtil.getXml(
092                            getEmailFileEntryUpdatedBody(), "emailFileEntryUpdatedBody");
093            }
094    
095            public LocalizedValuesMap getEmailFileEntryUpdatedSubject() {
096                    return _typedSettings.getLocalizedValuesMap(
097                            "emailFileEntryUpdatedSubject");
098            }
099    
100            @Settings.Property(ignore = true)
101            public String getEmailFileEntryUpdatedSubjectXml() {
102                    return LocalizationUtil.getXml(
103                            getEmailFileEntryUpdatedSubject(), "emailFileEntryUpdatedSubject");
104            }
105    
106            public String getEmailFromAddress() {
107                    return _typedSettings.getValue("emailFromAddress");
108            }
109    
110            public String getEmailFromName() {
111                    return _typedSettings.getValue("emailFromName");
112            }
113    
114            public boolean isEmailFileEntryAddedEnabled() {
115                    return _typedSettings.getBooleanValue("emailFileEntryAddedEnabled");
116            }
117    
118            public boolean isEmailFileEntryUpdatedEnabled() {
119                    return _typedSettings.getBooleanValue("emailFileEntryUpdatedEnabled");
120            }
121    
122            public boolean isShowHiddenMountFolders() {
123                    return _typedSettings.getBooleanValue("showHiddenMountFolders");
124            }
125    
126            private static FallbackKeys _getFallbackKeys() {
127                    FallbackKeys fallbackKeys = new FallbackKeys();
128    
129                    fallbackKeys.add(
130                            "emailFileEntryAddedBody",
131                            PropsKeys.DL_EMAIL_FILE_ENTRY_ADDED_BODY);
132                    fallbackKeys.add(
133                            "emailFileEntryAddedEnabled",
134                            PropsKeys.DL_EMAIL_FILE_ENTRY_ADDED_ENABLED);
135                    fallbackKeys.add(
136                            "emailFileEntryAddedSubject",
137                            PropsKeys.DL_EMAIL_FILE_ENTRY_ADDED_SUBJECT);
138                    fallbackKeys.add(
139                            "emailFileEntryUpdatedBody",
140                            PropsKeys.DL_EMAIL_FILE_ENTRY_UPDATED_BODY);
141                    fallbackKeys.add(
142                            "emailFileEntryUpdatedEnabled",
143                            PropsKeys.DL_EMAIL_FILE_ENTRY_UPDATED_ENABLED);
144                    fallbackKeys.add(
145                            "emailFileEntryUpdatedSubject",
146                            PropsKeys.DL_EMAIL_FILE_ENTRY_UPDATED_SUBJECT);
147                    fallbackKeys.add(
148                            "emailFromAddress", PropsKeys.DL_EMAIL_FROM_ADDRESS,
149                            PropsKeys.ADMIN_EMAIL_FROM_ADDRESS);
150                    fallbackKeys.add(
151                            "emailFromName", PropsKeys.DL_EMAIL_FROM_NAME,
152                            PropsKeys.ADMIN_EMAIL_FROM_NAME);
153                    fallbackKeys.add(
154                            "enableCommentRatings", PropsKeys.DL_COMMENT_RATINGS_ENABLED);
155                    fallbackKeys.add("enableRatings", PropsKeys.DL_RATINGS_ENABLED);
156                    fallbackKeys.add(
157                            "enableRelatedAssets", PropsKeys.DL_RELATED_ASSETS_ENABLED);
158                    fallbackKeys.add(
159                            "entriesPerPage", PropsKeys.SEARCH_CONTAINER_PAGE_DEFAULT_DELTA);
160                    fallbackKeys.add("entryColumns", PropsKeys.DL_ENTRY_COLUMNS);
161                    fallbackKeys.add("fileEntryColumns", PropsKeys.DL_FILE_ENTRY_COLUMNS);
162                    fallbackKeys.add("folderColumns", PropsKeys.DL_FOLDER_COLUMNS);
163                    fallbackKeys.add(
164                            "foldersPerPage", PropsKeys.SEARCH_CONTAINER_PAGE_DEFAULT_DELTA);
165                    fallbackKeys.add(
166                            "fileEntriesPerPage",
167                            PropsKeys.SEARCH_CONTAINER_PAGE_DEFAULT_DELTA);
168                    fallbackKeys.add(
169                            "showFoldersSearch", PropsKeys.DL_FOLDERS_SEARCH_VISIBLE);
170                    fallbackKeys.add(
171                            "showHiddenMountFolders", PropsKeys.DL_SHOW_HIDDEN_MOUNT_FOLDERS);
172                    fallbackKeys.add("showSubfolders", PropsKeys.DL_SUBFOLDERS_VISIBLE);
173    
174                    return fallbackKeys;
175            }
176    
177            static {
178                    SettingsFactoryUtil.registerSettingsMetadata(
179                            DLGroupServiceSettings.class, null, _getFallbackKeys());
180            }
181    
182            private final TypedSettings _typedSettings;
183    
184    }