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