1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * This library is free software; you can redistribute it and/or modify it under
5    * the terms of the GNU Lesser General Public License as published by the Free
6    * Software Foundation; either version 2.1 of the License, or (at your option)
7    * any later version.
8    *
9    * This library is distributed in the hope that it will be useful, but WITHOUT
10   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11   * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12   * details.
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 void processXML(StringBuilder sb, 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          RuntimePortletUtil.processPortlet(
80              sb, _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  }