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.portal.model.impl;
016    
017    import com.liferay.portal.kernel.util.StringPool;
018    import com.liferay.portal.kernel.util.StringUtil;
019    import com.liferay.portal.kernel.util.UnicodeProperties;
020    import com.liferay.portal.kernel.util.Validator;
021    import com.liferay.portal.model.Layout;
022    import com.liferay.portal.model.LayoutType;
023    import com.liferay.portal.model.LayoutTypeAccessPolicy;
024    import com.liferay.portal.model.LayoutTypeController;
025    
026    import java.util.Map;
027    
028    /**
029     * @author Brian Wing Shun Chan
030     */
031    public class LayoutTypeImpl implements LayoutType {
032    
033            public LayoutTypeImpl(
034                    Layout layout, LayoutTypeController layoutTypeController,
035                    LayoutTypeAccessPolicy layoutTypeAccessPolicy) {
036    
037                    _layout = layout;
038                    _layoutTypeController = layoutTypeController;
039                    _layoutTypeAccessPolicy = layoutTypeAccessPolicy;
040            }
041    
042            @Override
043            public String[] getConfigurationActionDelete() {
044                    return _layoutTypeController.getConfigurationActionDelete();
045            }
046    
047            @Override
048            public String[] getConfigurationActionUpdate() {
049                    return _layoutTypeController.getConfigurationActionUpdate();
050            }
051    
052            @Override
053            public Layout getLayout() {
054                    return _layout;
055            }
056    
057            @Override
058            public LayoutTypeAccessPolicy getLayoutTypeAccessPolicy() {
059                    return _layoutTypeAccessPolicy;
060            }
061    
062            @Override
063            public LayoutTypeController getLayoutTypeController() {
064                    return _layoutTypeController;
065            }
066    
067            @Override
068            public UnicodeProperties getTypeSettingsProperties() {
069                    return _layout.getTypeSettingsProperties();
070            }
071    
072            @Override
073            public String getTypeSettingsProperty(String key) {
074                    return getTypeSettingsProperty(key, null);
075            }
076    
077            @Override
078            public String getTypeSettingsProperty(String key, String defaultValue) {
079                    UnicodeProperties typeSettingsProperties = getTypeSettingsProperties();
080    
081                    return typeSettingsProperties.getProperty(key, defaultValue);
082            }
083    
084            @Override
085            public String getURL(Map<String, String> variables) {
086                    String url = _layoutTypeController.getURL();
087    
088                    if (Validator.isNull(url)) {
089                            url = getDefaultURL();
090                    }
091    
092                    return replaceVariables(url, variables);
093            }
094    
095            @Override
096            public boolean isBrowsable() {
097                    return _layoutTypeController.isBrowsable();
098            }
099    
100            @Override
101            public boolean isFirstPageable() {
102                    return _layoutTypeController.isFirstPageable();
103            }
104    
105            @Override
106            public boolean isParentable() {
107                    return _layoutTypeController.isParentable();
108            }
109    
110            @Override
111            public boolean isSitemapable() {
112                    return _layoutTypeController.isSitemapable();
113            }
114    
115            @Override
116            public boolean isURLFriendliable() {
117                    return _layoutTypeController.isURLFriendliable();
118            }
119    
120            /**
121             * @deprecated As of 7.0.0, with no direct replacement
122             */
123            @Deprecated
124            @Override
125            public void setLayout(Layout layout) {
126            }
127    
128            @Override
129            public void setTypeSettingsProperty(String key, String value) {
130                    UnicodeProperties typeSettingsProperties = getTypeSettingsProperties();
131    
132                    typeSettingsProperties.setProperty(key, value);
133            }
134    
135            protected String getDefaultURL() {
136                    return _URL;
137            }
138    
139            protected String replaceVariables(
140                    String url, Map<String, String> variables) {
141    
142                    return StringUtil.replace(
143                            url, StringPool.DOLLAR_AND_OPEN_CURLY_BRACE,
144                            StringPool.CLOSE_CURLY_BRACE, variables);
145            }
146    
147            private static final String _URL =
148                    "${liferay:mainPath}/portal/layout?p_l_id=${liferay:plid}&" +
149                            "p_v_l_s_g_id=${liferay:pvlsgid}";
150    
151            private final Layout _layout;
152            private final LayoutTypeAccessPolicy _layoutTypeAccessPolicy;
153            private final LayoutTypeController _layoutTypeController;
154    
155    }