001/* 002 * (C) Copyright 2006-2012 Nuxeo SA (http://nuxeo.com/) and others. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 * 016 * Contributors: 017 * Thomas Roger <troger@nuxeo.com> 018 */ 019 020package org.nuxeo.ecm.platform.query.core; 021 022import java.util.List; 023 024import org.nuxeo.ecm.core.api.DocumentModel; 025import org.nuxeo.ecm.core.api.DocumentModelList; 026import org.nuxeo.ecm.core.api.impl.DocumentModelListImpl; 027import org.nuxeo.ecm.platform.query.api.AbstractPageProvider; 028 029/** 030 * Wraps a {@link DocumentModelList} inside a {@link org.nuxeo.ecm.platform.query.api.PageProvider}. 031 * <p> 032 * This page provider does not handle pagination at all, there is only one page with all the documents. 033 * 034 * @author <a href="mailto:troger@nuxeo.com">Thomas Roger</a> 035 * @since 5.6 036 */ 037public class DocumentModelListPageProvider extends AbstractPageProvider<DocumentModel> { 038 039 private static final long serialVersionUID = 1L; 040 041 protected final DocumentModelList docs; 042 043 public DocumentModelListPageProvider() { 044 docs = new DocumentModelListImpl(); 045 } 046 047 public DocumentModelListPageProvider(DocumentModelList docs) { 048 this.docs = docs; 049 } 050 051 public void setDocumentModelList(List<DocumentModel> docs) { 052 this.docs.addAll(docs); 053 } 054 055 public DocumentModelList getDocumentModelList() { 056 return new DocumentModelListImpl(docs); 057 } 058 059 @Override 060 public List<DocumentModel> getCurrentPage() { 061 return docs; 062 } 063 064 @Override 065 public long getResultsCount() { 066 return docs.totalSize(); 067 } 068 069 @Override 070 public long getPageSize() { 071 return docs.totalSize(); 072 } 073 074 @Override 075 public long getCurrentPageSize() { 076 return docs.totalSize(); 077 } 078 079 @Override 080 public long getNumberOfPages() { 081 return 1; 082 } 083}