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.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 res) {
53 _res = (RenderResponseImpl)res;
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(StringMaker sm, 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 =
72 (LiferayPortletURL)_res.createPortletURL(isAction());
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 sm.append(portletURL.toString());
94 }
95
96 public boolean isAction() {
97 return _action;
98 }
99
100 private RenderResponseImpl _res;
101 private boolean _action = false;
102
103 }