1   /**
2    * Copyright (c) 2000-2009 Liferay, Inc. All rights reserved.
3    *
4    *
5    *
6    *
7    * The contents of this file are subject to the terms of the Liferay Enterprise
8    * Subscription License ("License"). You may not use this file except in
9    * compliance with the License. You can obtain a copy of the License by
10   * contacting Liferay, Inc. See the License for the specific language governing
11   * permissions and limitations under the License, including but not limited to
12   * distribution rights of the Software.
13   *
14   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20   * SOFTWARE.
21   */
22  
23  package com.liferay.portlet.layoutconfiguration.util.velocity;
24  
25  import com.liferay.portal.kernel.util.Validator;
26  import com.liferay.portal.model.PortletConstants;
27  import com.liferay.portlet.layoutconfiguration.util.RuntimePortletUtil;
28  
29  import java.util.Map;
30  
31  import javax.portlet.RenderRequest;
32  import javax.portlet.RenderResponse;
33  
34  import javax.servlet.ServletContext;
35  import javax.servlet.http.HttpServletRequest;
36  import javax.servlet.http.HttpServletResponse;
37  
38  /**
39   * <a href="PortletLogic.java.html"><b><i>View Source</i></b></a>
40   *
41   * @author Ivica Cardic
42   * @author Brian Wing Shun Chan
43   */
44  public class PortletLogic extends RuntimeLogic {
45  
46      public PortletLogic(
47          ServletContext servletContext, HttpServletRequest request,
48          HttpServletResponse response, String portletId) {
49  
50          this(servletContext, request, response, null, null);
51  
52          _portletId = portletId;
53      }
54  
55      public PortletLogic(
56          ServletContext servletContext, HttpServletRequest request,
57          HttpServletResponse response, RenderRequest renderRequest,
58          RenderResponse renderResponse) {
59  
60          _servletContext = servletContext;
61          _request = request;
62          _response = response;
63          _renderRequest = renderRequest;
64          _renderResponse = renderResponse;
65      }
66  
67      public void processContent(StringBuilder sb, Map<String, String> attributes)
68          throws Exception {
69  
70          String rootPortletId = attributes.get("name");
71          String instanceId = attributes.get("instance");
72          String queryString = attributes.get("queryString");
73  
74          String portletId = _portletId;
75  
76          if (portletId == null) {
77              portletId = rootPortletId;
78  
79              if (Validator.isNotNull(instanceId)) {
80                  portletId += PortletConstants.INSTANCE_SEPARATOR + instanceId;
81              }
82          }
83  
84          RuntimePortletUtil.processPortlet(
85              sb, _servletContext, _request, _response, _renderRequest,
86              _renderResponse, portletId, queryString);
87      }
88  
89      private ServletContext _servletContext;
90      private HttpServletRequest _request;
91      private HttpServletResponse _response;
92      private RenderRequest _renderRequest;
93      private RenderResponse _renderResponse;
94      private String _portletId;
95  
96  }