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