1
19
20 package com.liferay.portlet.layoutconfiguration.util.xml;
21
22 import com.liferay.portal.kernel.portlet.LiferayPortletURL;
23 import com.liferay.portal.kernel.xml.Document;
24 import com.liferay.portal.kernel.xml.Element;
25 import com.liferay.portal.kernel.xml.SAXReaderUtil;
26 import com.liferay.portal.util.PortalUtil;
27 import com.liferay.portlet.RenderResponseImpl;
28
29 import javax.portlet.PortletRequest;
30 import javax.portlet.RenderResponse;
31
32
38 public class ActionURLLogic extends RuntimeLogic {
39
40 public static final String OPEN_TAG = "<runtime-action-url";
41
42 public static final String CLOSE_1_TAG = "</runtime-action-url>";
43
44 public static final String CLOSE_2_TAG = "/>";
45
46 public ActionURLLogic(RenderResponse renderResponse) {
47 _renderResponseImpl = (RenderResponseImpl)renderResponse;
48 }
49
50 public String getOpenTag() {
51 return OPEN_TAG;
52 }
53
54 public String getClose1Tag() {
55 return CLOSE_1_TAG;
56 }
57
58 public void processXML(StringBuilder sb, String xml) throws Exception {
59 Document doc = SAXReaderUtil.read(xml);
60
61 Element root = doc.getRootElement();
62
63 LiferayPortletURL portletURL = _renderResponseImpl.createPortletURLImpl(
64 getLifecycle());
65
66 String portletId = root.attributeValue("portlet-name");
67
68 if (portletId != null) {
69 portletId = PortalUtil.getJsSafePortletId(portletId);
70
71 portletURL.setPortletId(portletId);
72 }
73
74 for (int i = 1;; i++) {
75 String paramName = root.attributeValue("param-name-" + i);
76 String paramValue = root.attributeValue("param-value-" + i);
77
78 if ((paramName == null) || (paramValue == null)) {
79 break;
80 }
81
82 portletURL.setParameter(paramName, paramValue);
83 }
84
85 sb.append(portletURL.toString());
86 }
87
88 public String getLifecycle() {
89 return _lifecycle;
90 }
91
92 private RenderResponseImpl _renderResponseImpl;
93 private String _lifecycle = PortletRequest.ACTION_PHASE;
94
95 }