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.portal.apache.bridges.struts;
016    
017    import com.liferay.portal.kernel.log.Log;
018    import com.liferay.portal.kernel.log.LogFactoryUtil;
019    import com.liferay.portal.kernel.util.HttpUtil;
020    import com.liferay.portlet.PortletResponseImpl;
021    import com.liferay.portlet.PortletURLImplWrapper;
022    
023    import org.apache.portals.bridges.struts.StrutsPortletURL;
024    
025    /**
026     * @author Michael Young
027     */
028    public class LiferayStrutsPortletURLImpl extends PortletURLImplWrapper {
029    
030            public LiferayStrutsPortletURLImpl(
031                    PortletResponseImpl portletResponseImpl, long plid, String lifecycle) {
032    
033                    super(portletResponseImpl, plid, lifecycle);
034            }
035    
036            public void setParameter(String name, String value) {
037                    super.setParameter(name, value);
038    
039                    // Add parameters from the query string because bridges passes these
040                    // through instead of setting them on the portlet URL
041    
042                    String decodedValue = HttpUtil.decodeURL(value);
043    
044                    try {
045                            if (name.equals(StrutsPortletURL.PAGE)) {
046                                    String[] urlComponents = decodedValue.split("\\?", 2);
047    
048                                    if (urlComponents.length != 2) {
049                                            return;
050                                    }
051    
052                                    String[] nameValue = urlComponents[1].split("\\&");
053    
054                                    for (int i = 0; i < nameValue.length; i++) {
055                                            String[] nameValuePair = nameValue[i].split("\\=", 2);
056    
057                                            if (nameValuePair.length == 2) {
058                                                    super.setParameter(nameValuePair[0], nameValuePair[1]);
059                                            }
060                                            else if (nameValuePair.length == 1) {
061                                                    super.setParameter(nameValuePair[0], "true");
062                                            }
063                                    }
064                            }
065                    }
066                    catch (Throwable t) {
067                            _log.error("Could not parse Struts page query string " + value, t);
068                    }
069            }
070    
071            private static Log _log = LogFactoryUtil.getLog(
072                    LiferayStrutsPortletURLImpl.class);
073    
074    }