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.enterpriseadmin.search;
022:
023: import com.liferay.portal.kernel.dao.search.SearchContainer;
024: import com.liferay.portal.kernel.util.OrderByComparator;
025: import com.liferay.portal.kernel.util.ParamUtil;
026: import com.liferay.portal.kernel.util.Validator;
027: import com.liferay.portal.util.PortletKeys;
028: import com.liferay.portlet.PortalPreferences;
029: import com.liferay.portlet.PortletPreferencesFactoryUtil;
030: import com.liferay.portlet.enterpriseadmin.util.EnterpriseAdminUtil;
031: import com.liferay.util.CollectionFactory;
032:
033: import java.util.ArrayList;
034: import java.util.List;
035: import java.util.Map;
036:
037: import javax.portlet.PortletURL;
038: import javax.portlet.RenderRequest;
039:
040: import org.apache.commons.logging.Log;
041: import org.apache.commons.logging.LogFactory;
042:
043: /**
044: * <a href="RoleSearch.java.html"><b><i>View Source</i></b></a>
045: *
046: * @author Brian Wing Shun Chan
047: *
048: */
049: public class RoleSearch extends SearchContainer {
050:
051: static List headerNames = new ArrayList();
052: static Map orderableHeaders = CollectionFactory.getHashMap();
053:
054: static {
055: headerNames.add("name");
056: headerNames.add("type");
057: headerNames.add("description");
058:
059: orderableHeaders.put("name", "name");
060: orderableHeaders.put("type", "type");
061: orderableHeaders.put("description", "description");
062: }
063:
064: public static final String EMPTY_RESULTS_MESSAGE = "no-roles-were-found";
065:
066: public RoleSearch(RenderRequest req, PortletURL iteratorURL) {
067: super (req, new RoleDisplayTerms(req), new RoleSearchTerms(req),
068: DEFAULT_CUR_PARAM, DEFAULT_DELTA, iteratorURL,
069: headerNames, EMPTY_RESULTS_MESSAGE);
070:
071: RoleDisplayTerms displayTerms = (RoleDisplayTerms) getDisplayTerms();
072:
073: iteratorURL.setParameter(RoleDisplayTerms.NAME, displayTerms
074: .getName());
075: iteratorURL.setParameter(RoleDisplayTerms.DESCRIPTION,
076: displayTerms.getDescription());
077: iteratorURL.setParameter(RoleDisplayTerms.TYPE, String
078: .valueOf(displayTerms.getType()));
079:
080: try {
081: PortalPreferences prefs = PortletPreferencesFactoryUtil
082: .getPortalPreferences(req);
083:
084: String orderByCol = ParamUtil.getString(req, "orderByCol");
085: String orderByType = ParamUtil
086: .getString(req, "orderByType");
087:
088: if (Validator.isNotNull(orderByCol)
089: && Validator.isNotNull(orderByType)) {
090:
091: prefs.setValue(PortletKeys.ENTERPRISE_ADMIN,
092: "roles-order-by-col", orderByCol);
093: prefs.setValue(PortletKeys.ENTERPRISE_ADMIN,
094: "roles-order-by-type", orderByType);
095: } else {
096: orderByCol = prefs.getValue(
097: PortletKeys.ENTERPRISE_ADMIN,
098: "roles-order-by-col", "name");
099: orderByType = prefs.getValue(
100: PortletKeys.ENTERPRISE_ADMIN,
101: "roles-order-by-type", "asc");
102: }
103:
104: OrderByComparator orderByComparator = EnterpriseAdminUtil
105: .getRoleOrderByComparator(orderByCol, orderByType);
106:
107: setOrderableHeaders(orderableHeaders);
108: setOrderByCol(orderByCol);
109: setOrderByType(orderByType);
110: setOrderByComparator(orderByComparator);
111: } catch (Exception e) {
112: _log.error(e);
113: }
114: }
115:
116: private static Log _log = LogFactory.getLog(RoleSearch.class);
117:
118: }
|