1
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
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 void processXML(StringBuilder sb, 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 sb.append(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 }