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 DLFileShortcutPermission.contains(
129 _permissionChecker, dlFileShortcut,
130 ActionKeys.UPDATE)) {
131
132 showInput = true;
133 }
134 }
135 catch (Exception e) {
136 }
137 }
138 else if (folder != null) {
139 name = Folder.class.getSimpleName();
140
141 try {
142 if (DLFolderPermission.contains(
143 _permissionChecker, folder, ActionKeys.DELETE) ||
144 DLFolderPermission.contains(
145 _permissionChecker, folder, ActionKeys.UPDATE)) {
146
147 showInput = true;
148 }
149 }
150 catch (Exception e) {
151 }
152 }
153
154 if (!showInput) {
155 return StringPool.BLANK;
156 }
157
158 StringBundler sb = new StringBundler();
159
160 sb.append("['");
161 sb.append(_liferayPortletResponse.getNamespace());
162 sb.append(RowChecker.ROW_IDS);
163 sb.append(Folder.class.getSimpleName());
164 sb.append("Checkbox', '");
165 sb.append(_liferayPortletResponse.getNamespace());
166 sb.append(RowChecker.ROW_IDS);
167 sb.append(DLFileShortcut.class.getSimpleName());
168 sb.append("Checkbox', '");
169 sb.append(_liferayPortletResponse.getNamespace());
170 sb.append(RowChecker.ROW_IDS);
171 sb.append(FileEntry.class.getSimpleName());
172 sb.append("Checkbox']");
173
174 String checkBoxRowIds = sb.toString();
175
176 return getRowCheckBox(
177 checked, disabled,
178 _liferayPortletResponse.getNamespace() + RowChecker.ROW_IDS +
179 name + "Checkbox",
180 primaryKey, checkBoxRowIds, "'#" + getAllRowIds() + "Checkbox'",
181 _liferayPortletResponse.getNamespace() + "toggleActionsButton();");
182 }
183
184 private LiferayPortletResponse _liferayPortletResponse;
185 private PermissionChecker _permissionChecker;
186
187 }