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