001    /**
002     * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portlet.currencyconverter.action;
016    
017    import com.liferay.portal.kernel.servlet.SessionErrors;
018    import com.liferay.portal.kernel.servlet.SessionMessages;
019    import com.liferay.portal.kernel.util.Constants;
020    import com.liferay.portal.kernel.util.ParamUtil;
021    import com.liferay.portal.kernel.util.StringUtil;
022    import com.liferay.portal.struts.PortletAction;
023    
024    import javax.portlet.ActionRequest;
025    import javax.portlet.ActionResponse;
026    import javax.portlet.PortletConfig;
027    import javax.portlet.PortletPreferences;
028    import javax.portlet.RenderRequest;
029    import javax.portlet.RenderResponse;
030    import javax.portlet.ValidatorException;
031    
032    import org.apache.struts.action.ActionForm;
033    import org.apache.struts.action.ActionForward;
034    import org.apache.struts.action.ActionMapping;
035    
036    /**
037     * @author Brian Wing Shun Chan
038     */
039    public class EditPreferencesAction extends PortletAction {
040    
041            public void processAction(
042                            ActionMapping mapping, ActionForm form, PortletConfig portletConfig,
043                            ActionRequest actionRequest, ActionResponse actionResponse)
044                    throws Exception {
045    
046                    String cmd = ParamUtil.getString(actionRequest, Constants.CMD);
047    
048                    if (!cmd.equals(Constants.UPDATE)) {
049                            return;
050                    }
051    
052                    PortletPreferences preferences = actionRequest.getPreferences();
053    
054                    String[] symbols = StringUtil.split(
055                            ParamUtil.getString(actionRequest, "symbols").toUpperCase());
056    
057                    preferences.setValues("symbols", symbols);
058    
059                    try {
060                            preferences.store();
061                    }
062                    catch (ValidatorException ve) {
063                            SessionErrors.add(
064                                    actionRequest, ValidatorException.class.getName(), ve);
065    
066                            return;
067                    }
068    
069                    SessionMessages.add(
070                            actionRequest, portletConfig.getPortletName() + ".doEdit");
071            }
072    
073            public ActionForward render(
074                            ActionMapping mapping, ActionForm form, PortletConfig portletConfig,
075                            RenderRequest renderRequest, RenderResponse renderResponse)
076                    throws Exception {
077    
078                    return mapping.findForward("portlet.currency_converter.edit");
079            }
080    
081    }