001/*
002 * (C) Copyright 2006-2011 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 *     Nuxeo
018 */
019package org.nuxeo.ecm.automation.jaxrs.io.documents;
020
021import org.nuxeo.ecm.automation.core.util.PaginableDocumentModelList;
022import org.nuxeo.ecm.automation.core.util.PaginablePageProvider;
023import org.nuxeo.ecm.core.api.DocumentModel;
024import org.nuxeo.ecm.platform.query.api.PageProvider;
025
026/**
027 * Wraps a {@link PageProvider} as a {@link DocumentList}
028 *
029 * @author Tiry (tdelprat@nuxeo.com)
030 */
031public class PaginableDocumentModelListImpl extends PaginablePageProvider<DocumentModel> implements
032        PaginableDocumentModelList {
033
034    private static final long serialVersionUID = 1L;
035
036    protected String documentLinkBuilder;
037
038    public PaginableDocumentModelListImpl(PageProvider<DocumentModel> provider) {
039        this(provider, null);
040    }
041
042    /**
043     * Creates a {@code PaginableDocumentModelListImpl} with more display information.
044     *
045     * @param documentLinkBuilder the name of what will be used to compute the document URLs, usually a codec name.
046     * @since 5.6
047     */
048    public PaginableDocumentModelListImpl(PageProvider<DocumentModel> provider, String documentLinkBuilder) {
049        super(provider);
050        this.documentLinkBuilder = documentLinkBuilder;
051    }
052
053    public PageProvider<DocumentModel> getProvider() {
054        return pageProvider;
055    }
056
057    @Override
058    public String getDocumentLinkBuilder() {
059        return documentLinkBuilder;
060    }
061
062    @Override
063    public long totalSize() {
064        return pageProvider.getResultsCount();
065    }
066}