001: /**
002: * Copyright (c) 2000-2008 Liferay, Inc. All rights reserved.
003: *
004: * Permission is hereby granted, free of charge, to any person obtaining a copy
005: * of this software and associated documentation files (the "Software"), to deal
006: * in the Software without restriction, including without limitation the rights
007: * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
008: * copies of the Software, and to permit persons to whom the Software is
009: * furnished to do so, subject to the following conditions:
010: *
011: * The above copyright notice and this permission notice shall be included in
012: * all copies or substantial portions of the Software.
013: *
014: * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
015: * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
016: * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
017: * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
018: * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
019: * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
020: * SOFTWARE.
021: */package com.liferay.portal.kernel.dao.search;
022:
023: import com.liferay.portal.kernel.util.OrderByComparator;
024: import com.liferay.portal.kernel.util.ParamUtil;
025:
026: import java.util.ArrayList;
027: import java.util.List;
028: import java.util.Map;
029:
030: import javax.portlet.PortletURL;
031: import javax.portlet.RenderRequest;
032:
033: /**
034: * <a href="SearchContainer.java.html"><b><i>View Source</i></b></a>
035: *
036: * @author Brian Wing Shun Chan
037: *
038: */
039: public class SearchContainer {
040:
041: public static final String DEFAULT_CUR_PARAM = "cur";
042:
043: public static final int DEFAULT_CUR_VALUE = 1;
044:
045: public static final int DEFAULT_DELTA = 20;
046:
047: public SearchContainer() {
048: }
049:
050: public SearchContainer(RenderRequest req,
051: DisplayTerms displayTerms, DisplayTerms searchTerms,
052: String curParam, int delta, PortletURL iteratorURL,
053: List headerNames, String emptyResultsMessage) {
054:
055: _displayTerms = displayTerms;
056: _searchTerms = searchTerms;
057:
058: _curParam = curParam;
059: _curValue = ParamUtil.get(req, _curParam, 1);
060: setDelta(delta);
061:
062: _iteratorURL = iteratorURL;
063:
064: _iteratorURL.setParameter(DisplayTerms.KEYWORDS, ParamUtil
065: .getString(req, DisplayTerms.KEYWORDS));
066: _iteratorURL.setParameter(DisplayTerms.ADVANCED_SEARCH, String
067: .valueOf(ParamUtil.getBoolean(req,
068: DisplayTerms.ADVANCED_SEARCH)));
069: _iteratorURL.setParameter(DisplayTerms.AND_OPERATOR, String
070: .valueOf(ParamUtil.getBoolean(req,
071: DisplayTerms.AND_OPERATOR, true)));
072:
073: if (headerNames != null) {
074: _headerNames = new ArrayList(headerNames.size());
075:
076: _headerNames.addAll(headerNames);
077: }
078:
079: _emptyResultsMessage = emptyResultsMessage;
080: }
081:
082: public DisplayTerms getDisplayTerms() {
083: return _displayTerms;
084: }
085:
086: public DisplayTerms getSearchTerms() {
087: return _searchTerms;
088: }
089:
090: public String getCurParam() {
091: return _curParam;
092: }
093:
094: public int getCurValue() {
095: return _curValue;
096: }
097:
098: public int getDelta() {
099: return _delta;
100: }
101:
102: public void setDelta(int delta) {
103: if (delta <= 0) {
104: _delta = DEFAULT_DELTA;
105: } else {
106: _delta = delta;
107: }
108:
109: _calculateStartAndEnd();
110: }
111:
112: public int getStart() {
113: return _start;
114: }
115:
116: public int getEnd() {
117: return _end;
118: }
119:
120: public int getResultEnd() {
121: return _resultEnd;
122: }
123:
124: public int getTotal() {
125: return _total;
126: }
127:
128: public void setTotal(int total) {
129: _total = total;
130:
131: if (((_curValue - 1) * _delta) > _total) {
132: _curValue = DEFAULT_CUR_VALUE;
133: }
134:
135: _calculateStartAndEnd();
136: }
137:
138: public List getResults() {
139: return _results;
140: }
141:
142: public void setResults(List results) {
143: _results = results;
144: }
145:
146: public List getResultRows() {
147: return _resultRows;
148: }
149:
150: public PortletURL getIteratorURL() {
151: return _iteratorURL;
152: }
153:
154: public void setIteratorURL(PortletURL iteratorURL) {
155: _iteratorURL = iteratorURL;
156: }
157:
158: public List getHeaderNames() {
159: return _headerNames;
160: }
161:
162: public void setHeaderNames(List headerNames) {
163: _headerNames = headerNames;
164: }
165:
166: public Map getOrderableHeaders() {
167: return _orderableHeaders;
168: }
169:
170: public void setOrderableHeaders(Map orderableHeaders) {
171: _orderableHeaders = orderableHeaders;
172: }
173:
174: public String getOrderByCol() {
175: return _orderByCol;
176: }
177:
178: public void setOrderByCol(String orderByCol) {
179: _orderByCol = orderByCol;
180: }
181:
182: public String getOrderByType() {
183: return _orderByType;
184: }
185:
186: public void setOrderByType(String orderByType) {
187: _orderByType = orderByType;
188: }
189:
190: public OrderByComparator getOrderByComparator() {
191: return _orderByComparator;
192: }
193:
194: public void setOrderByComparator(OrderByComparator orderByComparator) {
195: _orderByComparator = orderByComparator;
196: }
197:
198: public String getEmptyResultsMessage() {
199: return _emptyResultsMessage;
200: }
201:
202: public void setEmptyResultsMessage(String emptyResultsMessage) {
203: _emptyResultsMessage = emptyResultsMessage;
204: }
205:
206: public RowChecker getRowChecker() {
207: return _rowChecker;
208: }
209:
210: public void setRowChecker(RowChecker rowChecker) {
211: _rowChecker = rowChecker;
212: }
213:
214: public boolean isHover() {
215: return _hover;
216: }
217:
218: public void setHover(boolean hover) {
219: _hover = hover;
220: }
221:
222: private void _calculateStartAndEnd() {
223: _start = (_curValue - 1) * _delta;
224: _end = _start + _delta;
225:
226: _resultEnd = _end;
227:
228: if (_resultEnd > _total) {
229: _resultEnd = _total;
230: }
231: }
232:
233: private DisplayTerms _displayTerms;
234: private DisplayTerms _searchTerms;
235: private String _curParam = DEFAULT_CUR_PARAM;
236: private int _curValue;
237: private int _delta = DEFAULT_DELTA;
238: private int _start;
239: private int _end;
240: private int _resultEnd;
241: private int _total;
242: private List _results = new ArrayList();
243: private List _resultRows = new ArrayList();
244: private PortletURL _iteratorURL;
245: private List _headerNames;
246: private Map _orderableHeaders;
247: private String _orderByCol;
248: private String _orderByType;
249: private OrderByComparator _orderByComparator;
250: private String _emptyResultsMessage;
251: private RowChecker _rowChecker;
252: private boolean _hover = true;
253:
254: }
|