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.ParameterMapSettings;
020    import com.liferay.portal.kernel.settings.PortletInstanceSettingsLocator;
021    import com.liferay.portal.kernel.settings.Settings;
022    import com.liferay.portal.kernel.settings.SettingsFactoryUtil;
023    import com.liferay.portal.kernel.settings.TypedSettings;
024    import com.liferay.portal.kernel.util.ArrayUtil;
025    import com.liferay.portal.kernel.util.PropsKeys;
026    import com.liferay.portal.model.Layout;
027    import com.liferay.portal.util.PortletKeys;
028    import com.liferay.portlet.documentlibrary.model.DLFolderConstants;
029    import com.liferay.portlet.documentlibrary.util.DLUtil;
030    
031    import java.util.Map;
032    
033    /**
034     * @author Sergio Gonz??lez
035     */
036    @Settings.Config(
037            settingsIds = {
038                    PortletKeys.DOCUMENT_LIBRARY, PortletKeys.DOCUMENT_LIBRARY_ADMIN,
039                    PortletKeys.DOCUMENT_LIBRARY_DISPLAY, PortletKeys.MEDIA_GALLERY_DISPLAY
040            }
041    )
042    public class DLPortletInstanceSettings {
043    
044            public static DLPortletInstanceSettings getInstance(
045                            Layout layout, String portletId)
046                    throws PortalException {
047    
048                    Settings settings = SettingsFactoryUtil.getSettings(
049                            new PortletInstanceSettingsLocator(layout, portletId));
050    
051                    return new DLPortletInstanceSettings(settings);
052            }
053    
054            public static DLPortletInstanceSettings getInstance(
055                            Layout layout, String portletId, Map<String, String[]> parameterMap)
056                    throws PortalException {
057    
058                    Settings settings = SettingsFactoryUtil.getSettings(
059                            new PortletInstanceSettingsLocator(layout, portletId));
060    
061                    Settings parameterMapSettings = new ParameterMapSettings(
062                            parameterMap, settings);
063    
064                    return new DLPortletInstanceSettings(parameterMapSettings);
065            }
066    
067            public DLPortletInstanceSettings(Settings settings) {
068                    _typedSettings = new TypedSettings(settings);
069            }
070    
071            public long getDefaultFolderId() {
072                    return _typedSettings.getLongValue(
073                            "rootFolderId", DLFolderConstants.DEFAULT_PARENT_FOLDER_ID);
074            }
075    
076            public String[] getDisplayViews() {
077                    return _typedSettings.getValues("displayViews");
078            }
079    
080            public int getEntriesPerPage() {
081                    return _typedSettings.getIntegerValue("entriesPerPage");
082            }
083    
084            public String[] getEntryColumns() {
085                    return _typedSettings.getValues("entryColumns");
086            }
087    
088            public int getFileEntriesPerPage() {
089                    return _typedSettings.getIntegerValue("fileEntriesPerPage");
090            }
091    
092            public String[] getFileEntryColumns() {
093                    return _typedSettings.getValues("fileEntryColumns");
094            }
095    
096            public String[] getFolderColumns() {
097                    return _typedSettings.getValues("folderColumns");
098            }
099    
100            public int getFoldersPerPage() {
101                    return _typedSettings.getIntegerValue("foldersPerPage");
102            }
103    
104            public String[] getMimeTypes() {
105                    return _typedSettings.getValues("mimeTypes", _MIME_TYPES_DEFAULT);
106            }
107    
108            public long getRootFolderId() {
109                    return _typedSettings.getLongValue(
110                            "rootFolderId", DLFolderConstants.DEFAULT_PARENT_FOLDER_ID);
111            }
112    
113            public boolean isEnableCommentRatings() {
114                    return _typedSettings.getBooleanValue("enableCommentRatings");
115            }
116    
117            public boolean isEnableFileEntryDrafts() {
118                    return _typedSettings.getBooleanValue("enableFileEntryDrafts");
119            }
120    
121            public boolean isEnableRatings() {
122                    return _typedSettings.getBooleanValue("enableRatings");
123            }
124    
125            public boolean isEnableRelatedAssets() {
126                    return _typedSettings.getBooleanValue("enableRelatedAssets");
127            }
128    
129            public boolean isShowActions() {
130                    return _typedSettings.getBooleanValue("showActions");
131            }
132    
133            public boolean isShowFolderMenu() {
134                    return _typedSettings.getBooleanValue("showFolderMenu");
135            }
136    
137            public boolean isShowFoldersSearch() {
138                    return _typedSettings.getBooleanValue("showFoldersSearch");
139            }
140    
141            public boolean isShowSubfolders() {
142                    return _typedSettings.getBooleanValue("showSubfolders");
143            }
144    
145            public boolean isShowTabs() {
146                    return _typedSettings.getBooleanValue("showTabs");
147            }
148    
149            private static FallbackKeys _getFallbackKeys() {
150                    FallbackKeys fallbackKeys = new FallbackKeys();
151    
152                    fallbackKeys.add("displayViews", PropsKeys.DL_DISPLAY_VIEWS);
153                    fallbackKeys.add(
154                            "enableCommentRatings", PropsKeys.DL_COMMENT_RATINGS_ENABLED);
155                    fallbackKeys.add(
156                            "enableFileEntryDrafts", PropsKeys.DL_FILE_ENTRY_DRAFTS_ENABLED);
157                    fallbackKeys.add("enableRatings", PropsKeys.DL_RATINGS_ENABLED);
158                    fallbackKeys.add(
159                            "enableRelatedAssets", PropsKeys.DL_RELATED_ASSETS_ENABLED);
160                    fallbackKeys.add(
161                            "entriesPerPage", PropsKeys.SEARCH_CONTAINER_PAGE_DEFAULT_DELTA);
162                    fallbackKeys.add("entryColumns", PropsKeys.DL_ENTRY_COLUMNS);
163                    fallbackKeys.add("fileEntryColumns", PropsKeys.DL_FILE_ENTRY_COLUMNS);
164                    fallbackKeys.add("folderColumns", PropsKeys.DL_FOLDER_COLUMNS);
165                    fallbackKeys.add(
166                            "foldersPerPage", PropsKeys.SEARCH_CONTAINER_PAGE_DEFAULT_DELTA);
167                    fallbackKeys.add(
168                            "fileEntriesPerPage",
169                            PropsKeys.SEARCH_CONTAINER_PAGE_DEFAULT_DELTA);
170                    fallbackKeys.add("showActions", PropsKeys.DL_ACTIONS_VISIBLE);
171                    fallbackKeys.add("showFolderMenu", PropsKeys.DL_FOLDER_MENU_VISIBLE);
172                    fallbackKeys.add(
173                            "showFoldersSearch", PropsKeys.DL_FOLDERS_SEARCH_VISIBLE);
174                    fallbackKeys.add("showSubfolders", PropsKeys.DL_SUBFOLDERS_VISIBLE);
175                    fallbackKeys.add("showTabs", PropsKeys.DL_TABS_VISIBLE);
176    
177                    return fallbackKeys;
178            }
179    
180            private static final String[] _MIME_TYPES_DEFAULT = ArrayUtil.toStringArray(
181                    DLUtil.getAllMediaGalleryMimeTypes());
182    
183            static {
184                    SettingsFactoryUtil.registerSettingsMetadata(
185                            DLPortletInstanceSettings.class, null, _getFallbackKeys());
186            }
187    
188            private final TypedSettings _typedSettings;
189    
190    }