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.StringUtil;
024 import com.liferay.portal.kernel.util.Validator;
025 import com.liferay.taglib.util.ParamAndPropertyAncestorTagImpl;
026
027 import java.util.List;
028
029 import javax.portlet.MimeResponse;
030 import javax.portlet.PortletRequest;
031 import javax.portlet.PortletResponse;
032 import javax.portlet.PortletURL;
033
034 import javax.servlet.http.HttpServletRequest;
035 import javax.servlet.jsp.JspException;
036
037
040 public class SearchContainerTag<R> extends ParamAndPropertyAncestorTagImpl {
041
042 public static final String DEFAULT_VAR = "searchContainer";
043
044 @Override
045 public int doEndTag() {
046 _curParam = SearchContainer.DEFAULT_CUR_PARAM;
047 _delta = SearchContainer.DEFAULT_DELTA;
048 _deltaConfigurable = SearchContainer.DEFAULT_DELTA_CONFIGURABLE;
049 _deltaParam = SearchContainer.DEFAULT_DELTA_PARAM;
050 _displayTerms = null;
051 _emptyResultsMessage = null;
052 _hasResults = false;
053 _headerNames = null;
054 _hover = false;
055 _id = null;
056 _iteratorURL = null;
057 _orderByCol = null;
058 _orderByColParam = SearchContainer.DEFAULT_ORDER_BY_COL_PARAM;
059 _orderByComparator = null;
060 _orderByType = null;
061 _orderByTypeParam = SearchContainer.DEFAULT_ORDER_BY_TYPE_PARAM;
062 _rowChecker = null;
063 _searchContainer = null;
064 _searchTerms = null;
065 _var = DEFAULT_VAR;
066
067 return EVAL_PAGE;
068 }
069
070 @Override
071 public int doStartTag() throws JspException {
072 try {
073 HttpServletRequest request = getServletRequest();
074
075 PortletRequest portletRequest =
076 (PortletRequest)request.getAttribute(
077 JavaConstants.JAVAX_PORTLET_REQUEST);
078 PortletResponse portletResponse =
079 (PortletResponse)request.getAttribute(
080 JavaConstants.JAVAX_PORTLET_RESPONSE);
081
082 if (_iteratorURL == null) {
083 _iteratorURL =
084 ((MimeResponse)portletResponse).createRenderURL();
085 }
086
087 if (_searchContainer == null) {
088 _searchContainer = new SearchContainer<R>(
089 portletRequest, _displayTerms, _searchTerms, getCurParam(),
090 getDelta(), _iteratorURL, null, _emptyResultsMessage);
091 }
092
093 _searchContainer.setDeltaConfigurable(_deltaConfigurable);
094 _searchContainer.setId(_id);
095
096 if (_headerNames != null) {
097 _searchContainer.setHeaderNames(_headerNames);
098 }
099
100 _searchContainer.setHover(_hover);
101
102 if (Validator.isNotNull(_orderByColParam)) {
103 _searchContainer.setOrderByColParam(_orderByColParam);
104 }
105
106 if (Validator.isNotNull(_orderByCol)) {
107 _searchContainer.setOrderByCol(_orderByCol);
108 }
109
110 if (_orderByComparator != null) {
111 _searchContainer.setOrderByComparator(_orderByComparator);
112 }
113
114 if (Validator.isNotNull(_orderByTypeParam)) {
115 _searchContainer.setOrderByTypeParam(_orderByTypeParam);
116 }
117
118 if (Validator.isNotNull(_orderByType)) {
119 _searchContainer.setOrderByType(_orderByType);
120 }
121
122 if (_rowChecker != null) {
123 _searchContainer.setRowChecker(_rowChecker);
124 }
125
126 pageContext.setAttribute(_var, _searchContainer);
127
128 return EVAL_BODY_INCLUDE;
129 }
130 catch (Exception e) {
131 throw new JspException(e);
132 }
133 }
134
135 public String getCurParam() {
136 return _curParam;
137 }
138
139 public int getDelta() {
140 return _delta;
141 }
142
143 public String getDeltaParam() {
144 return _deltaParam;
145 }
146
147 public DisplayTerms getDisplayTerms() {
148 return _displayTerms;
149 }
150
151 public String getEmptyResultsMessage() {
152 return _emptyResultsMessage;
153 }
154
155 public PortletURL getIteratorURL() {
156 return _iteratorURL;
157 }
158
159 public String getOrderByCol() {
160 return _orderByCol;
161 }
162
163 public String getOrderByColParam() {
164 return _orderByColParam;
165 }
166
167 public OrderByComparator getOrderByComparator() {
168 return _orderByComparator;
169 }
170
171 public String getOrderByType() {
172 return _orderByType;
173 }
174
175 public String getOrderByTypeParam() {
176 return _orderByTypeParam;
177 }
178
179 public RowChecker getRowChecker() {
180 return _rowChecker;
181 }
182
183 public SearchContainer<R> getSearchContainer() {
184 return _searchContainer;
185 }
186
187 public DisplayTerms getSearchTerms() {
188 return _searchTerms;
189 }
190
191 public String getVar() {
192 return _var;
193 }
194
195 public boolean isDeltaConfigurable() {
196 return _deltaConfigurable;
197 }
198
199 public boolean isHasResults() {
200 return _hasResults;
201 }
202
203 public boolean isHover() {
204 return _hover;
205 }
206
207 public void setCurParam(String curParam) {
208 _curParam = curParam;
209 }
210
211 public void setDelta(int delta) {
212 _delta = delta;
213 }
214
215 public void setDeltaConfigurable(boolean deltaConfigurable) {
216 _deltaConfigurable = deltaConfigurable;
217 }
218
219 public void setDeltaParam(String deltaParam) {
220 _deltaParam = deltaParam;
221 }
222
223 public void setDisplayTerms(DisplayTerms displayTerms) {
224 _displayTerms = displayTerms;
225 }
226
227 public void setEmptyResultsMessage(String emptyResultsMessage) {
228 _emptyResultsMessage = emptyResultsMessage;
229 }
230
231 public void setHasResults(boolean hasResults) {
232 _hasResults = hasResults;
233 }
234
235 public void setHeaderNames(String headerNames) {
236 _headerNames = ListUtil.toList(StringUtil.split(headerNames));
237 }
238
239 public void setHover(boolean hover) {
240 _hover = hover;
241 }
242
243 public void setId(String id) {
244 _id = id;
245 }
246
247 public void setIteratorURL(PortletURL iteratorURL) {
248 _iteratorURL = iteratorURL;
249 }
250
251 public void setOrderByCol(String orderByCol) {
252 _orderByCol = orderByCol;
253 }
254
255 public void setOrderByColParam(String orderByColParam) {
256 _orderByColParam = orderByColParam;
257 }
258
259 public void setOrderByComparator(OrderByComparator orderByComparator) {
260 _orderByComparator = orderByComparator;
261 }
262
263 public void setOrderByType(String orderByType) {
264 _orderByType = orderByType;
265 }
266
267 public void setOrderByTypeParam(String orderByTypeParam) {
268 _orderByTypeParam = orderByTypeParam;
269 }
270
271 public void setRowChecker(RowChecker rowChecker) {
272 _rowChecker = rowChecker;
273 }
274
275 public void setSearchContainer(SearchContainer<R> searchContainer) {
276 _searchContainer = searchContainer;
277 }
278
279 public void setSearchTerms(DisplayTerms searchTerms) {
280 _searchTerms = searchTerms;
281 }
282
283 public void setVar(String var) {
284 _var = var;
285 }
286
287 private String _curParam = SearchContainer.DEFAULT_CUR_PARAM;
288 private int _delta = SearchContainer.DEFAULT_DELTA;
289 private boolean _deltaConfigurable =
290 SearchContainer.DEFAULT_DELTA_CONFIGURABLE;
291 private String _deltaParam = SearchContainer.DEFAULT_DELTA_PARAM;
292 private DisplayTerms _displayTerms;
293 private String _emptyResultsMessage;
294 private boolean _hasResults;
295 private List<String> _headerNames;
296 private boolean _hover = true;
297 private String _id;
298 private PortletURL _iteratorURL;
299 private String _orderByCol;
300 private String _orderByColParam =
301 SearchContainer.DEFAULT_ORDER_BY_COL_PARAM;
302 private OrderByComparator _orderByComparator;
303 private String _orderByType;
304 private String _orderByTypeParam =
305 SearchContainer.DEFAULT_ORDER_BY_TYPE_PARAM;
306 private RowChecker _rowChecker;
307 private SearchContainer<R> _searchContainer;
308 private DisplayTerms _searchTerms;
309 private String _var = DEFAULT_VAR;
310
311 }