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 java.util.ArrayList;
024: import java.util.HashMap;
025: import java.util.List;
026: import java.util.Map;
027:
028: import javax.portlet.PortletURL;
029:
030: import javax.servlet.ServletContext;
031: import javax.servlet.http.HttpServletRequest;
032: import javax.servlet.http.HttpServletResponse;
033:
034: /**
035: * <a href="ResultRow.java.html"><b><i>View Source</i></b></a>
036: *
037: * @author Brian Wing Shun Chan
038: *
039: */
040: public class ResultRow {
041:
042: public ResultRow(Object obj, long primaryKey, int pos) {
043: this (obj, String.valueOf(primaryKey), pos);
044: }
045:
046: public ResultRow(Object obj, long primaryKey, int pos, boolean bold) {
047: this (obj, String.valueOf(primaryKey), pos, bold);
048: }
049:
050: public ResultRow(Object obj, String primaryKey, int pos) {
051: this (obj, primaryKey, pos, false);
052: }
053:
054: public ResultRow(Object obj, String primaryKey, int pos,
055: boolean bold) {
056: _obj = obj;
057: _primaryKey = primaryKey;
058: _pos = pos;
059: _bold = bold;
060: _entries = new ArrayList();
061: }
062:
063: public Object getObject() {
064: return _obj;
065: }
066:
067: public void setObject(Object obj) {
068: _obj = obj;
069: }
070:
071: public String getPrimaryKey() {
072: return _primaryKey;
073: }
074:
075: public void setPrimaryKey(String primaryKey) {
076: _primaryKey = primaryKey;
077: }
078:
079: public int getPos() {
080: return _pos;
081: }
082:
083: public boolean isBold() {
084: return _bold;
085: }
086:
087: public boolean isRestricted() {
088: return _restricted;
089: }
090:
091: public void setRestricted(boolean restricted) {
092: _restricted = restricted;
093: }
094:
095: public String getClassName() {
096: return _className;
097: }
098:
099: public void setClassName(String className) {
100: _className = className;
101: }
102:
103: public String getClassHoverName() {
104: return _classHoverName;
105: }
106:
107: public void setClassHoverName(String classHoverName) {
108: _classHoverName = classHoverName;
109: }
110:
111: public List getEntries() {
112: return _entries;
113: }
114:
115: public Object getParameter(String param) {
116: if (_params == null) {
117: _params = new HashMap();
118: }
119:
120: return _params.get(param);
121: }
122:
123: public void setParameter(String param, Object value) {
124: if (_params == null) {
125: _params = new HashMap();
126: }
127:
128: _params.put(param, value);
129: }
130:
131: // Text with name
132:
133: public void addText(String name) {
134: addText(_entries.size(), name);
135: }
136:
137: public void addText(int index, String name) {
138: addText(index, SearchEntry.DEFAULT_ALIGN,
139: SearchEntry.DEFAULT_VALIGN,
140: SearchEntry.DEFAULT_COLSPAN, name);
141: }
142:
143: public void addText(String align, String valign, String name) {
144: addText(_entries.size(), align, valign,
145: SearchEntry.DEFAULT_COLSPAN, name);
146: }
147:
148: public void addText(String align, String valign, int colspan,
149: String name) {
150:
151: addText(_entries.size(), align, valign, colspan, name);
152: }
153:
154: public void addText(int index, String align, String valign,
155: int colspan, String name) {
156:
157: _entries.add(index, new TextSearchEntry(align, valign, colspan,
158: name));
159: }
160:
161: // Text with name and href
162:
163: public void addText(String name, String href) {
164: addText(_entries.size(), name, href);
165: }
166:
167: public void addText(int index, String name, String href) {
168: addText(index, SearchEntry.DEFAULT_ALIGN,
169: SearchEntry.DEFAULT_VALIGN,
170: SearchEntry.DEFAULT_COLSPAN, name, href);
171: }
172:
173: public void addText(String align, String valign, String name,
174: String href) {
175: addText(_entries.size(), align, valign,
176: SearchEntry.DEFAULT_COLSPAN, name, href);
177: }
178:
179: public void addText(String align, String valign, int colspan,
180: String name, String href) {
181:
182: addText(_entries.size(), align, valign, colspan, name, href);
183: }
184:
185: public void addText(int index, String align, String valign,
186: int colspan, String name, String href) {
187:
188: if (_restricted) {
189: href = null;
190: }
191:
192: _entries.add(index, new TextSearchEntry(align, valign, colspan,
193: name, href));
194: }
195:
196: // Text with name and portlet URL
197:
198: public void addText(String name, PortletURL portletURL) {
199: if (portletURL == null) {
200: addText(name);
201: } else {
202: addText(name, portletURL.toString());
203: }
204: }
205:
206: public void addText(int index, String name, PortletURL portletURL) {
207: if (portletURL == null) {
208: addText(index, name);
209: } else {
210: addText(index, name, portletURL.toString());
211: }
212: }
213:
214: public void addText(String align, String valign, String name,
215: PortletURL portletURL) {
216:
217: addText(align, valign, SearchEntry.DEFAULT_COLSPAN, name,
218: portletURL);
219: }
220:
221: public void addText(String align, String valign, int colspan,
222: String name, PortletURL portletURL) {
223:
224: if (portletURL == null) {
225: addText(align, valign, colspan, name);
226: } else {
227: addText(align, valign, colspan, name, portletURL.toString());
228: }
229: }
230:
231: public void addText(int index, String align, String valign,
232: int colspan, String name, PortletURL portletURL) {
233:
234: if (portletURL == null) {
235: addText(index, align, valign, colspan, name);
236: } else {
237: addText(index, align, valign, colspan, name, portletURL
238: .toString());
239: }
240: }
241:
242: // Text with search entry
243:
244: public void addText(TextSearchEntry searchEntry) {
245: if (_restricted) {
246: searchEntry.setHref(null);
247: }
248:
249: _entries.add(_entries.size(), searchEntry);
250: }
251:
252: public void addText(int index, TextSearchEntry searchEntry) {
253: if (_restricted) {
254: searchEntry.setHref(null);
255: }
256:
257: _entries.add(index, searchEntry);
258: }
259:
260: // Button with name and href
261:
262: public void addButton(String name, String href) {
263: addButton(_entries.size(), name, href);
264: }
265:
266: public void addButton(int index, String name, String href) {
267: addButton(index, SearchEntry.DEFAULT_ALIGN,
268: SearchEntry.DEFAULT_VALIGN,
269: SearchEntry.DEFAULT_COLSPAN, name, href);
270: }
271:
272: public void addButton(String align, String valign, String name,
273: String href) {
274:
275: addButton(_entries.size(), align, valign,
276: SearchEntry.DEFAULT_COLSPAN, name, href);
277: }
278:
279: public void addButton(String align, String valign, int colspan,
280: String name, String href) {
281:
282: addButton(_entries.size(), align, valign, colspan, name, href);
283: }
284:
285: public void addButton(int index, String align, String valign,
286: int colspan, String name, String href) {
287:
288: if (_restricted) {
289: href = null;
290: }
291:
292: _entries.add(index, new ButtonSearchEntry(align, valign,
293: colspan, name, href));
294: }
295:
296: // JSP
297:
298: public void addJSP(String path) {
299: addJSP(_entries.size(), path);
300: }
301:
302: public void addJSP(String align, String valign, String path) {
303: addJSP(_entries.size(), align, valign,
304: SearchEntry.DEFAULT_COLSPAN, path);
305: }
306:
307: public void addJSP(String align, String valign, int colspan,
308: String path) {
309: addJSP(_entries.size(), align, valign, colspan, path);
310: }
311:
312: public void addJSP(int index, String path) {
313: addJSP(index, SearchEntry.DEFAULT_ALIGN,
314: SearchEntry.DEFAULT_VALIGN,
315: SearchEntry.DEFAULT_COLSPAN, path);
316: }
317:
318: public void addJSP(int index, String align, String valign,
319: int colspan, String path) {
320:
321: _entries.add(index, new JSPSearchEntry(align, valign, colspan,
322: path));
323: }
324:
325: // JSP with portlet context
326:
327: public void addJSP(String path, ServletContext ctx,
328: HttpServletRequest req, HttpServletResponse res) {
329:
330: addJSP(_entries.size(), path, ctx, req, res);
331: }
332:
333: public void addJSP(String align, String valign, String path,
334: ServletContext ctx, HttpServletRequest req,
335: HttpServletResponse res) {
336:
337: addJSP(_entries.size(), align, valign,
338: SearchEntry.DEFAULT_COLSPAN, path, ctx, req, res);
339: }
340:
341: public void addJSP(String align, String valign, int colspan,
342: String path, ServletContext ctx, HttpServletRequest req,
343: HttpServletResponse res) {
344:
345: addJSP(_entries.size(), align, valign, colspan, path, ctx, req,
346: res);
347: }
348:
349: public void addJSP(int index, String path, ServletContext ctx,
350: HttpServletRequest req, HttpServletResponse res) {
351:
352: addJSP(index, SearchEntry.DEFAULT_ALIGN,
353: SearchEntry.DEFAULT_VALIGN,
354: SearchEntry.DEFAULT_COLSPAN, path, ctx, req, res);
355: }
356:
357: public void addJSP(int index, String align, String valign,
358: int colspan, String path, ServletContext ctx,
359: HttpServletRequest req, HttpServletResponse res) {
360:
361: _entries.add(index, new JSPSearchEntry(align, valign, colspan,
362: path, ctx, req, res));
363: }
364:
365: // Score
366:
367: public void addScore(float score) {
368: addScore(_entries.size(), score);
369: }
370:
371: public void addScore(int index, float score) {
372: _entries.add(index, new ScoreSearchEntry(score));
373: }
374:
375: private Object _obj;
376: private String _primaryKey;
377: private int _pos;
378: private boolean _bold;
379: private boolean _restricted;
380: private String _className;
381: private String _classHoverName;
382: private List _entries;
383: private Map _params;
384:
385: }
|