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 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 isCategorizable() {
104                    return true;
105            }
106    
107            public boolean isLinkable() {
108                    return _LINKABLE;
109            }
110    
111            public boolean isSelectable() {
112                    return _SELECTABLE;
113            }
114    
115            public void setClassNameId(long classNameId) {
116                    _classNameId = classNameId;
117            }
118    
119            public void setPortletId(String portletId) {
120                    _portletId = portletId;
121            }
122    
123            protected long getControlPanelPlid(ThemeDisplay themeDisplay)
124                    throws PortalException, SystemException {
125    
126                    Group controlPanelGroup = GroupLocalServiceUtil.getGroup(
127                            themeDisplay.getCompanyId(), GroupConstants.CONTROL_PANEL);
128    
129                    return LayoutLocalServiceUtil.getDefaultPlid(
130                            controlPanelGroup.getGroupId(), true);
131            }
132    
133            protected String getIconPath(ThemeDisplay themeDisplay) {
134                    return themeDisplay.getPathThemeImages() + "/common/page.png";
135            }
136    
137            private static final boolean _LINKABLE = false;
138    
139            private static final boolean _PERMISSION = true;
140    
141            private static final boolean _SELECTABLE = true;
142    
143            private long _classNameId;
144            private String _portletId;
145    
146    }