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