001    /**
002     * Copyright (c) 2000-2010 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.assetcategoriesnavigation.action;
016    
017    import com.liferay.portal.kernel.portlet.BaseConfigurationAction;
018    import com.liferay.portal.kernel.servlet.SessionMessages;
019    import com.liferay.portal.kernel.util.ArrayUtil;
020    import com.liferay.portal.kernel.util.Constants;
021    import com.liferay.portal.kernel.util.ParamUtil;
022    import com.liferay.portal.kernel.util.StringUtil;
023    import com.liferay.portlet.PortletPreferencesFactoryUtil;
024    
025    import javax.portlet.ActionRequest;
026    import javax.portlet.ActionResponse;
027    import javax.portlet.PortletConfig;
028    import javax.portlet.PortletPreferences;
029    import javax.portlet.RenderRequest;
030    import javax.portlet.RenderResponse;
031    
032    /**
033     * @author Jorge Ferrer
034     */
035    public class ConfigurationActionImpl extends BaseConfigurationAction {
036    
037            public void processAction(
038                            PortletConfig portletConfig, ActionRequest actionRequest,
039                            ActionResponse actionResponse)
040                    throws Exception {
041    
042                    String cmd = ParamUtil.getString(actionRequest, Constants.CMD);
043    
044                    if (!cmd.equals(Constants.UPDATE)) {
045                            return;
046                    }
047    
048                    boolean allAssetVocabularies = ParamUtil.getBoolean(
049                            actionRequest, "allAssetVocabularies");
050                    long[] assetVocabularyIds = StringUtil.split(
051                            ParamUtil.getString(actionRequest, "assetVocabularyIds"), 0L);
052    
053                    String portletResource = ParamUtil.getString(
054                            actionRequest, "portletResource");
055    
056                    PortletPreferences preferences =
057                            PortletPreferencesFactoryUtil.getPortletSetup(
058                                    actionRequest, portletResource);
059    
060                    preferences.setValue(
061                            "all-asset-vocabularies", String.valueOf(allAssetVocabularies));
062                    preferences.setValues(
063                            "asset-vocabulary-ids",
064                            ArrayUtil.toStringArray(assetVocabularyIds));
065    
066                    preferences.store();
067    
068                    SessionMessages.add(
069                            actionRequest, portletConfig.getPortletName() + ".doConfigure");
070            }
071    
072            public String render(
073                            PortletConfig portletConfig, RenderRequest renderRequest,
074                            RenderResponse renderResponse)
075                    throws Exception {
076    
077                    return "/html/portlet/asset_categories_navigation/configuration.jsp";
078            }
079    
080    }