1   /**
2    * Copyright (c) 2000-2010 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   *
12   *
13   */
14  
15  package com.liferay.portlet.layoutconfiguration.util.xml;
16  
17  import com.liferay.portal.kernel.portlet.LiferayPortletURL;
18  import com.liferay.portal.kernel.xml.Document;
19  import com.liferay.portal.kernel.xml.Element;
20  import com.liferay.portal.kernel.xml.SAXReaderUtil;
21  import com.liferay.portal.util.PortalUtil;
22  import com.liferay.portlet.RenderResponseImpl;
23  
24  import javax.portlet.PortletRequest;
25  import javax.portlet.RenderResponse;
26  
27  /**
28   * <a href="ActionURLLogic.java.html"><b><i>View Source</i></b></a>
29   *
30   * @author Brian Wing Shun Chan
31   */
32  public class ActionURLLogic extends RuntimeLogic {
33  
34      public static final String OPEN_TAG = "<runtime-action-url";
35  
36      public static final String CLOSE_1_TAG = "</runtime-action-url>";
37  
38      public static final String CLOSE_2_TAG = "/>";
39  
40      public ActionURLLogic(RenderResponse renderResponse) {
41          _renderResponseImpl = (RenderResponseImpl)renderResponse;
42      }
43  
44      public String getOpenTag() {
45          return OPEN_TAG;
46      }
47  
48      public String getClose1Tag() {
49          return CLOSE_1_TAG;
50      }
51  
52      public String processXML(String xml) throws Exception {
53          Document doc = SAXReaderUtil.read(xml);
54  
55          Element root = doc.getRootElement();
56  
57          LiferayPortletURL portletURL =
58              _renderResponseImpl.createLiferayPortletURL(getLifecycle());
59  
60          String portletId = root.attributeValue("portlet-name");
61  
62          if (portletId != null) {
63              portletId = PortalUtil.getJsSafePortletId(portletId);
64  
65              portletURL.setPortletId(portletId);
66          }
67  
68          for (int i = 1;; i++) {
69              String paramName = root.attributeValue("param-name-" + i);
70              String paramValue = root.attributeValue("param-value-" + i);
71  
72              if ((paramName == null) || (paramValue == null)) {
73                  break;
74              }
75  
76              portletURL.setParameter(paramName, paramValue);
77          }
78  
79          return portletURL.toString();
80      }
81  
82      public String getLifecycle() {
83          return _lifecycle;
84      }
85  
86      private RenderResponseImpl _renderResponseImpl;
87      private String _lifecycle = PortletRequest.ACTION_PHASE;
88  
89  }