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 setUserParams(LinkedHashMap<String, Object> userParams) {
046                    _userParams = userParams;
047            }
048    
049            @Override
050            protected void cleanUp() {
051                    _searchContainer = null;
052                    _searchTerms = null;
053                    _userParams = null;
054            }
055    
056            @Override
057            protected String getPage() {
058                    return _PAGE;
059            }
060    
061            @Override
062            protected void setAttributes(HttpServletRequest request) {
063                    SearchContainerTag<R> searchContainerTag =
064                            (SearchContainerTag<R>)findAncestorWithClass(
065                                    this, SearchContainerTag.class);
066    
067                    _searchContainer = searchContainerTag.getSearchContainer();
068    
069                    _searchTerms = _searchContainer.getSearchTerms();
070    
071                    request.setAttribute(
072                            "liferay-ui:user-search-container-results:searchContainer",
073                            _searchContainer);
074                    request.setAttribute(
075                            "liferay-ui:user-search-container-results:searchTerms",
076                            _searchTerms);
077                    request.setAttribute(
078                            "liferay-ui:user-search-container-results:userParams", _userParams);
079            }
080    
081            private static final String _PAGE =
082                    "/html/taglib/ui/user_search_container_results/page.jsp";
083    
084            private SearchContainer<R> _searchContainer;
085            private DisplayTerms _searchTerms;
086            private LinkedHashMap<String, Object> _userParams;
087    
088    }