001    /**
002     * Copyright (c) 2000-2012 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.HttpUtil;
022    import com.liferay.portal.kernel.util.StringBundler;
023    import com.liferay.portal.kernel.util.StringPool;
024    import com.liferay.portal.kernel.util.WebKeys;
025    import com.liferay.portal.model.Group;
026    import com.liferay.portal.model.GroupConstants;
027    import com.liferay.portal.security.permission.PermissionChecker;
028    import com.liferay.portal.service.GroupLocalServiceUtil;
029    import com.liferay.portal.service.LayoutLocalServiceUtil;
030    import com.liferay.portal.theme.ThemeDisplay;
031    
032    import javax.portlet.PortletRequest;
033    import javax.portlet.PortletURL;
034    import javax.portlet.WindowState;
035    
036    import javax.servlet.http.HttpServletRequest;
037    
038    /**
039     * @author Jorge Ferrer
040     * @author Sergio González
041     */
042    public abstract class BaseAssetRenderer implements AssetRenderer {
043    
044            public String[] getAvailableLocales() {
045                    return _AVAILABLE_LOCALES;
046            }
047    
048            public String getDiscussionPath() {
049                    return null;
050            }
051    
052            public String getIconPath(PortletRequest portletRequest) {
053                    ThemeDisplay themeDisplay = (ThemeDisplay)portletRequest.getAttribute(
054                            WebKeys.THEME_DISPLAY);
055    
056                    return getIconPath(themeDisplay);
057            }
058    
059            public PortletURL getURLEdit(
060                            LiferayPortletRequest liferayPortletRequest,
061                            LiferayPortletResponse liferayPortletResponse)
062                    throws Exception {
063    
064                    return null;
065            }
066    
067            public PortletURL getURLExport(
068                            LiferayPortletRequest liferayPortletRequest,
069                            LiferayPortletResponse liferayPortletResponse)
070                    throws Exception {
071    
072                    return null;
073            }
074    
075            public String getUrlTitle() {
076                    return null;
077            }
078    
079            public PortletURL getURLView(
080                            LiferayPortletResponse liferayPortletResponse,
081                            WindowState windowState)
082                    throws Exception {
083    
084                    return null;
085            }
086    
087            public String getURLViewInContext(
088                            LiferayPortletRequest liferayPortletRequest,
089                            LiferayPortletResponse liferayPortletResponse,
090                            String noSuchEntryRedirect)
091                    throws Exception {
092    
093                    return null;
094            }
095    
096            public String getViewInContextMessage() {
097                    return "view-in-context";
098            }
099    
100            @SuppressWarnings("unused")
101            public boolean hasEditPermission(PermissionChecker permissionChecker)
102                    throws PortalException, SystemException {
103    
104                    return false;
105            }
106    
107            @SuppressWarnings("unused")
108            public boolean hasViewPermission(PermissionChecker permissionChecker)
109                    throws PortalException, SystemException {
110    
111                    return true;
112            }
113    
114            public boolean isConvertible() {
115                    return false;
116            }
117    
118            public boolean isDisplayable() {
119                    return true;
120            }
121    
122            public boolean isLocalizable() {
123                    return false;
124            }
125    
126            public boolean isPrintable() {
127                    return false;
128            }
129    
130            protected long getControlPanelPlid(
131                            LiferayPortletRequest liferayPortletRequest)
132                    throws PortalException, SystemException {
133    
134                    HttpServletRequest request =
135                            liferayPortletRequest.getHttpServletRequest();
136    
137                    ThemeDisplay themeDisplay = (ThemeDisplay)request.getAttribute(
138                            WebKeys.THEME_DISPLAY);
139    
140                    Group controlPanelGroup = GroupLocalServiceUtil.getGroup(
141                            themeDisplay.getCompanyId(), GroupConstants.CONTROL_PANEL);
142    
143                    return LayoutLocalServiceUtil.getDefaultPlid(
144                            controlPanelGroup.getGroupId(), true);
145            }
146    
147            protected long getControlPanelPlid(ThemeDisplay themeDisplay)
148                    throws PortalException, SystemException {
149    
150                    Group controlPanelGroup = GroupLocalServiceUtil.getGroup(
151                            themeDisplay.getCompanyId(), GroupConstants.CONTROL_PANEL);
152    
153                    return LayoutLocalServiceUtil.getDefaultPlid(
154                            controlPanelGroup.getGroupId(), true);
155            }
156    
157            protected String getIconPath(ThemeDisplay themeDisplay) {
158                    return themeDisplay.getPathThemeImages() + "/common/page.png";
159            }
160    
161            protected String getURLViewInContext(
162                    LiferayPortletRequest liferayPortletRequest, String noSuchEntryRedirect,
163                    String path, String primaryKeyParameterName,
164                    long primaryKeyParameterValue) {
165    
166                    ThemeDisplay themeDisplay =
167                            (ThemeDisplay)liferayPortletRequest.getAttribute(
168                                    WebKeys.THEME_DISPLAY);
169    
170                    StringBundler sb = new StringBundler(11);
171    
172                    sb.append(themeDisplay.getPortalURL());
173                    sb.append(themeDisplay.getPathMain());
174                    sb.append(path);
175                    sb.append("?p_l_id=");
176                    sb.append(themeDisplay.getPlid());
177                    sb.append("&noSuchEntryRedirect=");
178                    sb.append(HttpUtil.encodeURL(noSuchEntryRedirect));
179                    sb.append(StringPool.AMPERSAND);
180                    sb.append(primaryKeyParameterName);
181                    sb.append(StringPool.EQUAL);
182                    sb.append(primaryKeyParameterValue);
183    
184                    return sb.toString();
185            }
186    
187            private static final String[] _AVAILABLE_LOCALES = new String[0];
188    
189    }