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.calendar.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.portal.kernel.util.Validator;
027: import com.liferay.portlet.PortletPreferencesFactoryUtil;
028: import com.liferay.util.servlet.SessionErrors;
029: import com.liferay.util.servlet.SessionMessages;
030:
031: import javax.portlet.ActionRequest;
032: import javax.portlet.ActionResponse;
033: import javax.portlet.PortletConfig;
034: import javax.portlet.PortletPreferences;
035: import javax.portlet.RenderRequest;
036: import javax.portlet.RenderResponse;
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: if (!cmd.equals(Constants.UPDATE)) {
052: return;
053: }
054:
055: String portletResource = ParamUtil.getString(req,
056: "portletResource");
057:
058: PortletPreferences prefs = PortletPreferencesFactoryUtil
059: .getPortletSetup(req, portletResource, false, true);
060:
061: String tabs2 = ParamUtil.getString(req, "tabs2");
062:
063: if (tabs2.equals("email-from")) {
064: updateEmailFrom(req, prefs);
065: } else if (tabs2.equals("event-reminder-email")) {
066: updateEmailEventReminder(req, prefs);
067: }
068:
069: if (SessionErrors.isEmpty(req)) {
070: prefs.store();
071:
072: SessionMessages.add(req, config.getPortletName()
073: + ".doConfigure");
074: }
075: }
076:
077: public String render(PortletConfig config, RenderRequest req,
078: RenderResponse res) throws Exception {
079:
080: return "/html/portlet/calendar/configuration.jsp";
081: }
082:
083: protected void updateEmailFrom(ActionRequest req,
084: PortletPreferences prefs) throws Exception {
085:
086: String emailFromName = ParamUtil
087: .getString(req, "emailFromName");
088: String emailFromAddress = ParamUtil.getString(req,
089: "emailFromAddress");
090:
091: if (Validator.isNull(emailFromName)) {
092: SessionErrors.add(req, "emailFromName");
093: } else if (!Validator.isEmailAddress(emailFromAddress)) {
094: SessionErrors.add(req, "emailFromAddress");
095: } else {
096: prefs.setValue("email-from-name", emailFromName);
097: prefs.setValue("email-from-address", emailFromAddress);
098: }
099: }
100:
101: protected void updateEmailEventReminder(ActionRequest req,
102: PortletPreferences prefs) throws Exception {
103:
104: String emailEventReminderEnabled = ParamUtil.getString(req,
105: "emailEventReminderEnabled");
106: String emailEventReminderSubject = ParamUtil.getString(req,
107: "emailEventReminderSubject");
108: String emailEventReminderBody = ParamUtil.getString(req,
109: "emailEventReminderBody");
110:
111: if (Validator.isNull(emailEventReminderSubject)) {
112: SessionErrors.add(req, "emailEventReminderSubject");
113: } else if (Validator.isNull(emailEventReminderBody)) {
114: SessionErrors.add(req, "emailEventReminderBody");
115: } else {
116: prefs.setValue("email-event-reminder-enabled",
117: emailEventReminderEnabled);
118: prefs.setValue("email-event-reminder-subject",
119: emailEventReminderSubject);
120: prefs.setValue("email-event-reminder-body",
121: emailEventReminderBody);
122: }
123: }
124:
125: }
|