001/*
002 * Copyright 2013 Box, Inc. All rights reserved.
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 */
016package org.nuxeo.box.api.marshalling.dao;
017
018import org.nuxeo.box.api.marshalling.exceptions.BoxRestException;
019
020import java.io.InputStream;
021
022/**
023 * Preview of a file.
024 */
025public class BoxPreview extends BoxObject {
026
027    public final static String MIN_WIDTH = "min_width";
028
029    public final static String MIN_HEIGHT = "min_height";
030
031    public final static String MAX_WIDTH = "max_width";
032
033    public final static String MAX_HEIGHT = "max_height";
034
035    public final static String PAGE = "page";
036
037    private int firstPage = 1;
038
039    private int lastPage = 1;
040
041    private InputStream content;
042
043    /**
044     * Get the first page number.
045     *
046     * @return the first page number.
047     */
048    public Integer getFirstPage() {
049        return this.firstPage;
050    }
051
052    /**
053     * @param firstPage first page number
054     */
055    public void setFirstPage(Integer firstPage) {
056        this.firstPage = firstPage;
057    }
058
059    /**
060     * Get the last page number.
061     *
062     * @return the last page number
063     */
064    public Integer getLastPage() {
065        return this.lastPage;
066    }
067
068    /**
069     * Set the last page number.
070     *
071     * @param lastPage last page number
072     */
073    public void setLastPage(int lastPage) {
074        this.lastPage = lastPage;
075    }
076
077    /**
078     * Get content of the preview. Caller is responsible for closing the InputStream.
079     *
080     * @return preview input stream.
081     * @throws org.nuxeo.box.api.marshalling.exceptions.BoxRestException
082     */
083    public InputStream getContent() throws BoxRestException {
084        return content;
085    }
086
087    /**
088     * Set content.
089     *
090     * @param content content
091     */
092    public void setContent(InputStream content) {
093        this.content = content;
094    }
095
096    /**
097     * Get number of pages.
098     *
099     * @return number of pages
100     */
101    public Integer getNumPages() {
102        return getLastPage() - getFirstPage() + 1;
103    }
104
105}