001    /**
002     * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.taglib.ui;
016    
017    import com.liferay.portal.kernel.dao.search.DisplayTerms;
018    import com.liferay.portal.kernel.dao.search.RowChecker;
019    import com.liferay.portal.kernel.dao.search.SearchContainer;
020    import com.liferay.portal.kernel.util.JavaConstants;
021    import com.liferay.portal.kernel.util.ListUtil;
022    import com.liferay.portal.kernel.util.OrderByComparator;
023    import com.liferay.portal.kernel.util.ServerDetector;
024    import com.liferay.portal.kernel.util.StringUtil;
025    import com.liferay.portal.kernel.util.Validator;
026    import com.liferay.taglib.util.ParamAndPropertyAncestorTagImpl;
027    
028    import java.util.List;
029    
030    import javax.portlet.MimeResponse;
031    import javax.portlet.PortletRequest;
032    import javax.portlet.PortletResponse;
033    import javax.portlet.PortletURL;
034    
035    import javax.servlet.http.HttpServletRequest;
036    import javax.servlet.jsp.JspException;
037    
038    /**
039     * @author Raymond Augé
040     */
041    public class SearchContainerTag extends ParamAndPropertyAncestorTagImpl {
042    
043            public static final String DEFAULT_VAR = "searchContainer";
044    
045            public int doEndTag() {
046                    if (!ServerDetector.isResin()) {
047                            _curParam = SearchContainer.DEFAULT_CUR_PARAM;
048                            _delta = SearchContainer.DEFAULT_DELTA;
049                            _deltaConfigurable = SearchContainer.DEFAULT_DELTA_CONFIGURABLE;
050                            _deltaParam = SearchContainer.DEFAULT_DELTA_PARAM;
051                            _displayTerms = null;
052                            _emptyResultsMessage = null;
053                            _hasResults = false;
054                            _headerNames = null;
055                            _hover = false;
056                            _id = null;
057                            _iteratorURL = null;
058                            _orderByCol = null;
059                            _orderByColParam = SearchContainer.DEFAULT_ORDER_BY_COL_PARAM;
060                            _orderByComparator = null;
061                            _orderByType = null;
062                            _orderByTypeParam = SearchContainer.DEFAULT_ORDER_BY_TYPE_PARAM;
063                            _rowChecker = null;
064                            _searchContainer = null;
065                            _searchTerms = null;
066                            _var = DEFAULT_VAR;
067                    }
068    
069                    return EVAL_PAGE;
070            }
071    
072            public int doStartTag() throws JspException {
073                    try {
074                            HttpServletRequest request = getServletRequest();
075    
076                            PortletRequest portletRequest =
077                                    (PortletRequest)request.getAttribute(
078                                            JavaConstants.JAVAX_PORTLET_REQUEST);
079                            PortletResponse portletResponse =
080                                    (PortletResponse)request.getAttribute(
081                                            JavaConstants.JAVAX_PORTLET_RESPONSE);
082    
083                            if (_iteratorURL == null) {
084                                    _iteratorURL =
085                                            ((MimeResponse)portletResponse).createRenderURL();
086                            }
087    
088                            if (_searchContainer == null) {
089                                    _searchContainer = new SearchContainer(
090                                            portletRequest, _displayTerms, _searchTerms, getCurParam(),
091                                            getDelta(), _iteratorURL, null, _emptyResultsMessage);
092                            }
093    
094                            _searchContainer.setDeltaConfigurable(_deltaConfigurable);
095                            _searchContainer.setId(_id);
096    
097                            if (_headerNames != null) {
098                                    _searchContainer.setHeaderNames(_headerNames);
099                            }
100    
101                            _searchContainer.setHover(_hover);
102    
103                            if (Validator.isNotNull(_orderByColParam)) {
104                                    _searchContainer.setOrderByColParam(_orderByColParam);
105                            }
106    
107                            if (Validator.isNotNull(_orderByCol)) {
108                                    _searchContainer.setOrderByCol(_orderByCol);
109                            }
110    
111                            if (_orderByComparator != null) {
112                                    _searchContainer.setOrderByComparator(_orderByComparator);
113                            }
114    
115                            if (Validator.isNotNull(_orderByTypeParam)) {
116                                    _searchContainer.setOrderByTypeParam(_orderByTypeParam);
117                            }
118    
119                            if (Validator.isNotNull(_orderByType)) {
120                                    _searchContainer.setOrderByType(_orderByType);
121                            }
122    
123                            if (_rowChecker != null) {
124                                    _searchContainer.setRowChecker(_rowChecker);
125                            }
126    
127                            pageContext.setAttribute(_var, _searchContainer);
128    
129                            return EVAL_BODY_INCLUDE;
130                    }
131                    catch (Exception e) {
132                            throw new JspException(e);
133                    }
134            }
135    
136            public String getCurParam() {
137                    return _curParam;
138            }
139    
140            public int getDelta() {
141                    return _delta;
142            }
143    
144            public String getDeltaParam() {
145                    return _deltaParam;
146            }
147    
148            public DisplayTerms getDisplayTerms() {
149                    return _displayTerms;
150            }
151    
152            public String getEmptyResultsMessage() {
153                    return _emptyResultsMessage;
154            }
155    
156            public PortletURL getIteratorURL() {
157                    return _iteratorURL;
158            }
159    
160            public String getOrderByCol() {
161                    return _orderByCol;
162            }
163    
164            public String getOrderByColParam() {
165                    return _orderByColParam;
166            }
167    
168            public OrderByComparator getOrderByComparator() {
169                    return _orderByComparator;
170            }
171    
172            public String getOrderByType() {
173                    return _orderByType;
174            }
175    
176            public String getOrderByTypeParam() {
177                    return _orderByTypeParam;
178            }
179    
180            public RowChecker getRowChecker() {
181                    return _rowChecker;
182            }
183    
184            public SearchContainer getSearchContainer() {
185                    return _searchContainer;
186            }
187    
188            public DisplayTerms getSearchTerms() {
189                    return _searchTerms;
190            }
191    
192            public String getVar() {
193                    return _var;
194            }
195    
196            public boolean isDeltaConfigurable() {
197                    return _deltaConfigurable;
198            }
199    
200            public boolean isHasResults() {
201                    return _hasResults;
202            }
203    
204            public boolean isHover() {
205                    return _hover;
206            }
207    
208            public void setCurParam(String curParam) {
209                    _curParam = curParam;
210            }
211    
212            public void setDelta(int delta) {
213                    _delta = delta;
214            }
215    
216            public void setDeltaConfigurable(boolean deltaConfigurable) {
217                    _deltaConfigurable = deltaConfigurable;
218            }
219    
220            public void setDeltaParam(String deltaParam) {
221                    _deltaParam = deltaParam;
222            }
223    
224            public void setDisplayTerms(DisplayTerms displayTerms) {
225                    _displayTerms = displayTerms;
226            }
227    
228            public void setEmptyResultsMessage(String emptyResultsMessage) {
229                    _emptyResultsMessage = emptyResultsMessage;
230            }
231    
232            public void setHasResults(boolean hasResults) {
233                    _hasResults = hasResults;
234            }
235    
236            public void setHeaderNames(String headerNames) {
237                    _headerNames = ListUtil.toList(StringUtil.split(headerNames));
238            }
239    
240            public void setHover(boolean hover) {
241                    _hover = hover;
242            }
243    
244            public void setId(String id) {
245                    _id = id;
246            }
247    
248            public void setIteratorURL(PortletURL iteratorURL) {
249                    _iteratorURL = iteratorURL;
250            }
251    
252            public void setOrderByCol(String orderByCol) {
253                    _orderByCol = orderByCol;
254            }
255    
256            public void setOrderByColParam(String orderByColParam) {
257                    _orderByColParam = orderByColParam;
258            }
259    
260            public void setOrderByComparator(OrderByComparator orderByComparator) {
261                    _orderByComparator = orderByComparator;
262            }
263    
264            public void setOrderByType(String orderByType) {
265                    _orderByType = orderByType;
266            }
267    
268            public void setOrderByTypeParam(String orderByTypeParam) {
269                    _orderByTypeParam = orderByTypeParam;
270            }
271    
272            public void setRowChecker(RowChecker rowChecker) {
273                    _rowChecker = rowChecker;
274            }
275    
276            public void setSearchContainer(SearchContainer searchContainer) {
277                    _searchContainer = searchContainer;
278            }
279    
280            public void setSearchTerms(DisplayTerms searchTerms) {
281                    _searchTerms = searchTerms;
282            }
283    
284            public void setVar(String var) {
285                    _var = var;
286            }
287    
288            private String _curParam = SearchContainer.DEFAULT_CUR_PARAM;
289            private int _delta = SearchContainer.DEFAULT_DELTA;
290            private boolean _deltaConfigurable =
291                    SearchContainer.DEFAULT_DELTA_CONFIGURABLE;
292            private String _deltaParam = SearchContainer.DEFAULT_DELTA_PARAM;
293            private DisplayTerms _displayTerms;
294            private String _emptyResultsMessage;
295            private boolean _hasResults;
296            private List<String> _headerNames;
297            private boolean _hover = true;
298            private String _id;
299            private PortletURL _iteratorURL;
300            private OrderByComparator _orderByComparator;
301            private String _orderByCol;
302            private String _orderByColParam =
303                    SearchContainer.DEFAULT_ORDER_BY_COL_PARAM;
304            private String _orderByType;
305            private String _orderByTypeParam =
306                    SearchContainer.DEFAULT_ORDER_BY_TYPE_PARAM;
307            private RowChecker _rowChecker;
308            private SearchContainer _searchContainer;
309            private DisplayTerms _searchTerms;
310            private String _var = DEFAULT_VAR;
311    
312    }