001    /**
002     * Copyright (c) 2000-2011 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.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 java.util.Map;
031    
032    import javax.portlet.PortletRequest;
033    import javax.portlet.PortletURL;
034    
035    /**
036     * @author Jorge Ferrer
037     * @author Juan Fernández
038     * @author Raymond Augé
039     * @author Sergio González
040     */
041    public abstract class BaseAssetRendererFactory implements AssetRendererFactory {
042    
043            public AssetEntry getAssetEntry(long assetEntryId)
044                    throws PortalException, SystemException {
045    
046                    return AssetEntryLocalServiceUtil.getEntry(assetEntryId);
047            }
048    
049            public AssetEntry getAssetEntry(String className, long classPK)
050                    throws PortalException, SystemException {
051    
052                    return AssetEntryLocalServiceUtil.getEntry(className, classPK);
053            }
054    
055            public AssetRenderer getAssetRenderer(long classPK)
056                    throws PortalException, SystemException {
057    
058                    return getAssetRenderer(classPK, TYPE_LATEST_APPROVED);
059            }
060    
061            @SuppressWarnings("unused")
062            public AssetRenderer getAssetRenderer(long groupId, String urlTitle)
063                    throws PortalException, SystemException {
064    
065                    return null;
066            }
067    
068            public long getClassNameId() {
069                    return _classNameId;
070            }
071    
072            public Map<Long, String> getClassTypes(long[] groupId) throws Exception {
073                    return  null;
074            }
075    
076            public String getIconPath(PortletRequest portletRequest) {
077                    ThemeDisplay themeDisplay = (ThemeDisplay)portletRequest.getAttribute(
078                            WebKeys.THEME_DISPLAY);
079    
080                    return getIconPath(themeDisplay);
081            }
082    
083            public String getPortletId() {
084                    return _portletId;
085            }
086    
087            @SuppressWarnings("unused")
088            public PortletURL getURLAdd(
089                            LiferayPortletRequest liferayPortletRequest,
090                            LiferayPortletResponse liferayPortletResponse)
091                    throws PortalException, SystemException {
092    
093                    return null;
094            }
095    
096            public boolean hasPermission(
097                            PermissionChecker permissionChecker, long classPK, String actionId)
098                    throws Exception {
099    
100                    return _PERMISSION;
101            }
102    
103            public boolean isLinkable() {
104                    return _LINKABLE;
105            }
106    
107            public boolean isSelectable() {
108                    return _SELECTABLE;
109            }
110    
111            public void setClassNameId(long classNameId) {
112                    _classNameId = classNameId;
113            }
114    
115            public void setPortletId(String portletId) {
116                    _portletId = portletId;
117            }
118    
119            protected long getControlPanelPlid(ThemeDisplay themeDisplay)
120                    throws PortalException, SystemException {
121    
122                    Group controlPanelGroup = GroupLocalServiceUtil.getGroup(
123                            themeDisplay.getCompanyId(), GroupConstants.CONTROL_PANEL);
124    
125                    return LayoutLocalServiceUtil.getDefaultPlid(
126                            controlPanelGroup.getGroupId(), true);
127            }
128    
129            protected String getIconPath(ThemeDisplay themeDisplay) {
130                    return themeDisplay.getPathThemeImages() + "/common/page.png";
131            }
132    
133            private static final boolean _LINKABLE = false;
134    
135            private static final boolean _PERMISSION = true;
136    
137            private static final boolean _SELECTABLE = true;
138    
139            private long _classNameId;
140            private String _portletId;
141    
142    }