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