1   /**
2    * Copyright (c) 2000-2009 Liferay, Inc. All rights reserved.
3    *
4    * Permission is hereby granted, free of charge, to any person obtaining a copy
5    * of this software and associated documentation files (the "Software"), to deal
6    * in the Software without restriction, including without limitation the rights
7    * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8    * copies of the Software, and to permit persons to whom the Software is
9    * furnished to do so, subject to the following conditions:
10   *
11   * The above copyright notice and this permission notice shall be included in
12   * all copies or substantial portions of the Software.
13   *
14   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20   * SOFTWARE.
21   */
22  
23  package com.liferay.taglib.ui;
24  
25  import com.liferay.portal.kernel.servlet.StringServletResponse;
26  import com.liferay.portal.model.Layout;
27  import com.liferay.taglib.util.IncludeTag;
28  
29  import java.io.IOException;
30  
31  import javax.portlet.PortletURL;
32  
33  import javax.servlet.RequestDispatcher;
34  import javax.servlet.ServletContext;
35  import javax.servlet.ServletException;
36  import javax.servlet.http.HttpServletRequest;
37  import javax.servlet.http.HttpServletResponse;
38  import javax.servlet.jsp.JspException;
39  
40  /**
41   * <a href="BreadcrumbTag.java.html"><b><i>View Source</i></b></a>
42   *
43   * @author Brian Wing Shun Chan
44   *
45   */
46  public class BreadcrumbTag extends IncludeTag {
47  
48      public static void doTag(
49              ServletContext servletContext, HttpServletRequest request,
50              HttpServletResponse response)
51          throws IOException, ServletException {
52  
53          doTag(
54              _PAGE, null, null, null, _DISPLAY_STYLE, servletContext, request,
55              response);
56      }
57  
58      public static void doTag(
59              String page, Layout selLayout, String selLayoutParam,
60              PortletURL portletURL, int displayStyle,
61              ServletContext servletContext, HttpServletRequest request,
62              HttpServletResponse response)
63          throws IOException, ServletException {
64  
65          request.setAttribute("liferay-ui:breadcrumb:selLayout", selLayout);
66          request.setAttribute(
67              "liferay-ui:breadcrumb:selLayoutParam", selLayoutParam);
68          request.setAttribute("liferay-ui:breadcrumb:portletURL", portletURL);
69          request.setAttribute(
70              "liferay-ui:breadcrumb:displayStyle", String.valueOf(displayStyle));
71  
72          RequestDispatcher requestDispatcher =
73              servletContext.getRequestDispatcher(page);
74  
75          requestDispatcher.include(request, response);
76      }
77  
78      public int doEndTag() throws JspException {
79          try {
80              ServletContext servletContext = getServletContext();
81              HttpServletRequest request = getServletRequest();
82              StringServletResponse stringResponse = getServletResponse();
83  
84              doTag(
85                  getPage(), _selLayout, _selLayoutParam, _portletURL,
86                  _displayStyle, servletContext, request, stringResponse);
87  
88              pageContext.getOut().print(stringResponse.getString());
89  
90              return EVAL_PAGE;
91          }
92          catch (Exception e) {
93              throw new JspException(e);
94          }
95      }
96  
97      public void setSelLayout(Layout selLayout) {
98          _selLayout = selLayout;
99      }
100 
101     public void setSelLayoutParam(String selLayoutParam) {
102         _selLayoutParam = selLayoutParam;
103     }
104 
105     public void setPortletURL(PortletURL portletURL) {
106         _portletURL = portletURL;
107     }
108 
109     public void setDisplayStyle(int displayStyle) {
110         _displayStyle = displayStyle;
111     }
112 
113     protected String getDefaultPage() {
114         return _PAGE;
115     }
116 
117     private static final String _PAGE = "/html/taglib/ui/breadcrumb/page.jsp";
118 
119     private static final int _DISPLAY_STYLE = 0;
120 
121     private Layout _selLayout;
122     private String _selLayoutParam;
123     private PortletURL _portletURL;
124     private int _displayStyle = _DISPLAY_STYLE;
125 
126 }