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.portlet.journal.search;
022:
023: import com.liferay.portal.kernel.dao.search.SearchContainer;
024: import com.liferay.portal.kernel.util.JavaConstants;
025: import com.liferay.portal.kernel.util.OrderByComparator;
026: import com.liferay.portal.kernel.util.ParamUtil;
027: import com.liferay.portal.kernel.util.Validator;
028: import com.liferay.portal.util.PortletKeys;
029: import com.liferay.portlet.PortalPreferences;
030: import com.liferay.portlet.PortletPreferencesFactoryUtil;
031: import com.liferay.portlet.journal.util.JournalUtil;
032: import com.liferay.util.CollectionFactory;
033:
034: import java.util.ArrayList;
035: import java.util.List;
036: import java.util.Map;
037:
038: import javax.portlet.PortletConfig;
039: import javax.portlet.PortletURL;
040: import javax.portlet.RenderRequest;
041:
042: import org.apache.commons.logging.Log;
043: import org.apache.commons.logging.LogFactory;
044:
045: /**
046: * <a href="ArticleSearch.java.html"><b><i>View Source</i></b></a>
047: *
048: * @author Brian Wing Shun Chan
049: *
050: */
051: public class ArticleSearch extends SearchContainer {
052:
053: static List headerNames = new ArrayList();
054: static Map orderableHeaders = CollectionFactory.getHashMap();
055:
056: static {
057: headerNames.add("id");
058: headerNames.add("name");
059: headerNames.add("version");
060: headerNames.add("modified-date");
061: headerNames.add("display-date");
062: headerNames.add("author");
063:
064: orderableHeaders.put("id", "id");
065: orderableHeaders.put("name", "title");
066: orderableHeaders.put("version", "version");
067: orderableHeaders.put("modified-date", "modified-date");
068: orderableHeaders.put("display-date", "display-date");
069: }
070:
071: public static final String EMPTY_RESULTS_MESSAGE = "no-articles-were-found";
072:
073: public ArticleSearch(RenderRequest req, PortletURL iteratorURL) {
074: super (req, new ArticleDisplayTerms(req),
075: new ArticleSearchTerms(req), DEFAULT_CUR_PARAM,
076: DEFAULT_DELTA, iteratorURL, headerNames,
077: EMPTY_RESULTS_MESSAGE);
078:
079: PortletConfig portletConfig = (PortletConfig) req
080: .getAttribute(JavaConstants.JAVAX_PORTLET_CONFIG);
081:
082: ArticleDisplayTerms displayTerms = (ArticleDisplayTerms) getDisplayTerms();
083: ArticleSearchTerms searchTerms = (ArticleSearchTerms) getSearchTerms();
084:
085: if (!portletConfig.getPortletName().equals(PortletKeys.JOURNAL)) {
086: displayTerms.setStatus("approved");
087: searchTerms.setStatus("approved");
088: }
089:
090: iteratorURL.setParameter(ArticleDisplayTerms.GROUP_ID, String
091: .valueOf(displayTerms.getGroupId()));
092: iteratorURL.setParameter(ArticleDisplayTerms.ARTICLE_ID,
093: displayTerms.getArticleId());
094: iteratorURL.setParameter(ArticleDisplayTerms.VERSION, String
095: .valueOf(displayTerms.getVersion()));
096: iteratorURL.setParameter(ArticleDisplayTerms.TITLE,
097: displayTerms.getTitle());
098: iteratorURL.setParameter(ArticleDisplayTerms.DESCRIPTION,
099: displayTerms.getDescription());
100: iteratorURL.setParameter(ArticleDisplayTerms.CONTENT,
101: displayTerms.getContent());
102: iteratorURL.setParameter(ArticleDisplayTerms.TYPE, displayTerms
103: .getType());
104: iteratorURL.setParameter(ArticleDisplayTerms.STRUCTURE_ID,
105: displayTerms.getStructureId());
106: iteratorURL.setParameter(ArticleDisplayTerms.TEMPLATE_ID,
107: displayTerms.getTemplateId());
108: iteratorURL.setParameter(ArticleDisplayTerms.STATUS,
109: displayTerms.getStatus());
110:
111: try {
112: PortalPreferences prefs = PortletPreferencesFactoryUtil
113: .getPortalPreferences(req);
114:
115: String orderByCol = ParamUtil.getString(req, "orderByCol");
116: String orderByType = ParamUtil
117: .getString(req, "orderByType");
118:
119: if (Validator.isNotNull(orderByCol)
120: && Validator.isNotNull(orderByType)) {
121:
122: prefs.setValue(PortletKeys.JOURNAL,
123: "articles-order-by-col", orderByCol);
124: prefs.setValue(PortletKeys.JOURNAL,
125: "articles-order-by-type", orderByType);
126: } else {
127: orderByCol = prefs.getValue(PortletKeys.JOURNAL,
128: "articles-order-by-col", "id");
129: orderByType = prefs.getValue(PortletKeys.JOURNAL,
130: "articles-order-by-type", "asc");
131: }
132:
133: OrderByComparator orderByComparator = JournalUtil
134: .getArticleOrderByComparator(orderByCol,
135: orderByType);
136:
137: setOrderableHeaders(orderableHeaders);
138: setOrderByCol(orderByCol);
139: setOrderByType(orderByType);
140: setOrderByComparator(orderByComparator);
141: } catch (Exception e) {
142: _log.error(e);
143: }
144: }
145:
146: private static Log _log = LogFactory.getLog(ArticleSearch.class);
147:
148: }
|