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