001    /**
002     * Copyright (c) 2000-present Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portal.kernel.dao.search;
016    
017    import com.liferay.portal.kernel.util.ParamUtil;
018    import com.liferay.portal.kernel.util.Validator;
019    
020    import javax.portlet.PortletRequest;
021    
022    import javax.servlet.http.HttpServletRequest;
023    
024    /**
025     * @author Brian Wing Shun Chan
026     */
027    public class DisplayTerms {
028    
029            public static final String ADVANCED_SEARCH = "advancedSearch";
030    
031            public static final String AND_OPERATOR = "andOperator";
032    
033            public static final String KEYWORDS = "keywords";
034    
035            public DisplayTerms(HttpServletRequest request) {
036                    advancedSearch = ParamUtil.getBoolean(request, ADVANCED_SEARCH);
037                    andOperator = ParamUtil.getBoolean(request, AND_OPERATOR, true);
038                    keywords = ParamUtil.getString(request, KEYWORDS);
039            }
040    
041            public DisplayTerms(PortletRequest portletRequest) {
042                    advancedSearch = ParamUtil.getBoolean(portletRequest, ADVANCED_SEARCH);
043                    andOperator = ParamUtil.getBoolean(portletRequest, AND_OPERATOR, true);
044                    keywords = ParamUtil.getString(portletRequest, KEYWORDS);
045            }
046    
047            public String getKeywords() {
048                    return keywords;
049            }
050    
051            public boolean isAdvancedSearch() {
052                    return advancedSearch;
053            }
054    
055            public boolean isAndOperator() {
056                    return andOperator;
057            }
058    
059            public boolean isSearch() {
060                    if (advancedSearch || Validator.isNotNull(keywords)) {
061                            return true;
062                    }
063    
064                    return false;
065            }
066    
067            public void setAdvancedSearch(boolean advancedSearch) {
068                    this.advancedSearch = advancedSearch;
069            }
070    
071            protected boolean advancedSearch;
072            protected boolean andOperator;
073            protected String keywords;
074    
075    }