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.portal.model.Layout;
19  import com.liferay.taglib.util.IncludeTag;
20  
21  import javax.portlet.PortletURL;
22  
23  import javax.servlet.RequestDispatcher;
24  import javax.servlet.ServletContext;
25  import javax.servlet.http.HttpServletRequest;
26  import javax.servlet.http.HttpServletResponse;
27  import javax.servlet.jsp.JspException;
28  
29  /**
30   * <a href="BreadcrumbTag.java.html"><b><i>View Source</i></b></a>
31   *
32   * @author Brian Wing Shun Chan
33   */
34  public class BreadcrumbTag extends IncludeTag {
35  
36      public static void doTag(
37              ServletContext servletContext, HttpServletRequest request,
38              HttpServletResponse response)
39          throws Exception {
40  
41          doTag(
42              _PAGE, null, null, null, _DISPLAY_STYLE, servletContext, request,
43              response);
44      }
45  
46      public static void doTag(
47              String page, Layout selLayout, String selLayoutParam,
48              PortletURL portletURL, int displayStyle,
49              ServletContext servletContext, HttpServletRequest request,
50              HttpServletResponse response)
51          throws Exception {
52  
53          request.setAttribute(
54              "liferay-ui:breadcrumb:displayStyle", String.valueOf(displayStyle));
55          request.setAttribute("liferay-ui:breadcrumb:selLayout", selLayout);
56          request.setAttribute(
57              "liferay-ui:breadcrumb:selLayoutParam", selLayoutParam);
58          request.setAttribute("liferay-ui:breadcrumb:portletURL", portletURL);
59  
60          RequestDispatcher requestDispatcher =
61              servletContext.getRequestDispatcher(page);
62  
63          requestDispatcher.include(request, response);
64      }
65  
66      public int doEndTag() throws JspException {
67          try {
68              ServletContext servletContext = getServletContext();
69              HttpServletRequest request = getServletRequest();
70              StringServletResponse stringResponse = getServletResponse();
71  
72              doTag(
73                  getPage(), _selLayout, _selLayoutParam, _portletURL,
74                  _displayStyle, servletContext, request, stringResponse);
75  
76              pageContext.getOut().print(stringResponse.getString());
77  
78              return EVAL_PAGE;
79          }
80          catch (Exception e) {
81              throw new JspException(e);
82          }
83      }
84  
85      public void setDisplayStyle(int displayStyle) {
86          _displayStyle = displayStyle;
87      }
88  
89      public void setPortletURL(PortletURL portletURL) {
90          _portletURL = portletURL;
91      }
92  
93      public void setSelLayout(Layout selLayout) {
94          _selLayout = selLayout;
95      }
96  
97      public void setSelLayoutParam(String selLayoutParam) {
98          _selLayoutParam = selLayoutParam;
99      }
100 
101     protected String getDefaultPage() {
102         return _PAGE;
103     }
104 
105     private static final int _DISPLAY_STYLE = 0;
106 
107     private static final String _PAGE = "/html/taglib/ui/breadcrumb/page.jsp";
108 
109     private int _displayStyle = _DISPLAY_STYLE;
110     private PortletURL _portletURL;
111     private Layout _selLayout;
112     private String _selLayoutParam;
113 
114 }