1   /**
2    * Copyright (c) 2000-2009 Liferay, Inc. All rights reserved.
3    *
4    * The contents of this file are subject to the terms of the Liferay Enterprise
5    * Subscription License ("License"). You may not use this file except in
6    * compliance with the License. You can obtain a copy of the License by
7    * contacting Liferay, Inc. See the License for the specific language governing
8    * permissions and limitations under the License, including but not limited to
9    * distribution rights of the Software.
10   *
11   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
12   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
13   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
14   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
15   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
16   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
17   * SOFTWARE.
18   */
19  
20  package com.liferay.portal.struts;
21  
22  import com.liferay.portal.kernel.util.StringPool;
23  import com.liferay.portal.model.Portlet;
24  import com.liferay.portlet.PortletResponseImpl;
25  import com.liferay.portlet.PortletURLImplWrapper;
26  
27  import java.util.Map;
28  
29  /**
30   * <a href="StrutsActionPortletURL.java.html"><b><i>View Source</i></b></a>
31   *
32   * @author Brian Wing Shun Chan
33   *
34   */
35  public class StrutsActionPortletURL extends PortletURLImplWrapper {
36  
37      public StrutsActionPortletURL(
38          PortletResponseImpl portletResponseImpl, long plid, String lifecycle) {
39  
40          super(portletResponseImpl, plid, lifecycle);
41  
42          _portlet = portletResponseImpl.getPortlet();
43          _strutsPath =
44              StringPool.SLASH + _portlet.getStrutsPath() + StringPool.SLASH;
45      }
46  
47      public void setParameter(String name, String value) {
48          if (name.equals("struts_action")) {
49              if (!value.startsWith(_strutsPath)) {
50                  int pos = value.lastIndexOf(StringPool.SLASH);
51  
52                  value = _strutsPath + value.substring(pos + 1, value.length());
53              }
54          }
55  
56          super.setParameter(name, value);
57      }
58  
59      public void setParameters(Map<String, String[]> params) {
60          for (Map.Entry<String, String[]> entry : params.entrySet()) {
61              String name = entry.getKey();
62              String[] values = entry.getValue();
63  
64              if (name.equals("struts_action")) {
65                  for (int i = 0; i < values.length; i++) {
66                      String value = values[i];
67  
68                      if (!value.startsWith(_strutsPath)) {
69                          int pos = value.lastIndexOf(StringPool.SLASH);
70  
71                          value =
72                              _strutsPath +
73                                  value.substring(pos + 1, value.length());
74  
75                          values[i] = value;
76                      }
77                  }
78              }
79          }
80  
81          super.setParameters(params);
82      }
83  
84      private Portlet _portlet;
85      private String _strutsPath;
86  
87  }