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.velocity;
16  
17  import com.liferay.portal.kernel.util.Validator;
18  import com.liferay.portal.model.PortletConstants;
19  import com.liferay.portlet.layoutconfiguration.util.RuntimePortletUtil;
20  
21  import java.util.Map;
22  
23  import javax.portlet.RenderRequest;
24  import javax.portlet.RenderResponse;
25  
26  import javax.servlet.ServletContext;
27  import javax.servlet.http.HttpServletRequest;
28  import javax.servlet.http.HttpServletResponse;
29  
30  /**
31   * <a href="PortletLogic.java.html"><b><i>View Source</i></b></a>
32   *
33   * @author Ivica Cardic
34   * @author Brian Wing Shun Chan
35   */
36  public class PortletLogic extends RuntimeLogic {
37  
38      public PortletLogic(
39          ServletContext servletContext, HttpServletRequest request,
40          HttpServletResponse response, String portletId) {
41  
42          this(servletContext, request, response, null, null);
43  
44          _portletId = portletId;
45      }
46  
47      public PortletLogic(
48          ServletContext servletContext, HttpServletRequest request,
49          HttpServletResponse response, RenderRequest renderRequest,
50          RenderResponse renderResponse) {
51  
52          _servletContext = servletContext;
53          _request = request;
54          _response = response;
55          _renderRequest = renderRequest;
56          _renderResponse = renderResponse;
57      }
58  
59      public String processContent(Map<String, String> attributes)
60          throws Exception {
61  
62          String rootPortletId = attributes.get("name");
63          String instanceId = attributes.get("instance");
64          String queryString = attributes.get("queryString");
65  
66          String portletId = _portletId;
67  
68          if (portletId == null) {
69              portletId = rootPortletId;
70  
71              if (Validator.isNotNull(instanceId)) {
72                  portletId += PortletConstants.INSTANCE_SEPARATOR + instanceId;
73              }
74          }
75  
76          return RuntimePortletUtil.processPortlet(
77              _servletContext, _request, _response, _renderRequest,
78              _renderResponse, portletId, queryString);
79      }
80  
81      private ServletContext _servletContext;
82      private HttpServletRequest _request;
83      private HttpServletResponse _response;
84      private RenderRequest _renderRequest;
85      private RenderResponse _renderResponse;
86      private String _portletId;
87  
88  }