001    /**
002     * Copyright (c) 2000-2011 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
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            @Override
042            public void processAction(
043                            ActionMapping mapping, ActionForm form, PortletConfig portletConfig,
044                            ActionRequest actionRequest, ActionResponse actionResponse)
045                    throws Exception {
046    
047                    String cmd = ParamUtil.getString(actionRequest, Constants.CMD);
048    
049                    if (!cmd.equals(Constants.UPDATE)) {
050                            return;
051                    }
052    
053                    PortletPreferences preferences = actionRequest.getPreferences();
054    
055                    String[] symbols = StringUtil.split(
056                            ParamUtil.getString(actionRequest, "symbols").toUpperCase());
057    
058                    preferences.setValues("symbols", symbols);
059    
060                    try {
061                            preferences.store();
062                    }
063                    catch (ValidatorException ve) {
064                            SessionErrors.add(
065                                    actionRequest, ValidatorException.class.getName(), ve);
066    
067                            return;
068                    }
069    
070                    SessionMessages.add(
071                            actionRequest, portletConfig.getPortletName() + ".doEdit");
072            }
073    
074            @Override
075            public ActionForward render(
076                            ActionMapping mapping, ActionForm form, PortletConfig portletConfig,
077                            RenderRequest renderRequest, RenderResponse renderResponse)
078                    throws Exception {
079    
080                    return mapping.findForward("portlet.currency_converter.edit");
081            }
082    
083    }