001    /**
002     * Copyright (c) 2000-2011 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.xslcontent.action;
016    
017    import com.liferay.portal.kernel.portlet.BaseConfigurationAction;
018    import com.liferay.portal.kernel.servlet.SessionErrors;
019    import com.liferay.portal.kernel.servlet.SessionMessages;
020    import com.liferay.portal.kernel.util.Constants;
021    import com.liferay.portal.kernel.util.ParamUtil;
022    import com.liferay.portlet.PortletPreferencesFactoryUtil;
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    
031    /**
032     * @author Brian Wing Shun Chan
033     * @author Hugo Huijser
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                    String xmlURL = ParamUtil.getString(actionRequest, "xmlURL");
049                    String xslURL = ParamUtil.getString(actionRequest, "xslURL");
050    
051                    if (xmlURL.startsWith("file:/")) {
052                            SessionErrors.add(actionRequest, "xmlURL");
053                    }
054                    else if (xslURL.startsWith("file:/")) {
055                            SessionErrors.add(actionRequest, "xslURL");
056                    }
057                    else {
058                            String portletResource = ParamUtil.getString(
059                                    actionRequest, "portletResource");
060    
061                            PortletPreferences preferences =
062                                    PortletPreferencesFactoryUtil.getPortletSetup(
063                                            actionRequest, portletResource);
064    
065                            preferences.setValue("xml-url", xmlURL);
066                            preferences.setValue("xsl-url", xslURL);
067    
068                            preferences.store();
069    
070                            SessionMessages.add(
071                                    actionRequest, portletConfig.getPortletName() + ".doConfigure");
072                    }
073            }
074    
075            public String render(
076                            PortletConfig portletConfig, RenderRequest renderRequest,
077                            RenderResponse renderResponse)
078                    throws Exception {
079    
080                    return "/html/portlet/xsl_content/configuration.jsp";
081            }
082    
083    }