1
22
23 package com.liferay.portlet.portletconfiguration.action;
24
25 import com.liferay.portal.NoSuchPortletItemException;
26 import com.liferay.portal.PortletItemNameException;
27 import com.liferay.portal.kernel.servlet.SessionErrors;
28 import com.liferay.portal.kernel.util.Constants;
29 import com.liferay.portal.kernel.util.ParamUtil;
30 import com.liferay.portal.model.Layout;
31 import com.liferay.portal.model.Portlet;
32 import com.liferay.portal.security.auth.PrincipalException;
33 import com.liferay.portal.service.PortletPreferencesServiceUtil;
34 import com.liferay.portal.theme.ThemeDisplay;
35 import com.liferay.portal.util.WebKeys;
36 import com.liferay.portlet.PortletPreferencesFactoryUtil;
37
38 import javax.portlet.ActionRequest;
39 import javax.portlet.ActionResponse;
40 import javax.portlet.PortletConfig;
41 import javax.portlet.PortletPreferences;
42 import javax.portlet.RenderRequest;
43 import javax.portlet.RenderResponse;
44
45 import org.apache.struts.action.ActionForm;
46 import org.apache.struts.action.ActionForward;
47 import org.apache.struts.action.ActionMapping;
48
49
55 public class EditArchivedSetupsAction extends EditConfigurationAction {
56
57 public void processAction(
58 ActionMapping mapping, ActionForm form, PortletConfig portletConfig,
59 ActionRequest actionRequest, ActionResponse actionResponse)
60 throws Exception {
61
62 Portlet portlet = null;
63
64 try {
65 portlet = getPortlet(actionRequest);
66 }
67 catch (PrincipalException pe) {
68 SessionErrors.add(
69 actionRequest, PrincipalException.class.getName());
70
71 setForward(actionRequest, "portlet.portlet_configuration.error");
72 }
73
74 String cmd = ParamUtil.getString(actionRequest, Constants.CMD);
75
76 try {
77 if (cmd.equals(Constants.SAVE)) {
78 updateSetup(actionRequest, portlet);
79
80 sendRedirect(actionRequest, actionResponse);
81 }
82 else if (cmd.equals(Constants.RESTORE)) {
83 restoreSetup(actionRequest, portlet);
84
85 sendRedirect(actionRequest, actionResponse);
86 }
87 else if (cmd.equals(Constants.DELETE)) {
88 deleteSetup(actionRequest);
89
90 sendRedirect(actionRequest, actionResponse);
91 }
92 }
93 catch (Exception e) {
94 if (e instanceof NoSuchPortletItemException ||
95 e instanceof PortletItemNameException) {
96
97 SessionErrors.add(actionRequest, e.getClass().getName());
98
99 setForward(
100 actionRequest,
101 "portlet.portlet_configuration.edit_archived_setups");
102 }
103 else if (e instanceof PrincipalException) {
104 SessionErrors.add(actionRequest, e.getClass().getName());
105
106 setForward(
107 actionRequest, "portlet.portlet_configuration.error");
108 }
109 else {
110 throw e;
111 }
112 }
113 }
114
115 public ActionForward render(
116 ActionMapping mapping, ActionForm form, PortletConfig portletConfig,
117 RenderRequest renderRequest, RenderResponse renderResponse)
118 throws Exception {
119
120 Portlet portlet = null;
121
122 try {
123 portlet = getPortlet(renderRequest);
124 }
125 catch (PrincipalException pe) {
126 SessionErrors.add(
127 renderRequest, PrincipalException.class.getName());
128
129 return mapping.findForward("portlet.portlet_configuration.error");
130 }
131
132 renderResponse.setTitle(getTitle(portlet, renderRequest));
133
134 return mapping.findForward(getForward(
135 renderRequest,
136 "portlet.portlet_configuration.edit_archived_setups"));
137 }
138
139 private void deleteSetup(ActionRequest actionRequest) throws Exception {
140 long portletItemId = ParamUtil.getLong(actionRequest, "portletItemId");
141
142 PortletPreferencesServiceUtil.deleteArchivedPreferences(portletItemId);
143 }
144
145 private void restoreSetup(ActionRequest actionRequest, Portlet portlet)
146 throws Exception {
147
148 Layout layout = (Layout)actionRequest.getAttribute(WebKeys.LAYOUT);
149
150 String name = ParamUtil.getString(actionRequest, "name");
151
152 PortletPreferences setup =
153 PortletPreferencesFactoryUtil.getPortletSetup(
154 actionRequest, portlet.getPortletId());
155
156 PortletPreferencesServiceUtil.restoreArchivedPreferences(
157 layout.getGroupId(), name, portlet.getRootPortletId(), setup);
158 }
159
160 protected void updateSetup(ActionRequest actionRequest, Portlet portlet)
161 throws Exception {
162
163 ThemeDisplay themeDisplay = (ThemeDisplay)actionRequest.getAttribute(
164 WebKeys.THEME_DISPLAY);
165
166 String name = ParamUtil.getString(actionRequest, "name");
167
168 PortletPreferences setup =
169 PortletPreferencesFactoryUtil.getPortletSetup(
170 actionRequest, portlet.getPortletId());
171
172 PortletPreferencesServiceUtil.updateArchivePreferences(
173 themeDisplay.getUserId(), themeDisplay.getLayout().getGroupId(),
174 name, portlet.getRootPortletId(), setup);
175 }
176
177 }