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