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