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.ResultRowSplitter;
018    import com.liferay.portal.kernel.util.Validator;
019    
020    import javax.servlet.http.HttpServletRequest;
021    
022    /**
023     * @author Brian Wing Shun Chan
024     */
025    public class SearchIteratorTag<R> extends SearchPaginatorTag<R> {
026    
027            public static final String DEFAULT_DISPLAY_STYPE = "list";
028    
029            public String getDisplayStyle() {
030                    return _displayStyle;
031            }
032    
033            public ResultRowSplitter getResultRowSplitter() {
034                    return _resultRowSplitter;
035            }
036    
037            public void setDisplayStyle(String displayStyle) {
038                    _displayStyle = displayStyle;
039            }
040    
041            @Override
042            public void setMarkupView(String markupView) {
043                    _markupView = markupView;
044            }
045    
046            public void setPaginate(boolean paginate) {
047                    _paginate = paginate;
048            }
049    
050            public void setResultRowSplitter(ResultRowSplitter resultRowSplitter) {
051                    _resultRowSplitter = resultRowSplitter;
052            }
053    
054            @Override
055            protected void cleanUp() {
056                    super.cleanUp();
057    
058                    _displayStyle = DEFAULT_DISPLAY_STYPE;
059                    _markupView = null;
060                    _paginate = true;
061                    _resultRowSplitter = null;
062            }
063    
064            @Override
065            protected String getPage() {
066                    String displayStyle = _displayStyle;
067    
068                    if (Validator.isNull(displayStyle)) {
069                            displayStyle = DEFAULT_DISPLAY_STYPE;
070                    }
071    
072                    if (Validator.isNotNull(_markupView)) {
073                            return "/html/taglib/ui/search_iterator/" + _markupView + "/" +
074                                    displayStyle + ".jsp";
075                    }
076    
077                    return "/html/taglib/ui/search_iterator/" + displayStyle + ".jsp";
078            }
079    
080            @Override
081            protected void setAttributes(HttpServletRequest request) {
082                    super.setAttributes(request);
083    
084                    request.setAttribute(
085                            "liferay-ui:search-iterator:markupView", _markupView);
086                    request.setAttribute(
087                            "liferay-ui:search-iterator:paginate", String.valueOf(_paginate));
088                    request.setAttribute(
089                            "liferay-ui:search-iterator:resultRowSplitter", _resultRowSplitter);
090            }
091    
092            private String _displayStyle = DEFAULT_DISPLAY_STYPE;
093            private String _markupView;
094            private boolean _paginate = true;
095            private ResultRowSplitter _resultRowSplitter;
096    
097    }