001
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
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 isPreviewInContext() {
127 return false;
128 }
129
130 public boolean isPrintable() {
131 return false;
132 }
133
134 protected long getControlPanelPlid(
135 LiferayPortletRequest liferayPortletRequest)
136 throws PortalException, SystemException {
137
138 HttpServletRequest request =
139 liferayPortletRequest.getHttpServletRequest();
140
141 ThemeDisplay themeDisplay = (ThemeDisplay)request.getAttribute(
142 WebKeys.THEME_DISPLAY);
143
144 Group controlPanelGroup = GroupLocalServiceUtil.getGroup(
145 themeDisplay.getCompanyId(), GroupConstants.CONTROL_PANEL);
146
147 return LayoutLocalServiceUtil.getDefaultPlid(
148 controlPanelGroup.getGroupId(), true);
149 }
150
151 protected long getControlPanelPlid(ThemeDisplay themeDisplay)
152 throws PortalException, SystemException {
153
154 Group controlPanelGroup = GroupLocalServiceUtil.getGroup(
155 themeDisplay.getCompanyId(), GroupConstants.CONTROL_PANEL);
156
157 return LayoutLocalServiceUtil.getDefaultPlid(
158 controlPanelGroup.getGroupId(), true);
159 }
160
161 protected String getIconPath(ThemeDisplay themeDisplay) {
162 return themeDisplay.getPathThemeImages() + "/common/page.png";
163 }
164
165 protected String getURLViewInContext(
166 LiferayPortletRequest liferayPortletRequest, String noSuchEntryRedirect,
167 String path, String primaryKeyParameterName,
168 long primaryKeyParameterValue) {
169
170 ThemeDisplay themeDisplay =
171 (ThemeDisplay)liferayPortletRequest.getAttribute(
172 WebKeys.THEME_DISPLAY);
173
174 StringBundler sb = new StringBundler(11);
175
176 sb.append(themeDisplay.getPortalURL());
177 sb.append(themeDisplay.getPathMain());
178 sb.append(path);
179 sb.append("?p_l_id=");
180 sb.append(themeDisplay.getPlid());
181 sb.append("&noSuchEntryRedirect=");
182 sb.append(HttpUtil.encodeURL(noSuchEntryRedirect));
183 sb.append(StringPool.AMPERSAND);
184 sb.append(primaryKeyParameterName);
185 sb.append(StringPool.EQUAL);
186 sb.append(primaryKeyParameterValue);
187
188 return sb.toString();
189 }
190
191 private static final String[] _AVAILABLE_LOCALES = new String[0];
192
193 }