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="PasswordPolicySearch.java.html"><b><i>View Source</i></b></a>
045: *
046: * @author Scott Lee
047: *
048: */
049: public class PasswordPolicySearch 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("description");
057:
058: orderableHeaders.put("name", "name");
059: orderableHeaders.put("description", "description");
060: }
061:
062: public static final String EMPTY_RESULTS_MESSAGE = "no-password-policies-were-found";
063:
064: public PasswordPolicySearch(RenderRequest req,
065: PortletURL iteratorURL) {
066: super (req, new PasswordPolicyDisplayTerms(req),
067: new PasswordPolicySearchTerms(req), DEFAULT_CUR_PARAM,
068: DEFAULT_DELTA, iteratorURL, headerNames,
069: EMPTY_RESULTS_MESSAGE);
070:
071: PasswordPolicyDisplayTerms displayTerms = (PasswordPolicyDisplayTerms) getDisplayTerms();
072:
073: iteratorURL.setParameter(PasswordPolicyDisplayTerms.NAME,
074: displayTerms.getName());
075:
076: try {
077: PortalPreferences prefs = PortletPreferencesFactoryUtil
078: .getPortalPreferences(req);
079:
080: String orderByCol = ParamUtil.getString(req, "orderByCol");
081: String orderByType = ParamUtil
082: .getString(req, "orderByType");
083:
084: if (Validator.isNotNull(orderByCol)
085: && Validator.isNotNull(orderByType)) {
086:
087: prefs.setValue(PortletKeys.ENTERPRISE_ADMIN,
088: "password-policies-order-by-col", orderByCol);
089: prefs.setValue(PortletKeys.ENTERPRISE_ADMIN,
090: "password-policies-order-by-type", orderByType);
091: } else {
092: orderByCol = prefs.getValue(
093: PortletKeys.ENTERPRISE_ADMIN,
094: "password-policies-order-by-col", "name");
095: orderByType = prefs.getValue(
096: PortletKeys.ENTERPRISE_ADMIN,
097: "password-policies-order-by-type", "asc");
098: }
099:
100: OrderByComparator orderByComparator = EnterpriseAdminUtil
101: .getPasswordPolicyOrderByComparator(orderByCol,
102: orderByType);
103:
104: setOrderableHeaders(orderableHeaders);
105: setOrderByCol(orderByCol);
106: setOrderByType(orderByType);
107: setOrderByComparator(orderByComparator);
108: } catch (Exception e) {
109: _log.error(e);
110: }
111: }
112:
113: private static Log _log = LogFactory
114: .getLog(PasswordPolicySearch.class);
115:
116: }
|