/
DLFolderItemSelectorView.java
186 lines (152 loc) · 6.24 KB
/
DLFolderItemSelectorView.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
/**
* Copyright (c) 2000-present Liferay, Inc. All rights reserved.
*
* This library is free software; you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License as published by the Free
* Software Foundation; either version 2.1 of the License, or (at your option)
* any later version.
*
* This library is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
* details.
*/
package com.liferay.document.library.item.selector.web.internal.folder;
import com.liferay.document.library.constants.DLPortletKeys;
import com.liferay.document.library.item.selector.web.internal.configuration.FFFolderItemSelectorGroupSelectorConfiguration;
import com.liferay.document.library.item.selector.web.internal.constants.DLItemSelectorViewConstants;
import com.liferay.document.library.item.selector.web.internal.display.context.DLSelectFolderDisplayContext;
import com.liferay.document.library.kernel.model.DLFolderConstants;
import com.liferay.document.library.kernel.service.DLAppService;
import com.liferay.item.selector.ItemSelectorReturnType;
import com.liferay.item.selector.ItemSelectorView;
import com.liferay.item.selector.PortletItemSelectorView;
import com.liferay.item.selector.criteria.FolderItemSelectorReturnType;
import com.liferay.item.selector.criteria.folder.criterion.FolderItemSelectorCriterion;
import com.liferay.portal.configuration.metatype.bnd.util.ConfigurableUtil;
import com.liferay.portal.kernel.repository.model.Folder;
import com.liferay.portal.kernel.resource.bundle.ResourceBundleLoader;
import com.liferay.portal.kernel.theme.ThemeDisplay;
import com.liferay.portal.kernel.util.ParamUtil;
import com.liferay.portal.kernel.util.Portal;
import com.liferay.portal.kernel.util.ResourceBundleUtil;
import com.liferay.portal.kernel.util.WebKeys;
import com.liferay.portal.language.LanguageResources;
import java.io.IOException;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.ResourceBundle;
import javax.portlet.PortletURL;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;
/**
* @author Adolfo Pérez
*/
@Component(
configurationPid = "com.liferay.document.library.item.selector.web.internal.configuration.FFFolderItemSelectorGroupSelectorConfiguration",
property = {
"item.selector.view.key=" + DLItemSelectorViewConstants.DL_FOLDER_ITEM_SELECTOR_VIEW_KEY,
"item.selector.view.order:Integer=100"
},
service = ItemSelectorView.class
)
public class DLFolderItemSelectorView
implements PortletItemSelectorView<FolderItemSelectorCriterion> {
@Override
public Class<FolderItemSelectorCriterion> getItemSelectorCriterionClass() {
return FolderItemSelectorCriterion.class;
}
@Override
public List<String> getPortletIds() {
return _portletIds;
}
@Override
public List<ItemSelectorReturnType> getSupportedItemSelectorReturnTypes() {
return _supportedItemSelectorReturnTypes;
}
@Override
public String getTitle(Locale locale) {
ResourceBundleLoader resourceBundleLoader =
LanguageResources.PORTAL_RESOURCE_BUNDLE_LOADER;
ResourceBundle resourceBundle = resourceBundleLoader.loadResourceBundle(
locale);
return ResourceBundleUtil.getString(
resourceBundle, "documents-and-media");
}
@Override
public void renderHTML(
ServletRequest servletRequest, ServletResponse servletResponse,
FolderItemSelectorCriterion itemSelectorCriterion,
PortletURL portletURL, String itemSelectedEventName, boolean search)
throws IOException, ServletException {
RequestDispatcher requestDispatcher =
_servletContext.getRequestDispatcher("/select_folder.jsp");
ThemeDisplay themeDisplay = (ThemeDisplay)servletRequest.getAttribute(
WebKeys.THEME_DISPLAY);
long repositoryId = themeDisplay.getScopeGroupId();
long folderId = ParamUtil.getLong(
(HttpServletRequest)servletRequest, "folderId",
itemSelectorCriterion.getFolderId());
if (repositoryId != itemSelectorCriterion.getRepositoryId()) {
folderId = ParamUtil.getLong(
(HttpServletRequest)servletRequest, "folderId");
}
servletRequest.setAttribute(
DLSelectFolderDisplayContext.class.getName(),
new DLSelectFolderDisplayContext(
_dlAppService, _fetchFolder(folderId),
(HttpServletRequest)servletRequest, portletURL, repositoryId,
itemSelectorCriterion.getSelectedFolderId(),
itemSelectorCriterion.getSelectedRepositoryId(),
_isShowGroupSelector(itemSelectorCriterion)));
requestDispatcher.include(servletRequest, servletResponse);
}
protected void activate(Map<String, Object> properties) {
_ffFolderItemSelectorGroupSelectorConfiguration =
ConfigurableUtil.createConfigurable(
FFFolderItemSelectorGroupSelectorConfiguration.class,
properties);
}
private Folder _fetchFolder(long folderId) {
try {
if (folderId == DLFolderConstants.DEFAULT_PARENT_FOLDER_ID) {
return null;
}
return _dlAppService.getFolder(folderId);
}
catch (Exception exception) {
return null;
}
}
private boolean _isShowGroupSelector(
FolderItemSelectorCriterion itemSelectorCriterion) {
if (!_ffFolderItemSelectorGroupSelectorConfiguration.enabled()) {
return false;
}
return itemSelectorCriterion.isShowGroupSelector();
}
private static final List<String> _portletIds = Arrays.asList(
DLPortletKeys.DOCUMENT_LIBRARY_ADMIN, DLPortletKeys.DOCUMENT_LIBRARY);
private static final List<ItemSelectorReturnType>
_supportedItemSelectorReturnTypes = Collections.singletonList(
new FolderItemSelectorReturnType());
@Reference
private DLAppService _dlAppService;
private volatile FFFolderItemSelectorGroupSelectorConfiguration
_ffFolderItemSelectorGroupSelectorConfiguration;
@Reference
private Portal _portal;
@Reference(
target = "(osgi.web.symbolicname=com.liferay.document.library.item.selector.web)"
)
private ServletContext _servletContext;
}