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