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