001    /**
002     * Copyright (c) 2000-2011 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
013     */
014    
015    package com.liferay.portlet.asset.model;
016    
017    import com.liferay.portal.kernel.exception.PortalException;
018    import com.liferay.portal.kernel.exception.SystemException;
019    import com.liferay.portal.kernel.portlet.LiferayPortletRequest;
020    import com.liferay.portal.kernel.portlet.LiferayPortletResponse;
021    import com.liferay.portal.kernel.util.WebKeys;
022    import com.liferay.portal.model.Group;
023    import com.liferay.portal.model.GroupConstants;
024    import com.liferay.portal.security.permission.PermissionChecker;
025    import com.liferay.portal.service.GroupLocalServiceUtil;
026    import com.liferay.portal.service.LayoutLocalServiceUtil;
027    import com.liferay.portal.theme.ThemeDisplay;
028    import com.liferay.portlet.asset.service.AssetEntryLocalServiceUtil;
029    
030    import javax.portlet.PortletRequest;
031    import javax.portlet.PortletURL;
032    
033    /**
034     * @author Jorge Ferrer
035     * @author Juan Fernández
036     * @author Raymond Augé
037     * @author Sergio González
038     */
039    public abstract class BaseAssetRendererFactory implements AssetRendererFactory {
040    
041            public AssetEntry getAssetEntry(long assetEntryId)
042                    throws PortalException, SystemException {
043    
044                    return AssetEntryLocalServiceUtil.getEntry(assetEntryId);
045            }
046    
047            public AssetEntry getAssetEntry(String className, long classPK)
048                    throws PortalException, SystemException {
049    
050                    return AssetEntryLocalServiceUtil.getEntry(className, classPK);
051            }
052    
053            public AssetRenderer getAssetRenderer(long classPK)
054                    throws PortalException, SystemException {
055    
056                    return getAssetRenderer(classPK, TYPE_LATEST_APPROVED);
057            }
058    
059            @SuppressWarnings("unused")
060            public AssetRenderer getAssetRenderer(long groupId, String urlTitle)
061                    throws PortalException, SystemException {
062    
063                    return null;
064            }
065    
066            public long getClassNameId() {
067                    return _classNameId;
068            }
069    
070            public String getIconPath(PortletRequest portletRequest) {
071                    ThemeDisplay themeDisplay = (ThemeDisplay)portletRequest.getAttribute(
072                            WebKeys.THEME_DISPLAY);
073    
074                    return getIconPath(themeDisplay);
075            }
076    
077            public String getPortletId() {
078                    return _portletId;
079            }
080    
081            @SuppressWarnings("unused")
082            public PortletURL getURLAdd(
083                            LiferayPortletRequest liferayPortletRequest,
084                            LiferayPortletResponse liferayPortletResponse)
085                    throws PortalException, SystemException {
086    
087                    return null;
088            }
089    
090            public boolean hasPermission(
091                            PermissionChecker permissionChecker, long classPK, String actionId)
092                    throws Exception {
093    
094                    return true;
095            }
096    
097            public boolean isSelectable() {
098                    return true;
099            }
100    
101            public void setClassNameId(long classNameId) {
102                    _classNameId = classNameId;
103            }
104    
105            public void setPortletId(String portletId) {
106                    _portletId = portletId;
107            }
108    
109            protected long getControlPanelPlid(ThemeDisplay themeDisplay)
110                    throws PortalException, SystemException {
111    
112                    Group controlPanelGroup = GroupLocalServiceUtil.getGroup(
113                            themeDisplay.getCompanyId(), GroupConstants.CONTROL_PANEL);
114    
115                    return LayoutLocalServiceUtil.getDefaultPlid(
116                            controlPanelGroup.getGroupId(), true);
117            }
118    
119            protected String getIconPath(ThemeDisplay themeDisplay) {
120                    return themeDisplay.getPathThemeImages() + "/common/page.png";
121            }
122    
123            private long _classNameId;
124            private String _portletId;
125    
126    }