1
22
23 package com.liferay.portlet.rss.action;
24
25 import com.liferay.portal.kernel.portlet.BaseConfigurationAction;
26 import com.liferay.portal.kernel.servlet.SessionErrors;
27 import com.liferay.portal.kernel.servlet.SessionMessages;
28 import com.liferay.portal.kernel.util.Constants;
29 import com.liferay.portal.kernel.util.ParamUtil;
30 import com.liferay.portlet.PortletPreferencesFactoryUtil;
31
32 import javax.portlet.ActionRequest;
33 import javax.portlet.ActionResponse;
34 import javax.portlet.PortletConfig;
35 import javax.portlet.PortletPreferences;
36 import javax.portlet.RenderRequest;
37 import javax.portlet.RenderResponse;
38 import javax.portlet.ValidatorException;
39
40
45 public class ConfigurationActionImpl extends BaseConfigurationAction {
46
47 public void processAction(
48 PortletConfig portletConfig, ActionRequest actionRequest,
49 ActionResponse actionResponse)
50 throws Exception {
51
52 String cmd = ParamUtil.getString(actionRequest, Constants.CMD);
53
54 String portletResource = ParamUtil.getString(
55 actionRequest, "portletResource");
56
57 PortletPreferences prefs =
58 PortletPreferencesFactoryUtil.getPortletSetup(
59 actionRequest, portletResource);
60
61 if (cmd.equals("remove-footer-article")) {
62 removeFooterArticle(actionRequest, prefs);
63 }
64 else if (cmd.equals("remove-header-article")) {
65 removeHeaderArticle(actionRequest, prefs);
66 }
67 else if (cmd.equals("set-footer-article")) {
68 setFooterArticle(actionRequest, prefs);
69 }
70 else if (cmd.equals("set-header-article")) {
71 setHeaderArticle(actionRequest, prefs);
72 }
73 else if (cmd.equals(Constants.UPDATE)) {
74 updateConfiguration(actionRequest, prefs);
75 }
76
77 if (SessionErrors.isEmpty(actionRequest)) {
78 try {
79 prefs.store();
80 }
81 catch (ValidatorException ve) {
82 SessionErrors.add(
83 actionRequest, ValidatorException.class.getName(), ve);
84
85 return;
86 }
87
88 SessionMessages.add(
89 actionRequest, portletConfig.getPortletName() + ".doConfigure");
90 }
91 }
92
93 public String render(
94 PortletConfig portletConfig, RenderRequest renderRequest,
95 RenderResponse renderResponse)
96 throws Exception {
97
98 return "/html/portlet/rss/configuration.jsp";
99 }
100
101 protected void removeFooterArticle(
102 ActionRequest actionRequest, PortletPreferences prefs)
103 throws Exception {
104
105 prefs.setValues(
106 "footer-article-resource-values", new String[] {"0", ""});
107 }
108
109 protected void removeHeaderArticle(
110 ActionRequest actionRequest, PortletPreferences prefs)
111 throws Exception {
112
113 prefs.setValues(
114 "header-article-resource-values", new String[] {"0", ""});
115 }
116
117 protected void setFooterArticle(
118 ActionRequest actionRequest, PortletPreferences prefs)
119 throws Exception {
120
121 String footerArticleResourcePrimKey = ParamUtil.getString(
122 actionRequest, "resourcePrimKey");
123 String footerArticleResouceTitle = ParamUtil.getString(
124 actionRequest, "resourceTitle");
125
126 prefs.setValues(
127 "footer-article-resource-values",
128 new String[] {
129 footerArticleResourcePrimKey, footerArticleResouceTitle
130 });
131 }
132
133 protected void setHeaderArticle(
134 ActionRequest actionRequest, PortletPreferences prefs)
135 throws Exception {
136
137 String headerArticleResourcePrimKey = ParamUtil.getString(
138 actionRequest, "resourcePrimKey");
139 String headerArticleResouceTitle = ParamUtil.getString(
140 actionRequest, "resourceTitle");
141
142 prefs.setValues(
143 "header-article-resource-values",
144 new String[] {headerArticleResourcePrimKey, headerArticleResouceTitle});
145 }
146
147 protected void updateConfiguration(
148 ActionRequest actionRequest, PortletPreferences prefs)
149 throws Exception {
150
151 String[] urls = actionRequest.getParameterValues("url");
152 String[] titles = actionRequest.getParameterValues("title");
153 int entriesPerFeed = ParamUtil.getInteger(
154 actionRequest, "entriesPerFeed", 4);
155 int expandedEntriesPerFeed = ParamUtil.getInteger(
156 actionRequest, "expandedEntriesPerFeed", 1);
157 boolean showFeedTitle = ParamUtil.getBoolean(
158 actionRequest, "showFeedTitle");
159 boolean showFeedPublishedDate = ParamUtil.getBoolean(
160 actionRequest, "showFeedPublishedDate");
161 boolean showFeedDescription = ParamUtil.getBoolean(
162 actionRequest, "showFeedDescription");
163 boolean showFeedImage = ParamUtil.getBoolean(
164 actionRequest, "showFeedImage");
165 String feedImageAlignment = ParamUtil.getString(
166 actionRequest, "feedImageAlignment");
167 boolean showFeedItemAuthor = ParamUtil.getBoolean(
168 actionRequest, "showFeedItemAuthor");
169
170 if (urls != null && titles != null) {
171 prefs.setValues("urls", urls);
172 prefs.setValues("titles", titles);
173 }
174 else {
175 prefs.setValues("urls", new String[0]);
176 prefs.setValues("titles", new String[0]);
177 }
178
179 prefs.setValue("items-per-channel", String.valueOf(entriesPerFeed));
180 prefs.setValue(
181 "expanded-items-per-channel",
182 String.valueOf(expandedEntriesPerFeed));
183 prefs.setValue("show-feed-title", String.valueOf(showFeedTitle));
184 prefs.setValue(
185 "show-feed-published-date", String.valueOf(showFeedPublishedDate));
186 prefs.setValue(
187 "show-feed-description", String.valueOf(showFeedDescription));
188 prefs.setValue("show-feed-image", String.valueOf(showFeedImage));
189 prefs.setValue(
190 "feed-image-alignment", String.valueOf(feedImageAlignment));
191 prefs.setValue(
192 "show-feed-item-author", String.valueOf(showFeedItemAuthor));
193 }
194
195 }