001: /**
002: * Copyright (c) 2000-2008 Liferay, Inc. All rights reserved.
003: *
004: * Permission is hereby granted, free of charge, to any person obtaining a copy
005: * of this software and associated documentation files (the "Software"), to deal
006: * in the Software without restriction, including without limitation the rights
007: * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
008: * copies of the Software, and to permit persons to whom the Software is
009: * furnished to do so, subject to the following conditions:
010: *
011: * The above copyright notice and this permission notice shall be included in
012: * all copies or substantial portions of the Software.
013: *
014: * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
015: * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
016: * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
017: * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
018: * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
019: * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
020: * SOFTWARE.
021: */package com.liferay.portlet.rss.action;
022:
023: import com.liferay.portal.kernel.portlet.ConfigurationAction;
024: import com.liferay.portal.kernel.util.Constants;
025: import com.liferay.portal.kernel.util.ParamUtil;
026: import com.liferay.portlet.PortletPreferencesFactoryUtil;
027: import com.liferay.util.servlet.SessionErrors;
028: import com.liferay.util.servlet.SessionMessages;
029:
030: import javax.portlet.ActionRequest;
031: import javax.portlet.ActionResponse;
032: import javax.portlet.PortletConfig;
033: import javax.portlet.PortletPreferences;
034: import javax.portlet.RenderRequest;
035: import javax.portlet.RenderResponse;
036: import javax.portlet.ValidatorException;
037:
038: /**
039: * <a href="ConfigurationActionImpl.java.html"><b><i>View Source</i></b></a>
040: *
041: * @author Brian Wing Shun Chan
042: *
043: */
044: public class ConfigurationActionImpl implements ConfigurationAction {
045:
046: public void processAction(PortletConfig config, ActionRequest req,
047: ActionResponse res) throws Exception {
048:
049: String cmd = ParamUtil.getString(req, Constants.CMD);
050:
051: String portletResource = ParamUtil.getString(req,
052: "portletResource");
053:
054: PortletPreferences prefs = PortletPreferencesFactoryUtil
055: .getPortletSetup(req, portletResource, true, true);
056:
057: if (cmd.equals("remove-footer-article")) {
058: removeFooterArticle(req, prefs);
059: } else if (cmd.equals("remove-header-article")) {
060: removeHeaderArticle(req, prefs);
061: } else if (cmd.equals("set-footer-article")) {
062: setFooterArticle(req, prefs);
063: } else if (cmd.equals("set-header-article")) {
064: setHeaderArticle(req, prefs);
065: } else if (cmd.equals(Constants.UPDATE)) {
066: updateConfiguration(req, prefs);
067: }
068:
069: if (SessionErrors.isEmpty(req)) {
070: try {
071: prefs.store();
072: } catch (ValidatorException ve) {
073: SessionErrors.add(req, ValidatorException.class
074: .getName(), ve);
075:
076: return;
077: }
078:
079: SessionMessages.add(req, config.getPortletName()
080: + ".doConfigure");
081: }
082: }
083:
084: public String render(PortletConfig config, RenderRequest req,
085: RenderResponse res) throws Exception {
086:
087: return "/html/portlet/rss/configuration.jsp";
088: }
089:
090: protected void removeFooterArticle(ActionRequest req,
091: PortletPreferences prefs) throws Exception {
092:
093: prefs.setValues("footer-article-resouce-values", new String[] {
094: "0", "" });
095: }
096:
097: protected void removeHeaderArticle(ActionRequest req,
098: PortletPreferences prefs) throws Exception {
099:
100: prefs.setValues("header-article-resouce-values", new String[] {
101: "0", "" });
102: }
103:
104: protected void setFooterArticle(ActionRequest req,
105: PortletPreferences prefs) throws Exception {
106:
107: String footerArticleResouceId = ParamUtil.getString(req,
108: "resourceId");
109: String footerArticleResouceTitle = ParamUtil.getString(req,
110: "resourceTitle");
111:
112: prefs.setValues("footer-article-resouce-values", new String[] {
113: footerArticleResouceId, footerArticleResouceTitle });
114: }
115:
116: protected void setHeaderArticle(ActionRequest req,
117: PortletPreferences prefs) throws Exception {
118:
119: String headerArticleResouceId = ParamUtil.getString(req,
120: "resourceId");
121: String headerArticleResouceTitle = ParamUtil.getString(req,
122: "resourceTitle");
123:
124: prefs.setValues("header-article-resouce-values", new String[] {
125: headerArticleResouceId, headerArticleResouceTitle });
126: }
127:
128: protected void updateConfiguration(ActionRequest req,
129: PortletPreferences prefs) throws Exception {
130:
131: String[] urls = req.getParameterValues("url");
132: String[] titles = req.getParameterValues("title");
133: int entriesPerFeed = ParamUtil.getInteger(req,
134: "entriesPerFeed", 4);
135: boolean showFeedTitle = ParamUtil.getBoolean(req,
136: "showFeedTitle");
137: boolean showFeedPublishedDate = ParamUtil.getBoolean(req,
138: "showFeedPublishedDate");
139: boolean showFeedDescription = ParamUtil.getBoolean(req,
140: "showFeedDescription");
141: boolean showFeedImage = ParamUtil.getBoolean(req,
142: "showFeedImage");
143: String feedImageAlignment = ParamUtil.getString(req,
144: "feedImageAlignment");
145: long headerArticleResouceId = ParamUtil.getLong(req,
146: "headerArticleResouceId");
147: long footerArticleResouceId = ParamUtil.getLong(req,
148: "footerArticleResouceId");
149:
150: if (urls != null && titles != null) {
151: prefs.setValues("urls", urls);
152: prefs.setValues("titles", titles);
153: } else {
154: prefs.setValues("urls", new String[0]);
155: prefs.setValues("titles", new String[0]);
156: }
157:
158: prefs.setValue("items-per-channel", String
159: .valueOf(entriesPerFeed));
160: prefs
161: .setValue("show-feed-title", String
162: .valueOf(showFeedTitle));
163: prefs.setValue("show-feed-published-date", String
164: .valueOf(showFeedPublishedDate));
165: prefs.setValue("show-feed-description", String
166: .valueOf(showFeedDescription));
167: prefs
168: .setValue("show-feed-image", String
169: .valueOf(showFeedImage));
170: prefs.setValue("feed-image-alignment", String
171: .valueOf(feedImageAlignment));
172: prefs.setValue("header-article-resouce-id", String
173: .valueOf(headerArticleResouceId));
174: prefs.setValue("footer-article-resouce-id", String
175: .valueOf(footerArticleResouceId));
176: }
177:
178: }
|