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.WebKeys;
18  import com.liferay.portal.model.Portlet;
19  import com.liferay.portal.util.comparator.PortletRenderWeightComparator;
20  
21  import java.util.HashMap;
22  import java.util.Map;
23  import java.util.TreeMap;
24  
25  import javax.servlet.ServletContext;
26  import javax.servlet.http.HttpServletRequest;
27  import javax.servlet.http.HttpServletResponse;
28  
29  /**
30   * <a href="TemplateProcessor.java.html"><b><i>View Source</i></b></a>
31   *
32   * @author Ivica Cardic
33   * @author Brian Wing Shun Chan
34   * @author Shuyang Zhou
35   */
36  public class TemplateProcessor {
37  
38      public TemplateProcessor(
39          ServletContext servletContext, HttpServletRequest request,
40          HttpServletResponse response, String portletId) {
41  
42          _servletContext = servletContext;
43          _request = request;
44          _response = response;
45          _portletId = portletId;
46          _portletsMap = new TreeMap<Portlet, Object[]>(
47              new PortletRenderWeightComparator());
48      }
49  
50      public String processColumn(String columnId) throws Exception {
51          Map<String, String> attributes = new HashMap<String, String>();
52  
53          attributes.put("id", columnId);
54  
55          PortletColumnLogic logic = new PortletColumnLogic(
56              _servletContext, _request, _response);
57  
58          String content = logic.processContent(attributes);
59  
60          _portletsMap.putAll(logic.getPortletsMap());
61  
62          return content;
63      }
64  
65      public String processMax() throws Exception {
66          RuntimeLogic logic = new PortletLogic(
67              _servletContext, _request, _response, _portletId);
68  
69          return logic.processContent(new HashMap<String, String>());
70      }
71  
72      public String processPortlet(String portletId) throws Exception {
73          try {
74              _request.setAttribute(
75                  WebKeys.RENDER_PORTLET_RESOURCE, Boolean.TRUE);
76  
77              RuntimeLogic logic = new PortletLogic(
78                  _servletContext, _request, _response, portletId);
79  
80              return logic.processContent(new HashMap<String, String>());
81          }
82          finally {
83              _request.removeAttribute(WebKeys.RENDER_PORTLET_RESOURCE);
84          }
85      }
86  
87      public Map<Portlet, Object[]> getPortletsMap() {
88          return _portletsMap;
89      }
90  
91      private ServletContext _servletContext;
92      private HttpServletRequest _request;
93      private HttpServletResponse _response;
94      private String _portletId;
95      private Map<Portlet, Object[]> _portletsMap;
96  
97  }