1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * The contents of this file are subject to the terms of the Liferay Enterprise
5    * Subscription License ("License"). You may not use this file except in
6    * compliance with the License. You can obtain a copy of the License by
7    * contacting Liferay, Inc. See the License for the specific language governing
8    * permissions and limitations under the License, including but not limited to
9    * distribution rights of the Software.
10   *
11   *
12   *
13   */
14  
15  package com.liferay.portlet.layoutconfiguration.util.xml;
16  
17  import com.liferay.portal.kernel.util.Validator;
18  import com.liferay.portal.kernel.xml.Document;
19  import com.liferay.portal.kernel.xml.Element;
20  import com.liferay.portal.kernel.xml.SAXReaderUtil;
21  import com.liferay.portal.model.PortletConstants;
22  import com.liferay.portlet.layoutconfiguration.util.RuntimePortletUtil;
23  
24  import javax.portlet.RenderRequest;
25  import javax.portlet.RenderResponse;
26  
27  import javax.servlet.ServletContext;
28  import javax.servlet.http.HttpServletRequest;
29  import javax.servlet.http.HttpServletResponse;
30  
31  /**
32   * <a href="PortletLogic.java.html"><b><i>View Source</i></b></a>
33   *
34   * @author Brian Wing Shun Chan
35   */
36  public class PortletLogic extends RuntimeLogic {
37  
38      public static final String OPEN_TAG = "<runtime-portlet";
39  
40      public static final String CLOSE_1_TAG = "</runtime-portlet>";
41  
42      public static final String CLOSE_2_TAG = "/>";
43  
44      public PortletLogic(
45          ServletContext servletContext, HttpServletRequest request,
46          HttpServletResponse response, RenderRequest renderRequest,
47          RenderResponse renderResponse) {
48  
49          _servletContext = servletContext;
50          _request = request;
51          _response = response;
52          _renderRequest = renderRequest;
53          _renderResponse = 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 String processXML(String xml) throws Exception {
65          Document doc = SAXReaderUtil.read(xml);
66  
67          Element root = doc.getRootElement();
68  
69          String rootPortletId = root.attributeValue("name");
70          String instanceId = root.attributeValue("instance");
71          String queryString = root.attributeValue("queryString");
72  
73          String portletId = rootPortletId;
74  
75          if (Validator.isNotNull(instanceId)) {
76              portletId += PortletConstants.INSTANCE_SEPARATOR + instanceId;
77          }
78  
79          return RuntimePortletUtil.processPortlet(
80              _servletContext, _request, _response, _renderRequest,
81              _renderResponse, portletId, queryString);
82      }
83  
84      private ServletContext _servletContext;
85      private HttpServletRequest _request;
86      private HttpServletResponse _response;
87      private RenderRequest _renderRequest;
88      private RenderResponse _renderResponse;
89  
90  }