001
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.SearchContainerReference;
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.jsp.JspException;
036
037
040 public class SearchContainerTag<R> extends ParamAndPropertyAncestorTagImpl {
041
042 @Override
043 public int doEndTag() {
044 pageContext.setAttribute(
045 _searchContainer.getTotalVar(), _searchContainer.getTotal());
046
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 _total = 0;
067 _totalVar = SearchContainer.DEFAULT_TOTAL_VAR;
068 _var = SearchContainer.DEFAULT_VAR;
069
070 return EVAL_PAGE;
071 }
072
073 @Override
074 public int doStartTag() throws JspException {
075 try {
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<R>(
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 if (_total != 0) {
128 _searchContainer.setTotal(_total);
129 }
130
131 if (Validator.isNotNull(_totalVar)) {
132 _searchContainer.setTotalVar(_totalVar);
133 }
134
135 pageContext.setAttribute(_searchContainer.getTotalVar(), 0);
136 pageContext.setAttribute(_var, _searchContainer);
137
138 SearchContainerReference searchContainerReference =
139 (SearchContainerReference)pageContext.getAttribute(
140 "searchContainerReference");
141
142 if ((searchContainerReference != null) &&
143 !_var.equals(SearchContainer.DEFAULT_VAR)) {
144
145 searchContainerReference.register(_var, _searchContainer);
146 }
147
148 return EVAL_BODY_INCLUDE;
149 }
150 catch (Exception e) {
151 throw new JspException(e);
152 }
153 }
154
155 public String getCurParam() {
156 return _curParam;
157 }
158
159 public int getDelta() {
160 return _delta;
161 }
162
163 public String getDeltaParam() {
164 return _deltaParam;
165 }
166
167 public DisplayTerms getDisplayTerms() {
168 return _displayTerms;
169 }
170
171 public String getEmptyResultsMessage() {
172 return _emptyResultsMessage;
173 }
174
175 public PortletURL getIteratorURL() {
176 return _iteratorURL;
177 }
178
179 public String getOrderByCol() {
180 return _orderByCol;
181 }
182
183 public String getOrderByColParam() {
184 return _orderByColParam;
185 }
186
187 public OrderByComparator getOrderByComparator() {
188 return _orderByComparator;
189 }
190
191 public String getOrderByType() {
192 return _orderByType;
193 }
194
195 public String getOrderByTypeParam() {
196 return _orderByTypeParam;
197 }
198
199 public RowChecker getRowChecker() {
200 return _rowChecker;
201 }
202
203 public SearchContainer<R> getSearchContainer() {
204 return _searchContainer;
205 }
206
207 public DisplayTerms getSearchTerms() {
208 return _searchTerms;
209 }
210
211 public int getTotal() {
212 return _total;
213 }
214
215 public String getTotalVar() {
216 return _totalVar;
217 }
218
219 public String getVar() {
220 return _var;
221 }
222
223 public boolean isDeltaConfigurable() {
224 return _deltaConfigurable;
225 }
226
227 public boolean isHasResults() {
228 return _hasResults;
229 }
230
231 public boolean isHover() {
232 return _hover;
233 }
234
235 public void setCurParam(String curParam) {
236 _curParam = curParam;
237 }
238
239 public void setDelta(int delta) {
240 _delta = delta;
241 }
242
243 public void setDeltaConfigurable(boolean deltaConfigurable) {
244 _deltaConfigurable = deltaConfigurable;
245 }
246
247 public void setDeltaParam(String deltaParam) {
248 _deltaParam = deltaParam;
249 }
250
251 public void setDisplayTerms(DisplayTerms displayTerms) {
252 _displayTerms = displayTerms;
253 }
254
255 public void setEmptyResultsMessage(String emptyResultsMessage) {
256 _emptyResultsMessage = emptyResultsMessage;
257 }
258
259 public void setHasResults(boolean hasResults) {
260 _hasResults = hasResults;
261 }
262
263 public void setHeaderNames(String headerNames) {
264 _headerNames = ListUtil.toList(StringUtil.split(headerNames));
265 }
266
267 public void setHover(boolean hover) {
268 _hover = hover;
269 }
270
271 public void setId(String id) {
272 _id = id;
273 }
274
275 public void setIteratorURL(PortletURL iteratorURL) {
276 _iteratorURL = iteratorURL;
277 }
278
279 public void setOrderByCol(String orderByCol) {
280 _orderByCol = orderByCol;
281 }
282
283 public void setOrderByColParam(String orderByColParam) {
284 _orderByColParam = orderByColParam;
285 }
286
287 public void setOrderByComparator(OrderByComparator orderByComparator) {
288 _orderByComparator = orderByComparator;
289 }
290
291 public void setOrderByType(String orderByType) {
292 _orderByType = orderByType;
293 }
294
295 public void setOrderByTypeParam(String orderByTypeParam) {
296 _orderByTypeParam = orderByTypeParam;
297 }
298
299 public void setRowChecker(RowChecker rowChecker) {
300 _rowChecker = rowChecker;
301 }
302
303 public void setSearchContainer(SearchContainer<R> searchContainer) {
304 _searchContainer = searchContainer;
305 }
306
307 public void setSearchTerms(DisplayTerms searchTerms) {
308 _searchTerms = searchTerms;
309 }
310
311 public void setTotal(int total) {
312 _total = total;
313 }
314
315 public void setTotalVar(String totalVar) {
316 _totalVar = totalVar;
317 }
318
319 public void setVar(String var) {
320 _var = var;
321 }
322
323 private String _curParam = SearchContainer.DEFAULT_CUR_PARAM;
324 private int _delta = SearchContainer.DEFAULT_DELTA;
325 private boolean _deltaConfigurable =
326 SearchContainer.DEFAULT_DELTA_CONFIGURABLE;
327 private String _deltaParam = SearchContainer.DEFAULT_DELTA_PARAM;
328 private DisplayTerms _displayTerms;
329 private String _emptyResultsMessage;
330 private boolean _hasResults;
331 private List<String> _headerNames;
332 private boolean _hover = true;
333 private String _id;
334 private PortletURL _iteratorURL;
335 private String _orderByCol;
336 private String _orderByColParam =
337 SearchContainer.DEFAULT_ORDER_BY_COL_PARAM;
338 private OrderByComparator _orderByComparator;
339 private String _orderByType;
340 private String _orderByTypeParam =
341 SearchContainer.DEFAULT_ORDER_BY_TYPE_PARAM;
342 private RowChecker _rowChecker;
343 private SearchContainer<R> _searchContainer;
344 private DisplayTerms _searchTerms;
345 private int _total;
346 private String _totalVar = SearchContainer.DEFAULT_TOTAL_VAR;
347 private String _var = SearchContainer.DEFAULT_VAR;
348
349 }