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