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.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 void processContent(StringBuilder sb, 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          RuntimePortletUtil.processPortlet(
77              sb, _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  }