001
014
015 package com.liferay.portlet.documentlibrary.search;
016
017 import com.liferay.portal.NoSuchRepositoryEntryException;
018 import com.liferay.portal.kernel.dao.search.RowChecker;
019 import com.liferay.portal.kernel.portlet.LiferayPortletRequest;
020 import com.liferay.portal.kernel.portlet.LiferayPortletResponse;
021 import com.liferay.portal.kernel.repository.model.FileEntry;
022 import com.liferay.portal.kernel.repository.model.Folder;
023 import com.liferay.portal.kernel.util.GetterUtil;
024 import com.liferay.portal.kernel.util.StringBundler;
025 import com.liferay.portal.kernel.util.StringPool;
026 import com.liferay.portal.kernel.util.WebKeys;
027 import com.liferay.portal.security.permission.ActionKeys;
028 import com.liferay.portal.security.permission.PermissionChecker;
029 import com.liferay.portal.theme.ThemeDisplay;
030 import com.liferay.portlet.documentlibrary.NoSuchFileEntryException;
031 import com.liferay.portlet.documentlibrary.NoSuchFileShortcutException;
032 import com.liferay.portlet.documentlibrary.model.DLFileShortcut;
033 import com.liferay.portlet.documentlibrary.service.DLAppServiceUtil;
034 import com.liferay.portlet.documentlibrary.service.permission.DLFileEntryPermission;
035 import com.liferay.portlet.documentlibrary.service.permission.DLFileShortcutPermission;
036 import com.liferay.portlet.documentlibrary.service.permission.DLFolderPermission;
037
038
041 public class EntriesChecker extends RowChecker {
042
043 public EntriesChecker(
044 LiferayPortletRequest liferayPortletRequest,
045 LiferayPortletResponse liferayPortletResponse) {
046
047 super(liferayPortletResponse);
048
049 _liferayPortletResponse = liferayPortletResponse;
050
051 ThemeDisplay themeDisplay =
052 (ThemeDisplay)liferayPortletRequest.getAttribute(
053 WebKeys.THEME_DISPLAY);
054
055 _permissionChecker = themeDisplay.getPermissionChecker();
056 }
057
058 @Override
059 public String getAllRowsCheckBox() {
060 return null;
061 }
062
063 @Override
064 public String getRowCheckBox(
065 boolean checked, boolean disabled, String primaryKey) {
066
067 DLFileShortcut dlFileShortcut = null;
068 FileEntry fileEntry = null;
069 Folder folder = null;
070
071 long entryId = GetterUtil.getLong(primaryKey);
072
073 try {
074 fileEntry = DLAppServiceUtil.getFileEntry(entryId);
075 }
076 catch (Exception e1) {
077 if (e1 instanceof NoSuchFileEntryException ||
078 e1 instanceof NoSuchRepositoryEntryException) {
079
080 try {
081 dlFileShortcut = DLAppServiceUtil.getFileShortcut(entryId);
082 }
083 catch (Exception e2) {
084 if (e2 instanceof NoSuchFileShortcutException) {
085 try {
086 folder = DLAppServiceUtil.getFolder(entryId);
087 }
088 catch (Exception e3) {
089 return StringPool.BLANK;
090 }
091 }
092 else {
093 return StringPool.BLANK;
094 }
095 }
096 }
097 else {
098 return StringPool.BLANK;
099 }
100 }
101
102 boolean showInput = false;
103
104 String name = null;
105
106 if (fileEntry != null) {
107 name = FileEntry.class.getSimpleName();
108
109 try {
110 if (DLFileEntryPermission.contains(
111 _permissionChecker, fileEntry, ActionKeys.DELETE) ||
112 DLFileEntryPermission.contains(
113 _permissionChecker, fileEntry, ActionKeys.UPDATE)) {
114
115 showInput = true;
116 }
117 }
118 catch (Exception e) {
119 }
120 }
121 else if (dlFileShortcut != null) {
122 name = DLFileShortcut.class.getSimpleName();
123
124 try {
125 if (DLFileShortcutPermission.contains(
126 _permissionChecker, dlFileShortcut,
127 ActionKeys.DELETE)) {
128
129 showInput = true;
130 }
131 }
132 catch (Exception e) {
133 }
134 }
135 else if (folder != null) {
136 name = Folder.class.getSimpleName();
137
138 try {
139 if (DLFolderPermission.contains(
140 _permissionChecker, folder, ActionKeys.DELETE)) {
141
142 showInput = true;
143 }
144 }
145 catch (Exception e) {
146 }
147 }
148
149 if (!showInput) {
150 return StringPool.BLANK;
151 }
152
153 StringBundler sb = new StringBundler();
154
155 sb.append("['");
156 sb.append(_liferayPortletResponse.getNamespace());
157 sb.append(RowChecker.ROW_IDS);
158 sb.append(Folder.class.getSimpleName());
159 sb.append("Checkbox', '");
160 sb.append(_liferayPortletResponse.getNamespace());
161 sb.append(RowChecker.ROW_IDS);
162 sb.append(DLFileShortcut.class.getSimpleName());
163 sb.append("Checkbox', '");
164 sb.append(_liferayPortletResponse.getNamespace());
165 sb.append(RowChecker.ROW_IDS);
166 sb.append(FileEntry.class.getSimpleName());
167 sb.append("Checkbox']");
168
169 String checkBoxRowIds = sb.toString();
170
171 return getRowCheckBox(
172 checked, disabled,
173 _liferayPortletResponse.getNamespace() + RowChecker.ROW_IDS +
174 name + "Checkbox",
175 primaryKey, checkBoxRowIds, "'#" + getAllRowIds() + "Checkbox'",
176 _liferayPortletResponse.getNamespace() + "toggleActionsButton();");
177 }
178
179 private LiferayPortletResponse _liferayPortletResponse;
180 private PermissionChecker _permissionChecker;
181
182 }