001/* 002 * (C) Copyright 2006-2012 Nuxeo SA (http://nuxeo.com/) and others. 003 * 004 * All rights reserved. This program and the accompanying materials 005 * are made available under the terms of the GNU Lesser General Public License 006 * (LGPL) version 2.1 which accompanies this distribution, and is available at 007 * http://www.gnu.org/licenses/lgpl-2.1.html 008 * 009 * This library is distributed in the hope that it will be useful, 010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 012 * Lesser General Public License for more details. 013 * 014 * Contributors: 015 * Thomas Roger <troger@nuxeo.com> 016 */ 017 018package org.nuxeo.ecm.platform.query.core; 019 020import java.util.List; 021 022import org.nuxeo.ecm.core.api.DocumentModel; 023import org.nuxeo.ecm.core.api.DocumentModelList; 024import org.nuxeo.ecm.core.api.impl.DocumentModelListImpl; 025import org.nuxeo.ecm.platform.query.api.AbstractPageProvider; 026 027/** 028 * Wraps a {@link DocumentModelList} inside a {@link org.nuxeo.ecm.platform.query.api.PageProvider}. 029 * <p> 030 * This page provider does not handle pagination at all, there is only one page with all the documents. 031 * 032 * @author <a href="mailto:troger@nuxeo.com">Thomas Roger</a> 033 * @since 5.6 034 */ 035public class DocumentModelListPageProvider extends AbstractPageProvider<DocumentModel> { 036 037 private static final long serialVersionUID = 1L; 038 039 protected final DocumentModelList docs; 040 041 public DocumentModelListPageProvider() { 042 docs = new DocumentModelListImpl(); 043 } 044 045 public DocumentModelListPageProvider(DocumentModelList docs) { 046 this.docs = docs; 047 } 048 049 public void setDocumentModelList(List<DocumentModel> docs) { 050 this.docs.addAll(docs); 051 } 052 053 public DocumentModelList getDocumentModelList() { 054 return new DocumentModelListImpl(docs); 055 } 056 057 @Override 058 public List<DocumentModel> getCurrentPage() { 059 return docs; 060 } 061 062 @Override 063 public long getResultsCount() { 064 return docs.totalSize(); 065 } 066 067 @Override 068 public long getPageSize() { 069 return docs.totalSize(); 070 } 071 072 @Override 073 public long getCurrentPageSize() { 074 return docs.totalSize(); 075 } 076 077 @Override 078 public long getNumberOfPages() { 079 return 1; 080 } 081}