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.StringPool;
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          return processColumn(columnId, StringPool.BLANK);
52      }
53  
54      public String processColumn(String columnId, String classNames)
55          throws Exception {
56  
57          Map<String, String> attributes = new HashMap<String, String>();
58  
59          attributes.put("id", columnId);
60          attributes.put("classNames", classNames);
61  
62          PortletColumnLogic logic = new PortletColumnLogic(
63              _servletContext, _request, _response);
64  
65          String content = logic.processContent(attributes);
66  
67          _portletsMap.putAll(logic.getPortletsMap());
68  
69          return content;
70      }
71  
72      public String processMax() throws Exception {
73          return processMax(StringPool.BLANK);
74      }
75  
76      public String processMax(String classNames) throws Exception {
77          Map<String, String> attributes = new HashMap<String, String>();
78  
79          attributes.put("classNames", classNames);
80  
81          RuntimeLogic logic = new PortletLogic(
82              _servletContext, _request, _response, _portletId);
83  
84          return logic.processContent(attributes);
85      }
86  
87      public String processPortlet(String portletId) throws Exception {
88          RuntimeLogic logic = new PortletLogic(
89              _servletContext, _request, _response, portletId);
90  
91          return logic.processContent(new HashMap<String, String>());
92      }
93  
94      public Map<Portlet, Object[]> getPortletsMap() {
95          return _portletsMap;
96      }
97  
98      private ServletContext _servletContext;
99      private HttpServletRequest _request;
100     private HttpServletResponse _response;
101     private String _portletId;
102     private Map<Portlet, Object[]> _portletsMap;
103 
104 }