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