001    /**
002     * Copyright (c) 2000-2013 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.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            @Override
046            public AssetEntry getAssetEntry(long assetEntryId)
047                    throws PortalException, SystemException {
048    
049                    return AssetEntryLocalServiceUtil.getEntry(assetEntryId);
050            }
051    
052            @Override
053            public AssetEntry getAssetEntry(String className, long classPK)
054                    throws PortalException, SystemException {
055    
056                    return AssetEntryLocalServiceUtil.getEntry(className, classPK);
057            }
058    
059            @Override
060            public AssetRenderer getAssetRenderer(long classPK)
061                    throws PortalException, SystemException {
062    
063                    return getAssetRenderer(classPK, TYPE_LATEST_APPROVED);
064            }
065    
066            @Override
067            @SuppressWarnings("unused")
068            public AssetRenderer getAssetRenderer(long groupId, String urlTitle)
069                    throws PortalException, SystemException {
070    
071                    return null;
072            }
073    
074            @Override
075            public long getClassNameId() {
076                    return PortalUtil.getClassNameId(_className);
077            }
078    
079            @Override
080            public Map<Long, String> getClassTypes(long[] groupId, Locale locale)
081                    throws Exception {
082    
083                    return null;
084            }
085    
086            @Override
087            public String getIconPath(PortletRequest portletRequest) {
088                    ThemeDisplay themeDisplay = (ThemeDisplay)portletRequest.getAttribute(
089                            WebKeys.THEME_DISPLAY);
090    
091                    return getIconPath(themeDisplay);
092            }
093    
094            @Override
095            public String getPortletId() {
096                    return _portletId;
097            }
098    
099            @Override
100            @SuppressWarnings("unused")
101            public PortletURL getURLAdd(
102                            LiferayPortletRequest liferayPortletRequest,
103                            LiferayPortletResponse liferayPortletResponse)
104                    throws PortalException, SystemException {
105    
106                    return null;
107            }
108    
109            @Override
110            public boolean hasPermission(
111                            PermissionChecker permissionChecker, long classPK, String actionId)
112                    throws Exception {
113    
114                    return _PERMISSION;
115            }
116    
117            @Override
118            public boolean isCategorizable() {
119                    return true;
120            }
121    
122            @Override
123            public boolean isLinkable() {
124                    return _LINKABLE;
125            }
126    
127            @Override
128            public boolean isSelectable() {
129                    return _SELECTABLE;
130            }
131    
132            @Override
133            public void setClassName(String className) {
134                    _className = className;
135            }
136    
137            @Override
138            public void setPortletId(String portletId) {
139                    _portletId = portletId;
140            }
141    
142            protected long getControlPanelPlid(ThemeDisplay themeDisplay)
143                    throws PortalException, SystemException {
144    
145                    Group controlPanelGroup = GroupLocalServiceUtil.getGroup(
146                            themeDisplay.getCompanyId(), GroupConstants.CONTROL_PANEL);
147    
148                    return LayoutLocalServiceUtil.getDefaultPlid(
149                            controlPanelGroup.getGroupId(), true);
150            }
151    
152            protected String getIconPath(ThemeDisplay themeDisplay) {
153                    return themeDisplay.getPathThemeImages() + "/common/page.png";
154            }
155    
156            private static final boolean _LINKABLE = false;
157    
158            private static final boolean _PERMISSION = true;
159    
160            private static final boolean _SELECTABLE = true;
161    
162            private String _className;
163            private String _portletId;
164    
165    }