001    /**
002     * Copyright (c) 2000-2012 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.util.PortalClassLoaderUtil;
018    
019    import javax.servlet.http.HttpServletRequest;
020    
021    /**
022     * @author Brian Wing Shun Chan
023     */
024    public class SearchIteratorTag<R> extends SearchPaginatorTag<R> {
025    
026            public void setPaginate(boolean paginate) {
027                    _paginate = paginate;
028            }
029    
030            @Override
031            protected void cleanUp() {
032                    super.cleanUp();
033    
034                    _paginate = true;
035            }
036    
037            @Override
038            protected String getPage() {
039                    return _PAGE;
040            }
041    
042            @Override
043            protected void include(String page) throws Exception {
044                    Thread currentThread = Thread.currentThread();
045    
046                    ClassLoader contextClassLoader = currentThread.getContextClassLoader();
047    
048                    try {
049                            currentThread.setContextClassLoader(
050                                    PortalClassLoaderUtil.getClassLoader());
051    
052                            super.include(page);
053                    }
054                    finally {
055                            currentThread.setContextClassLoader(contextClassLoader);
056                    }
057            }
058    
059            @Override
060            protected void setAttributes(HttpServletRequest request) {
061                    super.setAttributes(request);
062    
063                    request.setAttribute(
064                            "liferay-ui:search-iterator:paginate", String.valueOf(_paginate));
065            }
066    
067            private static final String _PAGE =
068                    "/html/taglib/ui/search_iterator/page.jsp";
069    
070            private boolean _paginate = true;
071    
072    }