/
DefaultConfigurationAction.java
81 lines (63 loc) · 2.26 KB
/
DefaultConfigurationAction.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
/**
* SPDX-FileCopyrightText: (c) 2000 Liferay, Inc. https://liferay.com
* SPDX-License-Identifier: LGPL-2.1-or-later OR LicenseRef-Liferay-DXP-EULA-2.0.0-2023-06
*/
package com.liferay.portal.kernel.portlet;
import com.liferay.portal.kernel.exception.PortalException;
import com.liferay.portal.kernel.exception.SystemException;
import com.liferay.portal.kernel.settings.PortletPreferencesSettings;
import com.liferay.portal.kernel.settings.Settings;
import com.liferay.portal.kernel.util.StringUtil;
import javax.portlet.ActionRequest;
import javax.portlet.PortletPreferences;
import javax.portlet.PortletRequest;
import javax.portlet.ReadOnlyException;
/**
* @author Iván Zaera
*/
public class DefaultConfigurationAction
extends BaseJSPSettingsConfigurationAction
implements ConfigurationAction, ResourceServingConfigurationAction {
public DefaultConfigurationAction() {
setParameterNamePrefix("preferences--");
}
@Override
protected Settings getSettings(ActionRequest actionRequest) {
return new PortletPreferencesSettings(actionRequest.getPreferences());
}
protected void postProcess(
long companyId, PortletRequest portletRequest,
PortletPreferences portletPreferences)
throws PortalException {
}
@Override
protected void postProcess(
long companyId, PortletRequest portletRequest, Settings settings)
throws PortalException {
PortletPreferencesSettings portletPreferencesSettings =
(PortletPreferencesSettings)settings;
postProcess(
companyId, portletRequest,
portletPreferencesSettings.getPortletPreferences());
}
protected void removeDefaultValue(
PortletRequest portletRequest, PortletPreferences portletPreferences,
String key, String defaultValue) {
String value = getParameter(portletRequest, key);
if (defaultValue.equals(value) ||
StringUtil.equalsIgnoreBreakLine(defaultValue, value)) {
try {
portletPreferences.reset(key);
}
catch (ReadOnlyException readOnlyException) {
throw new SystemException(readOnlyException);
}
}
}
@Override
protected void updateMultiValuedKeys(ActionRequest actionRequest) {
// Legacy configuration actions that are not based on Settings must
// ignore this method to avoid failures due to multi valued keys not
// registering with SettingsConfigurationAction
}
}