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.service;
016    
017    import com.liferay.portal.kernel.bean.BeanReference;
018    import com.liferay.portal.kernel.exception.PortalException;
019    import com.liferay.portal.kernel.util.StringPool;
020    import com.liferay.portal.kernel.util.WebKeys;
021    import com.liferay.portal.model.Layout;
022    import com.liferay.portal.model.LayoutConstants;
023    import com.liferay.portal.service.persistence.LayoutPersistence;
024    import com.liferay.portal.theme.ThemeDisplay;
025    import com.liferay.portal.util.PortalUtil;
026    
027    import javax.servlet.http.HttpServletRequest;
028    
029    /**
030     * @author Brian Wing Shun Chan
031     */
032    public abstract class BaseLocalServiceImpl implements BaseLocalService {
033    
034            protected ClassLoader getClassLoader() {
035                    Class<?> clazz = getClass();
036    
037                    return clazz.getClassLoader();
038            }
039    
040            protected String getLayoutURL(
041                    Layout layout, ServiceContext serviceContext) {
042    
043                    HttpServletRequest request = serviceContext.getRequest();
044    
045                    if (request == null) {
046                            return StringPool.BLANK;
047                    }
048    
049                    ThemeDisplay themeDisplay = (ThemeDisplay)request.getAttribute(
050                            WebKeys.THEME_DISPLAY);
051    
052                    try {
053                            return PortalUtil.getLayoutURL(layout, themeDisplay);
054                    }
055                    catch (Exception e) {
056                            return StringPool.BLANK;
057                    }
058            }
059    
060            protected String getLayoutURL(
061                            long groupId, String portletId, ServiceContext serviceContext)
062                    throws PortalException {
063    
064                    long plid = serviceContext.getPlid();
065    
066                    long controlPanelPlid = PortalUtil.getControlPanelPlid(
067                            serviceContext.getCompanyId());
068    
069                    if (plid == controlPanelPlid) {
070                            plid = PortalUtil.getPlidFromPortletId(groupId, portletId);
071                    }
072    
073                    String layoutURL = StringPool.BLANK;
074    
075                    if (plid != LayoutConstants.DEFAULT_PLID) {
076                            Layout layout = layoutPersistence.findByPrimaryKey(plid);
077    
078                            layoutURL = getLayoutURL(layout, serviceContext);
079                    }
080    
081                    return layoutURL;
082            }
083    
084            @BeanReference(type = LayoutPersistence.class)
085            protected LayoutPersistence layoutPersistence;
086    
087    }