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.taglib.ui;
016    
017    import com.liferay.portal.kernel.dao.search.DisplayTerms;
018    import com.liferay.portal.kernel.dao.search.SearchContainer;
019    import com.liferay.taglib.util.IncludeTag;
020    
021    import java.util.LinkedHashMap;
022    
023    import javax.servlet.http.HttpServletRequest;
024    import javax.servlet.jsp.JspException;
025    import javax.servlet.jsp.JspTagException;
026    
027    /**
028     * @author Pei-Jung Lan
029     */
030    public class UserSearchContainerResultsTag<R> extends IncludeTag {
031    
032            @Override
033            public int doStartTag() throws JspException {
034                    SearchContainerTag<R> searchContainerTag =
035                            (SearchContainerTag<R>)findAncestorWithClass(
036                                    this, SearchContainerTag.class);
037    
038                    if (searchContainerTag == null) {
039                            throw new JspTagException("Requires liferay-ui:search-container");
040                    }
041    
042                    return super.doStartTag();
043            }
044    
045            public void setUseIndexer(boolean useIndexer) {
046                    _useIndexer = useIndexer;
047            }
048    
049            public void setUserParams(LinkedHashMap<String, Object> userParams) {
050                    _userParams = userParams;
051            }
052    
053            @Override
054            protected void cleanUp() {
055                    _searchContainer = null;
056                    _searchTerms = null;
057                    _useIndexer = true;
058                    _userParams = null;
059            }
060    
061            @Override
062            protected String getPage() {
063                    return _PAGE;
064            }
065    
066            @Override
067            protected void setAttributes(HttpServletRequest request) {
068                    SearchContainerTag<R> searchContainerTag =
069                            (SearchContainerTag<R>)findAncestorWithClass(
070                                    this, SearchContainerTag.class);
071    
072                    _searchContainer = searchContainerTag.getSearchContainer();
073    
074                    _searchTerms = _searchContainer.getSearchTerms();
075    
076                    request.setAttribute(
077                            "liferay-ui:user-search-container-results:useIndexer", _useIndexer);
078                    request.setAttribute(
079                            "liferay-ui:user-search-container-results:searchContainer",
080                            _searchContainer);
081                    request.setAttribute(
082                            "liferay-ui:user-search-container-results:searchTerms",
083                            _searchTerms);
084                    request.setAttribute(
085                            "liferay-ui:user-search-container-results:userParams", _userParams);
086            }
087    
088            private static final String _PAGE =
089                    "/html/taglib/ui/user_search_container_results/page.jsp";
090    
091            private SearchContainer<R> _searchContainer;
092            private DisplayTerms _searchTerms;
093            private boolean _useIndexer = true;
094            private LinkedHashMap<String, Object> _userParams;
095    
096    }