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.dao.search.DisplayTerms;
18  import com.liferay.portal.kernel.dao.search.RowChecker;
19  import com.liferay.portal.kernel.dao.search.SearchContainer;
20  import com.liferay.portal.kernel.util.JavaConstants;
21  import com.liferay.portal.kernel.util.ListUtil;
22  import com.liferay.portal.kernel.util.OrderByComparator;
23  import com.liferay.portal.kernel.util.StringUtil;
24  import com.liferay.portal.kernel.util.Validator;
25  import com.liferay.taglib.util.ParamAndPropertyAncestorTagImpl;
26  
27  import java.util.List;
28  
29  import javax.portlet.PortletRequest;
30  import javax.portlet.PortletResponse;
31  import javax.portlet.PortletURL;
32  import javax.portlet.RenderResponse;
33  
34  import javax.servlet.http.HttpServletRequest;
35  import javax.servlet.jsp.JspException;
36  
37  /**
38   * <a href="SearchContainerTag.java.html"><b><i>View Source</i></b></a>
39   *
40   * @author Raymond Augé
41   */
42  public class SearchContainerTag extends ParamAndPropertyAncestorTagImpl {
43  
44      public static final String DEFAULT_VAR = "searchContainer";
45  
46      public int doEndTag() {
47          _curParam = SearchContainer.DEFAULT_CUR_PARAM;
48          _delta = SearchContainer.DEFAULT_DELTA;
49          _deltaParam = SearchContainer.DEFAULT_DELTA_PARAM;
50          _displayTerms = null;
51          _emptyResultsMessage = null;
52          _hasResults = false;
53          _headerNames = null;
54          _hover = false;
55          _id = null;
56          _iteratorURL = null;
57          _orderByCol = null;
58          _orderByColParam = SearchContainer.DEFAULT_ORDER_BY_COL_PARAM;
59          _orderByComparator = null;
60          _orderByType = null;
61          _orderByTypeParam = SearchContainer.DEFAULT_ORDER_BY_TYPE_PARAM;
62          _rowChecker = null;
63          _searchContainer = null;
64          _searchTerms = null;
65          _var = DEFAULT_VAR;
66  
67          return EVAL_PAGE;
68      }
69  
70      public int doStartTag() throws JspException {
71          try {
72              HttpServletRequest request = getServletRequest();
73  
74              PortletRequest portletRequest =
75                  (PortletRequest)request.getAttribute(
76                      JavaConstants.JAVAX_PORTLET_REQUEST);
77              PortletResponse portletResponse =
78                  (PortletResponse)request.getAttribute(
79                      JavaConstants.JAVAX_PORTLET_RESPONSE);
80  
81              if (_iteratorURL == null) {
82                  _iteratorURL =
83                      ((RenderResponse)portletResponse).createRenderURL();
84              }
85  
86              if (_searchContainer == null) {
87                  _searchContainer = new SearchContainer(
88                      portletRequest, _displayTerms, _searchTerms, getCurParam(),
89                      getDelta(), _iteratorURL,  null, _emptyResultsMessage);
90              }
91  
92              _searchContainer.setId(_id);
93  
94              if (_headerNames != null) {
95                  _searchContainer.setHeaderNames(_headerNames);
96              }
97  
98              _searchContainer.setHover(_hover);
99  
100             if (Validator.isNotNull(_orderByColParam)) {
101                 _searchContainer.setOrderByColParam(_orderByColParam);
102             }
103 
104             if (Validator.isNotNull(_orderByCol)) {
105                 _searchContainer.setOrderByCol(_orderByCol);
106             }
107 
108             if (_orderByComparator != null) {
109                 _searchContainer.setOrderByComparator(_orderByComparator);
110             }
111 
112             if (Validator.isNotNull(_orderByTypeParam)) {
113                 _searchContainer.setOrderByTypeParam(_orderByTypeParam);
114             }
115 
116             if (Validator.isNotNull(_orderByType)) {
117                 _searchContainer.setOrderByType(_orderByType);
118             }
119 
120             if (_rowChecker != null) {
121                 _searchContainer.setRowChecker(_rowChecker);
122             }
123 
124             pageContext.setAttribute(_var, _searchContainer);
125 
126             return EVAL_BODY_INCLUDE;
127         }
128         catch (Exception e) {
129             throw new JspException(e);
130         }
131     }
132 
133     public String getCurParam() {
134         return _curParam;
135     }
136 
137     public int getDelta() {
138         return _delta;
139     }
140 
141     public String getDeltaParam() {
142         return _deltaParam;
143     }
144 
145     public DisplayTerms getDisplayTerms() {
146         return _displayTerms;
147     }
148 
149     public String getEmptyResultsMessage() {
150         return _emptyResultsMessage;
151     }
152 
153     public PortletURL getIteratorURL() {
154         return _iteratorURL;
155     }
156 
157     public String getOrderByCol() {
158         return _orderByCol;
159     }
160 
161     public String getOrderByColParam() {
162         return _orderByColParam;
163     }
164 
165     public OrderByComparator getOrderByComparator() {
166         return _orderByComparator;
167     }
168 
169     public String getOrderByType() {
170         return _orderByType;
171     }
172 
173     public String getOrderByTypeParam() {
174         return _orderByTypeParam;
175     }
176 
177     public RowChecker getRowChecker() {
178         return _rowChecker;
179     }
180 
181     public SearchContainer getSearchContainer() {
182         return _searchContainer;
183     }
184 
185     public DisplayTerms getSearchTerms() {
186         return _searchTerms;
187     }
188 
189     public String getVar() {
190         return _var;
191     }
192 
193     public boolean isHasResults() {
194         return _hasResults;
195     }
196 
197     public boolean isHover() {
198         return _hover;
199     }
200 
201     public void setCurParam(String curParam) {
202         _curParam = curParam;
203     }
204 
205     public void setDelta(int delta) {
206         _delta = delta;
207     }
208 
209     public void setDeltaParam(String deltaParam) {
210         _deltaParam = deltaParam;
211     }
212 
213     public void setDisplayTerms(DisplayTerms displayTerms) {
214         _displayTerms = displayTerms;
215     }
216 
217     public void setEmptyResultsMessage(String emptyResultsMessage) {
218         _emptyResultsMessage = emptyResultsMessage;
219     }
220 
221     public void setHasResults(boolean hasResults) {
222         _hasResults = hasResults;
223     }
224 
225     public void setHeaderNames(String headerNames) {
226         _headerNames = ListUtil.toList(StringUtil.split(headerNames));
227     }
228 
229     public void setHover(boolean hover) {
230         _hover = hover;
231     }
232 
233     public void setId(String id) {
234         _id = id;
235     }
236 
237     public void setIteratorURL(PortletURL iteratorURL) {
238         _iteratorURL = iteratorURL;
239     }
240 
241     public void setOrderByCol(String orderByCol) {
242         _orderByCol = orderByCol;
243     }
244 
245     public void setOrderByColParam(String orderByColParam) {
246         _orderByColParam = orderByColParam;
247     }
248 
249     public void setOrderByComparator(OrderByComparator orderByComparator) {
250         _orderByComparator = orderByComparator;
251     }
252 
253     public void setOrderByType(String orderByType) {
254         _orderByType = orderByType;
255     }
256 
257     public void setOrderByTypeParam(String orderByTypeParam) {
258         _orderByTypeParam = orderByTypeParam;
259     }
260 
261     public void setRowChecker(RowChecker rowChecker) {
262         _rowChecker = rowChecker;
263     }
264 
265     public void setSearchContainer(SearchContainer searchContainer) {
266         _searchContainer = searchContainer;
267     }
268 
269     public void setSearchTerms(DisplayTerms searchTerms) {
270         _searchTerms = searchTerms;
271     }
272 
273     public void setVar(String var) {
274         _var = var;
275     }
276 
277     private String _curParam = SearchContainer.DEFAULT_CUR_PARAM;
278     private int _delta = SearchContainer.DEFAULT_DELTA;
279     private String _deltaParam = SearchContainer.DEFAULT_DELTA_PARAM;
280     private DisplayTerms _displayTerms;
281     private String _emptyResultsMessage;
282     private boolean _hasResults;
283     private List<String> _headerNames;
284     private boolean _hover = true;
285     private String _id;
286     private PortletURL _iteratorURL;
287     private OrderByComparator _orderByComparator;
288     private String _orderByCol;
289     private String _orderByColParam =
290         SearchContainer.DEFAULT_ORDER_BY_COL_PARAM;
291     private String _orderByType;
292     private String _orderByTypeParam =
293         SearchContainer.DEFAULT_ORDER_BY_TYPE_PARAM;
294     private RowChecker _rowChecker;
295     private SearchContainer _searchContainer;
296     private DisplayTerms _searchTerms;
297     private String _var = DEFAULT_VAR;
298 
299 }