1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * This library is free software; you can redistribute it and/or modify it under
5    * the terms of the GNU Lesser General Public License as published by the Free
6    * Software Foundation; either version 2.1 of the License, or (at your option)
7    * any later version.
8    *
9    * This library is distributed in the hope that it will be useful, but WITHOUT
10   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11   * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12   * details.
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.portal.util.PropsValues;
20  import com.liferay.taglib.util.IncludeTag;
21  
22  import javax.portlet.PortletURL;
23  
24  import javax.servlet.RequestDispatcher;
25  import javax.servlet.ServletContext;
26  import javax.servlet.http.HttpServletRequest;
27  import javax.servlet.http.HttpServletResponse;
28  import javax.servlet.jsp.JspException;
29  
30  /**
31   * <a href="BreadcrumbTag.java.html"><b><i>View Source</i></b></a>
32   *
33   * @author Brian Wing Shun Chan
34   */
35  public class BreadcrumbTag extends IncludeTag {
36  
37      public static void doTag(
38              int displayStyle, boolean showGuestGroup, boolean showParentGroups,
39              boolean showLayout, boolean showPortletBreadcrumb,
40              ServletContext servletContext, HttpServletRequest request,
41              HttpServletResponse response)
42          throws Exception {
43  
44          doTag(
45              _PAGE, null, null, null, displayStyle, showGuestGroup,
46              showParentGroups, showLayout, showPortletBreadcrumb, servletContext,
47              request, response);
48      }
49  
50      public static void doTag(
51              ServletContext servletContext, HttpServletRequest request,
52              HttpServletResponse response)
53          throws Exception {
54  
55          doTag(
56              _PAGE, null, null, null, _DISPLAY_STYLE, _SHOW_GUEST_GROUP,
57              _SHOW_PARENT_GROUPS, true, true, servletContext, request,
58              response);
59      }
60  
61      public static void doTag(
62              String page, Layout selLayout, String selLayoutParam,
63              PortletURL portletURL, int displayStyle, boolean showGuestGroup,
64              boolean showParentGroups, boolean showLayout,
65              boolean showPortletBreadcrumb, ServletContext servletContext,
66              HttpServletRequest request, HttpServletResponse response)
67          throws Exception {
68  
69          request.setAttribute(
70              "liferay-ui:breadcrumb:displayStyle", String.valueOf(displayStyle));
71          request.setAttribute("liferay-ui:breadcrumb:portletURL", portletURL);
72          request.setAttribute("liferay-ui:breadcrumb:selLayout", selLayout);
73          request.setAttribute(
74              "liferay-ui:breadcrumb:selLayoutParam", selLayoutParam);
75          request.setAttribute(
76              "liferay-ui:breadcrumb:showGuestGroup",
77              String.valueOf(showGuestGroup));
78          request.setAttribute(
79              "liferay-ui:breadcrumb:showLayout", String.valueOf(showLayout));
80          request.setAttribute(
81              "liferay-ui:breadcrumb:showParentGroups",
82              String.valueOf(showParentGroups));
83          request.setAttribute(
84              "liferay-ui:breadcrumb:showPortletBreadcrumb",
85              String.valueOf(showPortletBreadcrumb));
86  
87          RequestDispatcher requestDispatcher =
88              servletContext.getRequestDispatcher(page);
89  
90          requestDispatcher.include(request, response);
91      }
92  
93      public int doEndTag() throws JspException {
94          try {
95              ServletContext servletContext = getServletContext();
96              HttpServletRequest request = getServletRequest();
97              StringServletResponse stringResponse = getServletResponse();
98  
99              doTag(
100                 getPage(), _selLayout, _selLayoutParam, _portletURL,
101                 _displayStyle, _showGuestGroup, _showParentGroups, _showLayout,
102                 _showPortletBreadcrumb, servletContext, request,
103                 stringResponse);
104 
105             pageContext.getOut().print(stringResponse.getString());
106 
107             return EVAL_PAGE;
108         }
109         catch (Exception e) {
110             throw new JspException(e);
111         }
112     }
113 
114     public void setDisplayStyle(int displayStyle) {
115         _displayStyle = displayStyle;
116     }
117 
118     public void setPortletURL(PortletURL portletURL) {
119         _portletURL = portletURL;
120     }
121 
122     public void setSelLayout(Layout selLayout) {
123         _selLayout = selLayout;
124     }
125 
126     public void setSelLayoutParam(String selLayoutParam) {
127         _selLayoutParam = selLayoutParam;
128     }
129 
130     public void setShowGuestGroup(boolean showGuestGroup) {
131         _showGuestGroup = showGuestGroup;
132     }
133 
134     public void setShowLayout(boolean showLayout) {
135         _showLayout = showLayout;
136     }
137 
138     public void setShowParentGroups(boolean showParentGroups) {
139         _showParentGroups = showParentGroups;
140     }
141 
142     public void setShowPortletBreadcrumb(boolean showPortletBreadcrumb) {
143         _showPortletBreadcrumb = showPortletBreadcrumb;
144     }
145 
146     protected String getDefaultPage() {
147         return _PAGE;
148     }
149 
150     private static final int _DISPLAY_STYLE = 0;
151 
152     private static final String _PAGE = "/html/taglib/ui/breadcrumb/page.jsp";
153 
154     private static final boolean _SHOW_GUEST_GROUP =
155         PropsValues.BREADCRUMB_SHOW_GUEST_GROUP;
156 
157     private static final boolean _SHOW_PARENT_GROUPS =
158         PropsValues.BREADCRUMB_SHOW_PARENT_GROUPS;
159 
160     private int _displayStyle = _DISPLAY_STYLE;
161     private PortletURL _portletURL;
162     private Layout _selLayout;
163     private String _selLayoutParam;
164     private boolean _showGuestGroup = _SHOW_GUEST_GROUP;
165     private boolean _showLayout = true;
166     private boolean _showParentGroups = _SHOW_PARENT_GROUPS;
167     private boolean _showPortletBreadcrumb = true;
168 
169 }