1   /**
2    * Copyright (c) 2000-2009 Liferay, Inc. All rights reserved.
3    *
4    *
5    *
6    *
7    * The contents of this file are subject to the terms of the Liferay Enterprise
8    * Subscription License ("License"). You may not use this file except in
9    * compliance with the License. You can obtain a copy of the License by
10   * contacting Liferay, Inc. See the License for the specific language governing
11   * permissions and limitations under the License, including but not limited to
12   * distribution rights 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  public class BreadcrumbTag extends IncludeTag {
46  
47      public static void doTag(
48              ServletContext servletContext, HttpServletRequest request,
49              HttpServletResponse response)
50          throws IOException, ServletException {
51  
52          doTag(
53              _PAGE, null, null, null, _DISPLAY_STYLE, servletContext, request,
54              response);
55      }
56  
57      public static void doTag(
58              String page, Layout selLayout, String selLayoutParam,
59              PortletURL portletURL, int displayStyle,
60              ServletContext servletContext, HttpServletRequest request,
61              HttpServletResponse response)
62          throws IOException, ServletException {
63  
64          request.setAttribute(
65              "liferay-ui:breadcrumb:displayStyle", String.valueOf(displayStyle));
66          request.setAttribute("liferay-ui:breadcrumb:selLayout", selLayout);
67          request.setAttribute(
68              "liferay-ui:breadcrumb:selLayoutParam", selLayoutParam);
69          request.setAttribute("liferay-ui:breadcrumb:portletURL", portletURL);
70  
71          RequestDispatcher requestDispatcher =
72              servletContext.getRequestDispatcher(page);
73  
74          requestDispatcher.include(request, response);
75      }
76  
77      public int doEndTag() throws JspException {
78          try {
79              ServletContext servletContext = getServletContext();
80              HttpServletRequest request = getServletRequest();
81              StringServletResponse stringResponse = getServletResponse();
82  
83              doTag(
84                  getPage(), _selLayout, _selLayoutParam, _portletURL,
85                  _displayStyle, servletContext, request, stringResponse);
86  
87              pageContext.getOut().print(stringResponse.getString());
88  
89              return EVAL_PAGE;
90          }
91          catch (Exception e) {
92              throw new JspException(e);
93          }
94      }
95  
96      public void setDisplayStyle(int displayStyle) {
97          _displayStyle = displayStyle;
98      }
99  
100     public void setPortletURL(PortletURL portletURL) {
101         _portletURL = portletURL;
102     }
103 
104     public void setSelLayout(Layout selLayout) {
105         _selLayout = selLayout;
106     }
107 
108     public void setSelLayoutParam(String selLayoutParam) {
109         _selLayoutParam = selLayoutParam;
110     }
111 
112     protected String getDefaultPage() {
113         return _PAGE;
114     }
115 
116     private static final int _DISPLAY_STYLE = 0;
117 
118     private static final String _PAGE = "/html/taglib/ui/breadcrumb/page.jsp";
119 
120     private int _displayStyle = _DISPLAY_STYLE;
121     private PortletURL _portletURL;
122     private Layout _selLayout;
123     private String _selLayoutParam;
124 
125 }