001
014
015 package com.liferay.portlet.journal.search;
016
017 import com.liferay.portal.kernel.dao.search.RowChecker;
018 import com.liferay.portal.kernel.portlet.LiferayPortletRequest;
019 import com.liferay.portal.kernel.portlet.LiferayPortletResponse;
020 import com.liferay.portal.kernel.util.GetterUtil;
021 import com.liferay.portal.kernel.util.StringBundler;
022 import com.liferay.portal.kernel.util.StringPool;
023 import com.liferay.portal.kernel.util.WebKeys;
024 import com.liferay.portal.security.permission.ActionKeys;
025 import com.liferay.portal.security.permission.PermissionChecker;
026 import com.liferay.portal.theme.ThemeDisplay;
027 import com.liferay.portlet.journal.NoSuchArticleException;
028 import com.liferay.portlet.journal.model.JournalArticle;
029 import com.liferay.portlet.journal.model.JournalFolder;
030 import com.liferay.portlet.journal.service.JournalArticleServiceUtil;
031 import com.liferay.portlet.journal.service.JournalFolderServiceUtil;
032 import com.liferay.portlet.journal.service.permission.JournalArticlePermission;
033 import com.liferay.portlet.journal.service.permission.JournalFolderPermission;
034
035 import javax.servlet.http.HttpServletRequest;
036
037
040 public class EntriesChecker extends RowChecker {
041
042 public EntriesChecker(
043 LiferayPortletRequest liferayPortletRequest,
044 LiferayPortletResponse liferayPortletResponse) {
045
046 super(liferayPortletResponse);
047
048 _liferayPortletResponse = liferayPortletResponse;
049
050 ThemeDisplay themeDisplay =
051 (ThemeDisplay)liferayPortletRequest.getAttribute(
052 WebKeys.THEME_DISPLAY);
053
054 _permissionChecker = themeDisplay.getPermissionChecker();
055 }
056
057 @Override
058 public String getAllRowsCheckBox() {
059 return null;
060 }
061
062 @Override
063 public String getAllRowsCheckBox(HttpServletRequest request) {
064 return null;
065 }
066
067 @Override
068 public String getRowCheckBox(
069 HttpServletRequest request, boolean checked, boolean disabled,
070 String primaryKey) {
071
072 ThemeDisplay themeDisplay = (ThemeDisplay)request.getAttribute(
073 WebKeys.THEME_DISPLAY);
074
075 JournalArticle article = null;
076 JournalFolder folder = null;
077
078 String articleId = GetterUtil.getString(primaryKey);
079
080 try {
081 article = JournalArticleServiceUtil.getArticle(
082 themeDisplay.getScopeGroupId(), articleId);
083 }
084 catch (Exception e1) {
085 if (e1 instanceof NoSuchArticleException) {
086 try {
087 long folderId = GetterUtil.getLong(primaryKey);
088
089 folder = JournalFolderServiceUtil.getFolder(folderId);
090 }
091 catch (Exception e2) {
092 return StringPool.BLANK;
093 }
094 }
095 }
096
097 boolean showInput = false;
098
099 String name = null;
100
101 if (article != null) {
102 name = JournalArticle.class.getSimpleName();
103
104 try {
105 if (JournalArticlePermission.contains(
106 _permissionChecker, article, ActionKeys.DELETE) ||
107 JournalArticlePermission.contains(
108 _permissionChecker, article, ActionKeys.EXPIRE) ||
109 JournalArticlePermission.contains(
110 _permissionChecker, article, ActionKeys.UPDATE)) {
111
112 showInput = true;
113 }
114 }
115 catch (Exception e) {
116 }
117 }
118 else if (folder != null) {
119 name = JournalFolder.class.getSimpleName();
120
121 try {
122 if (JournalFolderPermission.contains(
123 _permissionChecker, folder, ActionKeys.DELETE)) {
124
125 showInput = true;
126 }
127 }
128 catch (Exception e) {
129 }
130 }
131
132 if (!showInput) {
133 return StringPool.BLANK;
134 }
135
136 StringBundler sb = new StringBundler();
137
138 sb.append("['");
139 sb.append(_liferayPortletResponse.getNamespace());
140 sb.append(RowChecker.ROW_IDS);
141 sb.append(JournalFolder.class.getSimpleName());
142 sb.append("Checkbox', '");
143 sb.append(_liferayPortletResponse.getNamespace());
144 sb.append(RowChecker.ROW_IDS);
145 sb.append(JournalArticle.class.getSimpleName());
146 sb.append("Checkbox']");
147
148 String checkBoxRowIds = sb.toString();
149
150 return getRowCheckBox(
151 request, checked, disabled,
152 _liferayPortletResponse.getNamespace() + RowChecker.ROW_IDS +
153 name + "Checkbox",
154 primaryKey, checkBoxRowIds, "'#" + getAllRowIds() + "Checkbox'",
155 StringPool.BLANK);
156 }
157
158 private LiferayPortletResponse _liferayPortletResponse;
159 private PermissionChecker _permissionChecker;
160
161 }