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.exception.PortalException;
018    import com.liferay.portal.kernel.log.Log;
019    import com.liferay.portal.kernel.log.LogFactoryUtil;
020    import com.liferay.portal.model.Layout;
021    import com.liferay.portal.model.LayoutTypeAccessPolicy;
022    import com.liferay.portal.model.LayoutTypeController;
023    import com.liferay.portal.security.permission.PermissionThreadLocal;
024    
025    import java.util.Map;
026    
027    /**
028     * @author L??szl?? Csontos
029     */
030    public class LayoutTypeURLImpl extends LayoutTypePortletImpl {
031    
032            public LayoutTypeURLImpl(
033                    Layout layout, LayoutTypeController layoutTypeController,
034                    LayoutTypeAccessPolicy layoutTypeAccessPolicy) {
035    
036                    super(layout, layoutTypeController, layoutTypeAccessPolicy);
037            }
038    
039            @Override
040            public String getURL(Map<String, String> variables) {
041                    if (hasViewPermission()) {
042                            return super.getURL(variables);
043                    }
044    
045                    return replaceVariables(getDefaultURL(), variables);
046            }
047    
048            protected boolean hasViewPermission() {
049                    try {
050                            LayoutTypeAccessPolicy layoutTypeAccessPolicy =
051                                    getLayoutTypeAccessPolicy();
052    
053                            return layoutTypeAccessPolicy.isViewLayoutAllowed(
054                                    PermissionThreadLocal.getPermissionChecker(), getLayout());
055                    }
056                    catch (PortalException pe) {
057                            _log.error(pe);
058    
059                            return false;
060                    }
061            }
062    
063            private static final Log _log = LogFactoryUtil.getLog(
064                    LayoutTypeURLImpl.class);
065    
066    }