001
014
015 package com.liferay.portlet.wiki.asset;
016
017 import com.liferay.portal.kernel.exception.PortalException;
018 import com.liferay.portal.kernel.exception.SystemException;
019 import com.liferay.portal.security.permission.PermissionChecker;
020 import com.liferay.portal.theme.ThemeDisplay;
021 import com.liferay.portlet.asset.model.AssetRenderer;
022 import com.liferay.portlet.asset.model.BaseAssetRendererFactory;
023 import com.liferay.portlet.wiki.NoSuchPageException;
024 import com.liferay.portlet.wiki.model.WikiPage;
025 import com.liferay.portlet.wiki.model.WikiPageResource;
026 import com.liferay.portlet.wiki.service.WikiPageLocalServiceUtil;
027 import com.liferay.portlet.wiki.service.WikiPageResourceLocalServiceUtil;
028 import com.liferay.portlet.wiki.service.permission.WikiPagePermission;
029
030
037 public class WikiPageAssetRendererFactory extends BaseAssetRendererFactory {
038
039 public static final String CLASS_NAME = WikiPage.class.getName();
040
041 public static final String TYPE = "wiki";
042
043 @Override
044 public AssetRenderer getAssetRenderer(long classPK, int type)
045 throws PortalException, SystemException {
046
047 WikiPage page = null;
048
049 try {
050 page = WikiPageLocalServiceUtil.getWikiPage(classPK);
051 }
052 catch (NoSuchPageException nspe) {
053 if (type == TYPE_LATEST_APPROVED) {
054 page = WikiPageLocalServiceUtil.getPage(classPK);
055 }
056 else {
057 WikiPageResource wikiPageResource =
058 WikiPageResourceLocalServiceUtil.getPageResource(classPK);
059
060 page = WikiPageLocalServiceUtil.getPage(
061 wikiPageResource.getNodeId(), wikiPageResource.getTitle(),
062 null);
063 }
064 }
065
066 return new WikiPageAssetRenderer(page);
067 }
068
069 @Override
070 public String getClassName() {
071 return CLASS_NAME;
072 }
073
074 @Override
075 public String getType() {
076 return TYPE;
077 }
078
079 @Override
080 public boolean hasPermission(
081 PermissionChecker permissionChecker, long classPK, String actionId)
082 throws Exception {
083
084 return WikiPagePermission.contains(
085 permissionChecker, classPK, actionId);
086 }
087
088 @Override
089 public boolean isLinkable() {
090 return _LINKABLE;
091 }
092
093 @Override
094 protected String getIconPath(ThemeDisplay themeDisplay) {
095 return themeDisplay.getPathThemeImages() + "/common/pages.png";
096 }
097
098 private static final boolean _LINKABLE = true;
099
100 }