001    /**
002     * Copyright (c) 2000-2013 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.portal.util;
016    
017    import com.liferay.portal.kernel.configuration.Filter;
018    import com.liferay.portal.kernel.util.GetterUtil;
019    import com.liferay.portal.kernel.util.PropsKeys;
020    import com.liferay.portal.kernel.util.StringPool;
021    import com.liferay.portal.kernel.util.StringUtil;
022    import com.liferay.portal.model.Layout;
023    import com.liferay.portal.model.LayoutConstants;
024    
025    import java.util.HashMap;
026    import java.util.Map;
027    
028    /**
029     * @author Shuyang Zhou
030     * @author Brian Wing Shun Chan
031     */
032    public class LayoutSettings {
033    
034            public static void addLayoutSetting(String type) {
035                    _layoutSettingsMap.put(type, new LayoutSettings(type));
036            }
037    
038            public static LayoutSettings getInstance(Layout layout) {
039                    return getInstance(layout.getType());
040            }
041    
042            public static LayoutSettings getInstance(String type) {
043                    return _layoutSettingsMap.get(type);
044            }
045    
046            public static Map<String, LayoutSettings> getLayoutSettingsMap() {
047                    return _layoutSettingsMap;
048            }
049    
050            public String[] getConfigurationActionDelete() {
051                    return _configurationActionDelete;
052            }
053    
054            public String[] getConfigurationActionUpdate() {
055                    return _configurationActionUpdate;
056            }
057    
058            public String getEditPage() {
059                    return _editPage;
060            }
061    
062            public String getType() {
063                    return _type;
064            }
065    
066            public String getURL() {
067                    return _url;
068            }
069    
070            public String getURL(Map<String, String> variables) {
071                    return StringUtil.replace(
072                            _url, StringPool.DOLLAR_AND_OPEN_CURLY_BRACE,
073                            StringPool.CLOSE_CURLY_BRACE, variables);
074            }
075    
076            public String getViewPage() {
077                    return _viewPage;
078            }
079    
080            public boolean isFirstPageable() {
081                    return _firstPageable;
082            }
083    
084            public boolean isParentable() {
085                    return _parentable;
086            }
087    
088            public boolean isSitemapable() {
089                    return _sitemapable;
090            }
091    
092            public boolean isURLFriendliable() {
093                    return _urlFriendliable;
094            }
095    
096            private LayoutSettings(String type) {
097                    _type = type;
098    
099                    Filter filter = new Filter(type);
100    
101                    _configurationActionDelete = StringUtil.split(
102                            GetterUtil.getString(
103                                    PropsUtil.get(
104                                            PropsKeys.LAYOUT_CONFIGURATION_ACTION_DELETE, filter)));
105                    _configurationActionUpdate = StringUtil.split(
106                            GetterUtil.getString(
107                                    PropsUtil.get(
108                                            PropsKeys.LAYOUT_CONFIGURATION_ACTION_UPDATE, filter)));
109                    _editPage = GetterUtil.getString(
110                            PropsUtil.get(PropsKeys.LAYOUT_EDIT_PAGE, filter));
111                    _firstPageable = GetterUtil.getBoolean(
112                            PropsUtil.get(PropsKeys.LAYOUT_FIRST_PAGEABLE, filter));
113                    _parentable = GetterUtil.getBoolean(
114                            PropsUtil.get(PropsKeys.LAYOUT_PARENTABLE, filter), true);
115                    _sitemapable = GetterUtil.getBoolean(
116                            PropsUtil.get(PropsKeys.LAYOUT_SITEMAPABLE, filter), true);
117                    _url = GetterUtil.getString(
118                            PropsUtil.get(PropsKeys.LAYOUT_URL, filter));
119                    _urlFriendliable = GetterUtil.getBoolean(
120                            PropsUtil.get(PropsKeys.LAYOUT_URL_FRIENDLIABLE, filter), true);
121                    _viewPage = GetterUtil.getString(
122                            PropsUtil.get(PropsKeys.LAYOUT_VIEW_PAGE, filter));
123            }
124    
125            private static Map<String, LayoutSettings> _layoutSettingsMap =
126                    new HashMap<String, LayoutSettings>();
127    
128            static {
129                    _layoutSettingsMap.put(
130                            LayoutConstants.TYPE_CONTROL_PANEL,
131                            new LayoutSettings(LayoutConstants.TYPE_CONTROL_PANEL));
132    
133                    for (String type : PropsValues.LAYOUT_TYPES) {
134                            _layoutSettingsMap.put(type, new LayoutSettings(type));
135                    }
136            }
137    
138            private String[] _configurationActionDelete;
139            private String[] _configurationActionUpdate;
140            private String _editPage;
141            private boolean _firstPageable;
142            private boolean _parentable;
143            private boolean _sitemapable;
144            private String _type;
145            private String _url;
146            private boolean _urlFriendliable;
147            private String _viewPage;
148    
149    }