001
014
015 package com.liferay.portal.layoutconfiguration.util.xml;
016
017 import com.liferay.portal.kernel.layoutconfiguration.util.xml.RuntimeLogic;
018 import com.liferay.portal.kernel.portlet.LiferayPortletURL;
019 import com.liferay.portal.kernel.util.PortalUtil;
020 import com.liferay.portal.kernel.xml.Document;
021 import com.liferay.portal.kernel.xml.Element;
022 import com.liferay.portal.kernel.xml.SAXReaderUtil;
023 import com.liferay.portlet.RenderResponseImpl;
024
025 import javax.portlet.PortletRequest;
026 import javax.portlet.RenderResponse;
027
028
031 public class ActionURLLogic extends RuntimeLogic {
032
033 public static final String CLOSE_1_TAG = "</runtime-action-url>";
034
035 public static final String CLOSE_2_TAG = "/>";
036
037 public static final String OPEN_TAG = "<runtime-action-url";
038
039 public ActionURLLogic(RenderResponse renderResponse) {
040 _renderResponseImpl = (RenderResponseImpl)renderResponse;
041 }
042
043 @Override
044 public String getClose1Tag() {
045 return CLOSE_1_TAG;
046 }
047
048 public String getLifecycle() {
049 return _LIFECYCLE;
050 }
051
052 @Override
053 public String getOpenTag() {
054 return OPEN_TAG;
055 }
056
057 @Override
058 public String processXML(String xml) throws Exception {
059 Document doc = SAXReaderUtil.read(xml);
060
061 Element root = doc.getRootElement();
062
063 LiferayPortletURL liferayPortletURL =
064 _renderResponseImpl.createLiferayPortletURL(getLifecycle());
065
066 String portletId = root.attributeValue("portlet-name");
067
068 if (portletId != null) {
069 portletId = PortalUtil.getJsSafePortletId(portletId);
070
071 liferayPortletURL.setPortletId(portletId);
072 }
073
074 for (int i = 1;; i++) {
075 String paramName = root.attributeValue("param-name-" + i);
076 String paramValue = root.attributeValue("param-value-" + i);
077
078 if ((paramName == null) || (paramValue == null)) {
079 break;
080 }
081
082 liferayPortletURL.setParameter(paramName, paramValue);
083 }
084
085 return liferayPortletURL.toString();
086 }
087
088 private static final String _LIFECYCLE = PortletRequest.ACTION_PHASE;
089
090 private final RenderResponseImpl _renderResponseImpl;
091
092 }