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