001
014
015 package com.liferay.portlet.layoutconfiguration.util.xml;
016
017 import com.liferay.portal.kernel.util.Validator;
018 import com.liferay.portal.kernel.xml.Document;
019 import com.liferay.portal.kernel.xml.Element;
020 import com.liferay.portal.kernel.xml.SAXReaderUtil;
021 import com.liferay.portal.model.PortletConstants;
022 import com.liferay.portlet.layoutconfiguration.util.RuntimePortletUtil;
023
024 import javax.portlet.RenderRequest;
025 import javax.portlet.RenderResponse;
026
027 import javax.servlet.ServletContext;
028 import javax.servlet.http.HttpServletRequest;
029 import javax.servlet.http.HttpServletResponse;
030
031
035 public class PortletLogic extends RuntimeLogic {
036
037 public static final String CLOSE_1_TAG = "</runtime-portlet>";
038
039 public static final String CLOSE_2_TAG = "/>";
040
041 public static final String OPEN_TAG = "<runtime-portlet";
042
043 public PortletLogic(
044 ServletContext servletContext, HttpServletRequest request,
045 HttpServletResponse response, RenderRequest renderRequest,
046 RenderResponse renderResponse) {
047
048 _servletContext = servletContext;
049 _request = request;
050 _response = response;
051 _renderRequest = renderRequest;
052 _renderResponse = renderResponse;
053 }
054
055 @Override
056 public String getClose1Tag() {
057 return CLOSE_1_TAG;
058 }
059
060 @Override
061 public String getOpenTag() {
062 return OPEN_TAG;
063 }
064
065 @Override
066 public String processXML(String xml) throws Exception {
067 Document doc = SAXReaderUtil.read(xml);
068
069 Element root = doc.getRootElement();
070
071 String rootPortletId = root.attributeValue("name");
072 String instanceId = root.attributeValue("instance");
073 String queryString = root.attributeValue("queryString");
074
075 String portletId = rootPortletId;
076
077 if (Validator.isNotNull(instanceId)) {
078 portletId += PortletConstants.INSTANCE_SEPARATOR + instanceId;
079 }
080
081 return RuntimePortletUtil.processPortlet(
082 _servletContext, _request, _response, _renderRequest,
083 _renderResponse, portletId, queryString, false);
084 }
085
086 private RenderRequest _renderRequest;
087 private RenderResponse _renderResponse;
088 private HttpServletRequest _request;
089 private HttpServletResponse _response;
090 private ServletContext _servletContext;
091
092 }