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.taglib.ui;
16  
17  import com.liferay.portal.kernel.servlet.StringServletResponse;
18  import com.liferay.taglib.util.IncludeTag;
19  
20  import javax.servlet.RequestDispatcher;
21  import javax.servlet.ServletContext;
22  import javax.servlet.http.HttpServletRequest;
23  import javax.servlet.http.HttpServletResponse;
24  import javax.servlet.jsp.JspException;
25  
26  /**
27   * <a href="MyPlacesTag.java.html"><b><i>View Source</i></b></a>
28   *
29   * @author Brian Wing Shun Chan
30   */
31  public class MyPlacesTag extends IncludeTag {
32  
33      public static void doTag(
34              ServletContext servletContext, HttpServletRequest request,
35              HttpServletResponse response)
36          throws Exception {
37  
38          doTag(_PAGE, _MAX, servletContext, request, response);
39      }
40  
41      public static void doTag(
42              int max, ServletContext servletContext, HttpServletRequest request,
43              HttpServletResponse response)
44          throws Exception {
45  
46          doTag(_PAGE, max, servletContext, request, response);
47      }
48  
49      public static void doTag(
50              String page, int max, ServletContext servletContext,
51              HttpServletRequest request, HttpServletResponse response)
52          throws Exception {
53  
54          request.setAttribute("liferay-ui:my_places:max", String.valueOf(max));
55  
56          RequestDispatcher requestDispatcher =
57              servletContext.getRequestDispatcher(page);
58  
59          requestDispatcher.include(request, response);
60      }
61  
62      public int doEndTag() throws JspException {
63          try {
64              ServletContext servletContext = getServletContext();
65              HttpServletRequest request = getServletRequest();
66              StringServletResponse stringResponse = getServletResponse();
67  
68              doTag(getPage(), _max, servletContext, request, stringResponse);
69  
70              pageContext.getOut().print(stringResponse.getString());
71  
72              return EVAL_PAGE;
73          }
74          catch (Exception e) {
75              throw new JspException(e);
76          }
77      }
78  
79      public void setMax(int max) {
80          _max = max;
81      }
82  
83      protected String getDefaultPage() {
84          return _PAGE;
85      }
86  
87      private static final String _PAGE = "/html/taglib/ui/my_places/page.jsp";
88  
89      private static final int _MAX = 0;
90  
91      private int _max = _MAX;
92  
93  }